As we all know, HTTP is a stateless protocol. We do all sort of hacks to add state, like ext/session in PHP. While such hacks work great for a lot of use cases, we should remind ourselves that they are hacks. There is a phenomenon of state creep: coupling unrelated HTTP requests. Think of a page that references a thumbnail in an <img/>-tag and the picture is generated as needed: it would be possible to generate that image in the context of the request that embeds that image. So the template calls a helper to generate the thumbnail and the thumbnail is generated in the file system.
While this works well for a single host, your personal weblog about cooking and cats, it won’t work for something serious. When you start load balancing between two webserver nodes you are set on fire as you can’t guarantee that the image is present on the correct node (beside you are generating the image n times where n is the number of nodes). The solution is not that hard: pregenerate all the images with a queuing system and display “This image is currently not available”-placeholders as long as they are not ready or – in case of little image uploads – generate them when uploading the image. The other option is to generate them on the fly when they are requested. If you do the latter, do it in the context of the request that tries to receive the image, not in the embedding context (the page that embeds the image). Generating on the fly means that you deliver your files through PHP or something similar: this is fine as long as you have an HTTP accelerator in place.
One of the systems that does it in the way described above is Drupal. I’ve implement MogileFS for image storage and retrieval for Drupal and let me say, it was not a pleasure.
On a side note: HTTP 1.1 allows resources to be fetched in parallel, which makes generating images in the wrong context even worse from a user experience point of view, as the page will not show up until each thumbnail is generated.
Comments
Show comments linear or threaded
Lukas states:
published on 2008|09|25, 17:53hI usually solve this situation with mod_rewrite. If a picture is missing, it is pointed at a script to generate the image, put it into the file system and return it directly for this request.
Obviously this means that all necessary information to generate the image needs to be embedded in the pictures name, but this has so far not posed a problem for me.
Lars Strojny opines:
published on 2008|09|26, 12:47hThat’s a good idea, yes. Another solution which requires no code change is illustrated here.
John McHugh opines:
published on 2008|10|02, 02:35hHi, theres been allot of great work being done on trunk for Rhythmbox atm.
One of the things which was fixed was RB_SHELL_UI_LOCATION_MAIN_BOTTOM .
It has been relocated to below the browser source instead of below the album art and browser.
This means that the recommendation’s plugin needs some work.
What I was thinking was that the recommendations plugin should maintain the same height as the album art at all times. Also the similar artist scroll box background should be white.
The last thing is that instead of having header above the recommendation plugins widget for showing/hiding there should just be an option in the view category in the menu bar.
oh, one last thing, there should be options in the plugin browser to automatically show the recommendations when a new track starts for something like 10 seconds and then disappear.
For this use case a header might be appropriate to allow the user to click to keep the recommendations open for the entire song.
I couldn’t see why the recommendations plugin shouldn’t be included and enabled as default in Rhythmbox after these changes.
Its a really cool plugin by the way, one of the main things holding it back in my view was RB_SHELL_UI_LOCATION_MAIN_BOTTOM and now that thats been resolved it would be cool to see some of the smaller bugs squashed and see it hit main by the next release :D
Add comment