WWW

Case Against Using Symlinks For Code Promotion

Posted by Mike Brittain on May 12, 2009
WWW / 4 Comments

I’ve read and argued a lot about the case for using symlinks in managing code promotion. I’ve talked about this a lot with my pal, John Goulah, and he also noted this approach in a post he wrote about deploying code.

My general approach goes something like this:

  1. Point your document root at a static location, such as /var/www/html/prod.
  2. Promote new code (from stage, dev, what have you) to a versioned directory on your prod server, such as /var/www/html/release_12345.
  3. Use a symlink, “prod” in this case, to point at a specific release (e.g. prod -> release_12345).

The goal here is that you have a handful of versions on your prod servers that make it very quick to revert to a previous version.  You can revert your code, right?  (I’ll admit that only after a number of years I’ve finally gotten reverts working quickly and consistently.)  Our build process is not too involved, but it takes about two minutes to get code out to all of our servers and then flip over the symlinks to make the new code live.  The flip only takes one or two seconds, so all of the web servers we are deploying to remain consistent.

We have used a similar technique for nearly the last year in our build process at CafeMom.  I stress the word used, because we just got rid of the symlinks.

It turns out that we ran into an issue with the way that Apache handles symlinks while under load.  At the point when we would flip our symlinks to a new release version, files (especially PHP) from the previous release were still being executed or served by Apache.  It seems that Apache caches the real path to a file after determining where the symlink is pointing, and doesn’t necessarily re-check the symlink.  I don’t know how long this occurs, or whether it is specific to individual Apache children, but I do know that it has been a regular pain in the ass (PHP fatals, blank white pages, yuck).

To be clear about details, we also run APC on our servers to speed things up in our PHP processing.  When we promote a new version of code we also flush the PHP cache, thinking that this would help clear out cached versions of files.  The only thing that would absolutely clear up this issue was to cycle Apache, which we would prefer not to do on every deployment.

What now?  Rather than repointing a symlink, we move entire directories.  Something like this:

  1. Sync code out to a new versioned directory on our prod servers, say release_12346.
  2. Switch release directories doing something like this: “mv prod release_12345; mv release_12346 prod”.  (We use a state file to keep track of where “prod” originally lived, in case you’re wondering where release_12345 came from.)

Renaming these directories takes about the same time as swapping the old symlink we were using.  The Apache virtual host configurations (document roots) don’t need to be updated, either.  Looking at our APC dashboard and the affect on our site, it seems like this approach is working much more smoothly.

If you’ve got questions, alternative suggestions, or if you know what the root issue is with Apache caching our symlinks, sound off in the comments below!

Tags: , , , , , ,

Why Google Analytics (“ga.js”) Doesn’t Work with XHTML

Posted by Mike Brittain on September 13, 2008
WWW / 1 Comment

Finding a small issue with Google Analytics’ tracking code when served on pages with the application/xhtml+xml mime-type… It doesn’t work.

The issue is that the code checks the current HTTP protocol for the page, whether it is served as SSL or not.  If it is, the tracking code is served from a secure server to prevent your browser from complaining.  The actual tracking code is loaded using a script that uses a document.write() operation to add the script tag to your page.  This is illegal on pages served as XML, because the browser (at least Firefox) is designed to restrict JavaScript from inserting markup during render time.

This probably affects only the “latest” tracking code, ga.js, and not the legacy code, urchin.js.

The fix is actually pretty easy, despite the fact that I couldn’t find any official documentation about it from Google.  Take a look at the legacy code for inserting urchin.js on your page.  It uses a normal script tag, instead of using document.write() to insert the tag — which is legal.

Now look at the JS code used to insert ga.js.  Assuming you’re not serving an SSL site, you can replace the document.write() with a static script tag.  Something like the one below:

<script src="http://www.google-analytics.com/ga.js" type="text/javascript"></script>

If you are using SSL on your site, along with the application/xhtml+xml mime-type, then it’s up to you to deal with switching the hostname and protocol in the URL in the appropriate pages.

You should not make this change to the tracking code unless you need to (i.e. you’re serving XHTML and tracking pixels are not firing properly).

Tags: , , ,

Making Application Shortcuts for Chrome

Posted by Mike Brittain on September 09, 2008
Google, WWW / Comments Off on Making Application Shortcuts for Chrome

Google has a page listing some details for webmasters about their new web browser.  My favorite part is in regards to handling application shortcuts which I figured out from Gmail’s site.  It’s a simple addition of “application-name” and “application-url” meta tags, along with a meta description and link to an icon file, which you probably already have on your site.

