I have a nodejs application where res.render
method of express is taking about 400 ms in a blocking way. How do I handle this to execute in a non blocking way? My apache benchmark takes 12 seconds for executing around 30 concurrent requests. How do I implement this in a better manner?
var start = +new Date;
//fetch data from redis
console.log('time taken to fetch data from redis ' + (+new Date - start)); //30 ms
res.render('some_jade_view', params);
console.log('time taken to render data ' + (+new Date - start)); //530 ms
I tried process.nextTick
but it did not help much, ab results are the same.
I think you should really take a look into https://github.com/caolan/async.
Directly from Async's repo:
Cheers.
Edit: I'm not sure if rendering your view in an asynchronous manner would really help you reduce your times. You may want to implement a stream on the client side that fetches and templates the data as it is coming along. You could use a front end framework like Angular for that, or do it manually.