News for hackers. Stuff that matters.
Re:An expensive line of code: scaling Node.js on Heroku (2013) by partycoder on Thursday September 29, 2016 @12:19AM (#12603277)
node is meant to be used in scenarios when you give most of the work to libuv. However, if you to CPU intensive work in JavaScript itself, such as:

- serialization

- encoding

- cryptography

- compression

- etc. ... then, you are better off doing it on a lower level language. express logger counts as a form of serialization, and therefore it is slow.

If you absolutely have to do CPU intensive work... then: limit per-tick execution time and break it down into multiple ticks, otherwise you will block the node event loop and your system will degrade until it stops processing requests.

Now, you can find this faster by profiling. Just use a profiler, like nodegrind or flame graphs or whatever, you will find those bottlenecks very quickly.

Re:An expensive line of code: scaling Node.js on Heroku (2013) by sjnair96 on Thursday September 29, 2016 @05:15AM (#12604094)
If you don't mind, could you explain in detail (or link to resources) the points you bring up? It seems extremely interesting.
Re:An expensive line of code: scaling Node.js on Heroku (2013) by amelius on Thursday September 29, 2016 @05:21AM (#12604109)
Well, it boils down to the fact that libuv (part of Nodejs) helps in fair scheduling for I/O resources; but the CPU is a resource too, and there is no scheduling taking place for that resource. Therefore, heavy CPU use without proper yielding can block other activities. Since the CPU is involved even in starting I/O operations, heavy CPU use can also block I/O, and in fact it can block the whole process.
Re:An expensive line of code: scaling Node.js on Heroku (2013) by tboyd47 on Thursday September 29, 2016 @07:53PM (#12609695)
Interesting - does template rendering also count as serialization?
Re:An expensive line of code: scaling Node.js on Heroku (2013) by tedd4u on Monday October 03, 2016 @03:38PM (#12630627)
Yep. You can benchmark your server with template rendering and then benchmark again just outputting the values you plug into the templates without rendering them to get a sense of what it's costing you in terms of throughput, latency, etc. The advantage of node.js for serving websites I believe lies in the reusability of JS code on server and web browser, and that outweighs this issue. But you have to make sure your template rendering is efficient enough or be willing to spread the load across enough cores.
Re:An expensive line of code: scaling Node.js on Heroku (2013) by aikah on Thursday September 29, 2016 @05:50AM (#12604212)
Or just ditch node and write your server in Go. There is no reason to use node server side today, unless that task is specifically javascript related. There is 0 advantage in using nodejs.
Re:An expensive line of code: scaling Node.js on Heroku (2013) by roelvanhintum on Thursday September 29, 2016 @07:22AM (#12604436)
A universal React application would be one...
Re:An expensive line of code: scaling Node.js on Heroku (2013) by Veen on Thursday September 29, 2016 @07:07AM (#12604396)
Or Elixir.