Asynchronous image loading

Loading
After my cousin Roz reported she had trouble getting the app to load, I decided to add some very basic asynchronous image generation logic to Funhouse Photo. I found it was possible to get PHP exec() to run commands in the background if you piped stdout to /dev/null, so I set up a system that fired off all the image generation commands using that method, and returned a loading screen immediately.

That loading screen contains a setTimeout() javascript call that reloads the current page after five seconds, on the assumption that the images will have been created by then. If they aren’t, then another reload is caused.

There’s one big reason I chose to implement the loading this way; it’s very simple. It does have some disadvantages:

  • There’s the risk of infinitely reloading the page if an image command fails.
  • The user experience is pretty grotty. The redirect seems to take a very long time to complete, on the order of ten seconds or so. I’m not sure if this is Facebook doing something whacky, or me. Using top on my server shows a lot of idle time during these pauses, so I’m not sure where the delay is coming from.
  • You see a blank screen while the redirect is occurring, rather than anything a bit more compelling.

One idea I’m thinking about is pre-generating all possible images for all your friends when you first add the app, or at least for yourself. That seems like it could make the server load a bit less ‘peaky’, and spread the work out a bit. It would definitely require some kind of queuing/batch system though, and I haven’t made any progress on that.

I’m also looking into a more fine-grained and sophisticated lazy image generation method, like the one suggested by Stephen. It’s somewhat tricky on Facebook since all the image tags are rewritten, but I definitely think it’s the right direction to go in.

Funhouse Photo User Count: 507 total, 64 active daily. A great day of growth, with more than 100 new users since yesterday. I’m glad to see the growth accelerating a bit, though I don’t know how much of that was due to bored folks on Labor day! We’ll see what it looks like tomorrow. The active count was low. Hopefully adding in some new effects, now I’m done with foundation stuff, will help that out.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: