4 ms·
Just offload it to a child process/worker, or use a job queue. How exactly would you avoid that 500ms block in other platforms?
by ricardobeat 15y ago
Just offload it to a child process/worker, or use a job queue.
How exactly would you avoid that 500ms block in other platforms?
- masklinn 15y agoThe platform does it: other requests are handled by other threads or processes (pooled or not), one request is going to consume 500ms and the rest will keep on trucking concurrently. Unless you've gone above the capacities of the machine itself, other requests will be little to not affected.
- christkv 15y agojust as in node where you run multiple processes against the same socket using something like https://github.com/LearnBoost/cluster https://github.com/LearnBoost/cluster
- ricardobeat 15y agoThat's not avoiding it. The thread in question will still block for 500ms. The same holds true for a multi-process node app.
- wlievens 15y agoThe point is that in a multi-thread architecture, you can still serve requests on the other threads. In a single-process non-blocking IO architecture, blocking CPU calculations will block everyone. Big deal. Use workers to solve that. End of story.
- etherealG 15y agowould you mind giving an example of how you would code it so that that 1 request didn't block the rest? in a browser I'd go with a setTimeout or setInterval hack to "fork" another thread. is this the same in node?
- timrichard 15y agoIn Node Web Development [Packt], the author uses a Fibonacci algorithm as an example that could block the event loop. It outlines one solution where the calculation is split into callbacks dispatched through the event loop, making use of process.nextTick()