The Life and Times of James R J Constable Code and Pictures

SPL Champions 2009

SPL Champions 2009, originally uploaded by WeeJames.

Taken at the title party at Ibrox.

Title Party

Title Party, originally uploaded by WeeJames.

Pushers in the Park

Pushers, originally uploaded by WeeJames.

Clyde Sunset

Clyde Sunset, originally uploaded by WeeJames.

Count the Number of Files in a Directory in Linux

Again, part of the ‘need to write this down somewhere cos i’ll need it at some point in the future’ series – counting the number of files in a directory in Linux.

ls -1 | wc -l

Batch Processing Images in Ubuntu with Image Magick

The main point of this blog post is so that I have a resource next time I need to do this job. I’ve recently been presented with thousands of images that need to be converted to different sizes and didn’t really want to go to the hassle of installing some 3rd party utility or writing a script.

ls *.png | xargs -I {} convert -thumbnail 200 {} thumb.{}

You can add whatever arguments are required to the convert command.  In this case i’ve specifed a thumbnail with a width of 200px.  The brackets {} represent the file you’re operating on so in the example above the new image has thumb. prepended to the filename.

Hosting Sites with Heavy Traffic on Amazon EC2

I mentioned previously that I’d been looking at Amazon EC2 as a solution to host a site that underwent heavy bursts of traffic for only a couple of hours a week. The expected traffic bursts were 10-15k visitors in a 2 hour period and unfortunately a small EC2 instance just wasn’t enough. The next trial was with a large EC2 instance, with Apache tweaked to allow more simultaneous connections. Results went better than first time but I ended up having to bounce Apache a couple of times during the time frame to get it back up and running.

So fast forward to this week and it was time to try again. This time I went with an Extra Large instance running a stock 64-bit Ubuntu 8.04 and Lighttpd instead of Apache. And this time there were no problems. For the full 2 hours the site remained up and responsive, and because I could time the instance to come up just before the additional cost was negligible.

To give you an idea of the kind of traffic it had to deal with, the site took in just over 25,000 unique visitors in a 2 hour time frame. Glad to get the problem solved and now I know what to do next time I need some heavy traffic handled.

Encoding Flash Video (FLV) in Ubuntu 8.04 using FFMpeg

Recently while helping a friend with their website I required the need to convert any video file uploaded to FLV and have that display on the site.  My first instinct was to set up a conversion pipeline using FFMpeg on the Ubuntu server and have that convert the videos as required.  Unfortunately there seems to be an issue with the standard FFMpeg release on Ubuntu as it has issues attaching the sound when converting to Flash video.

Luckily it can be fixed fairly trivially by installing FFMpeg from Medibuntu.  Turns out the FFMpeg is in Medibuntu as some of the encoding libraries it use may violate some patents.

To get things up and running start by adding Medibuntu to your sources lists

sudo wget http://www.medibuntu.org/sources.list.d/hardy.list -O /etc/apt/sources.list.d/medibuntu.list

and then add Medibuntu to your sources keyring

sudo apt-get update && sudo apt-get install medibuntu-keyring && sudo apt-get update

Finally, install FFMpeg and its related tools

sudo apt-get install ffmpeg
sudo apt-get install libavcodec-dev libavcodec1d libavformat-dev libavformat1d libavutil-dev libavutil1d libpostproc-dev libpostproc1d libswscale-dev libswscale1d

And now when doing conversions with FFMpeg on Ubuntu the sound should be properly encoded as well.  This information was grabbed from the Ubuntu Forums.

links for 2009-04-17

More on Hosting with Amazon EC2

After moving the hosting of oceanseventy to Amazon EC2 before departing for pastures new I was fairly keen to try it out again on a site that was more than a few hundred hits a day.  I recently had call to host a single static page that would get hit about 13,000 times within the space of a couple of hours – but do very little for the rest of the time.

So I set up a small instance running on EC2, running Ubuntu 8.04 and tweaked Apache2 a little to increase the MaxClients setting.

Unfortunately not everything went to plan.  While the server itself was rock solid the response times from Apache grew very quickly to 20+ seconds.  So I’m trying to figure out what the next plan of attack is.  Do I set up a load balancer on EC2 and share the load with a number of instances, or do I go with a larger instance for the duration of the traffic spike, upgrading to a large or extra large instance.  Are there some settings I should be tweaking on Apache?  Should I be trying out an alternate webserver like Lighttpd?

Or maybe I give up and get back to the day job :)  Any advice appreciated.

← Before