I have recently been developing some fancy AJAX upload progress meters for a project I’m working on. This is using the new(ish) hooks in PHP which, when coupled with an extension such as APC, allow for polling of the upload progress as a file uploads in a standard HTML form.
Developing on a local server, however, means that file uploads are near instantaneous which makes testing… problematic. How best to simulate a real user’s experience?
My first instinct was to see if there were any suitable modules for Apache to enable bandwidth throttling. Apache 1.3 has mod_throttle which seems to be up to the task but I’m using Apache 2 and I don’t believe mod_throttle has been ported yet.
There also seem to be some extensions for Firefox which enable bandwidth limiting but these, unfortunately, are written for Windows environments.
The solution? trickle. Trickle is a portable lightweight userspace bandwidth shaper. It allows bandwidth limiting on a per-program basis and can be simply called with the executable as one of its parameters. Even better, it’s available in the Ubuntu repositories:
apt-get install trickle |
So, to restrict Firefox’s upload bandwidth we can run the following command:
trickle -s -d 1000 -u 10 firefox |
This limits the upload rate of Firefox to 10Kb/s. Perfect for testing form uploads.
Note: The -d flag shouldn’t be necessary (according to the
docs) but without this arbitrarily high setting, download bandwidth seems to be hampered. The -s flag merely instructs trickle to run in standalone mode (as opposed to running through the trickle daemon).
Leave a Reply