Application shortcuts are probably my favorite feature of Chrome, and the reason why I think that it is an important browser.  These shortcuts will help users and businesses to change their mindset about software-as-a-service applications.  They make web applications look like real software.  We used to have a desktop icon for Eudora or Outlook Express.  Now we have one for Gmail.  In the future, I suspect we’ll see more people replacing their installations of Microsoft Office with a shortcut to Google Docs, Zoho, ThinkFree, or Live Workspace.

Tags: , , , ,

What I think about Google Chrome

Posted by Mike Brittain on September 09, 2008
WWW / Comments Off on What I think about Google Chrome

I didn’t feel like posting an entry about Chrome, but I’ve had a lot of opinions about why I think it’s good.  Will I use it as?  That’s a good question.  We’ll need a Mac version, first, but I think I’d like to make the transition.

Anyway, Felix wrote a pretty good post about Chrome, and I decided to just add my thoughts on the end of that one.

Tags: , , ,

How to Setup a Web Proxy for the iPhone Simulator

Posted by Mike Brittain on September 04, 2008
WWW / Comments Off on How to Setup a Web Proxy for the iPhone Simulator

I have been trying to get a better view of how the iPhone makes use of certain HTTP headers.  When developing with Firefox, I usually turn on my Charles Proxy or enable a extension for watching headers, like livehttpheaders.  Fooling around with the iPhone simulator, I couldn’t find any obvious preference settings.  I also dug around with the “defaults” utility in OS X, but only came up with the following keys:

mikebrittain$ defaults read com.apple.iPhoneSimulator
{
"NSWindow Frame iPhoneSimulatorWindow" = "287 10 386 742 0 0 1280 778 ";
windowOrientation = 1;
}

So I took a closer look at Charles to see if there was a solution in there.  I was surprised to find that this is actually very easy to do.  Under the Proxy menu, there’s an option for Mac OS X Proxy.  Enabling that seems to make it possible to have all HTTP traffic proxied through Charles.

Are there other solutions I’m missing?

Tags: , , , , ,

I like Google Chrome

Posted by Mike Brittain on September 04, 2008
WWW / Comments Off on I like Google Chrome

I like Google Chrome.  I think there’s a lot of good stuff going on in that project, even if it doesn’t become a mainstream browser.  I had a lot of thoughts about the direction Google is taking with Chrome, and Felix seemed to touch on a lot of them his post about Chrome, so I just tacked on some of my thoughts the end of that.

Tags: , ,

Back to Dreamhost

Posted by Mike Brittain on September 02, 2008
WWW / Comments Off on Back to Dreamhost

It took me a few months running my blog on WordPress before I decided that I’d like to have a little more control over the layout and plugins.  Tonight I moved back to Dreamhost which allows for pretty simple installation, and allows any customizations I want to make.

Nothing bad to say about WordPress, however.  I love the software, and the hosted solution is fantastic if you don’t have your own hosting account elsewhere.

I’ve been a Dreamhost customer for many years now.  I’m not surprised that I ended up switching my blog site back over.

Tags: ,

Lost Opportunity for CDN Promotion

Posted by Mike Brittain on June 17, 2008
WWW / Comments Off on Lost Opportunity for CDN Promotion

Today, Firefox 3 is released to the public.  The Mozilla organization decided to shoot for a Guinness World Record for most downloads in a single day.  So far, it’s anyone’s guess whether they’re on track to reach that goal.  The site has been unreachable during the last hour.

This might have been a great opportunity for one of the big CDNs, or even one of the smaller ones, to jump on board with some pro-bono hosting in order to get some publicity related to this launch.

Tags:

Traffic Reports via Twitter

Posted by Mike Brittain on May 19, 2008
WWW / Comments Off on Traffic Reports via Twitter

Just came across this Twitter feed by accident (no pun intended)… Boston is apparently using Twitter feeds to broadcast messages about traffic conditions in the area.

I wonder who else is doing this?  I don’t have time at the moment to check in on others, but this is really interesting in terms of what other public information could be broadcast in this way.

Tags:

Translate Words From Your BlackBerry or Opera Mini Browser

Posted by Mike Brittain on May 17, 2008
Mobile, WWW / Comments Off on Translate Words From Your BlackBerry or Opera Mini Browser

I recently released a web application for use on iPhones for language translation while on the go. Enter a word or phrase and instantly get a translation into another language. Seems like it’d be a great tool for travelers and students, especially.

Today, I have added support for the BlackBerry and Opera Mini web browsers. Just point your mobile phone at this address to get started:

http://m.mikebrittain.com/tr