3 ms·
I'd use something like DelayedJob and send_later the call to your image processing stuff, that way the forking happens out of the request path, at least.
by swombat 17y ago
I'd use something like DelayedJob and send_later the call to your image processing stuff, that way the forking happens out of the request path, at least.
- patio11 17y agoYou just described my exact setup. However, my understanding is that Delayed::Job's worker threads have a full Rails environment in them, and if this blog post is correct and I am indeed forking that entire Rails process for every call out to ImageMagick, my vague recollections of what a fork entails suggest to me that the Ghosts of C Programmers Past are going to visit a terrible vengeance upon me.
- swombat 17y agoOnly if you run out of memory. But with DJ at least you should be forking only one call at a time, rather than multiple, like you might from the controller itself. So although you'll end up using more memory, it'll only be one extra rails process, not 4. May not still be ideal... interested to hear other people's ideas.
- simonw 17y agoUse http://github.com/documentcloud/cloud-crowd http://github.com/documentcloud/cloud-crowd
- jeremyw 17y agoThe fork+exec is efficient. The blog post compares things without units. Forks (principally page table copies w/copy-on-write in effect) are measured in microseconds and the exec is your standard binary startup time. While you don't want to put a synchronous fork/exec in the way of 5,000 reqs/sec, it will be a trivial part of your asynchronous imagemagick processing. At scale, you might care about the imagemagick startup latency, but not the forking.