1 year ago
#387531
Andrey Grigorev
Can you help me understand the assertion about node js thread(s)?
Backstory
I recently completed my Node.js skill assessment on LinkedIn, which is basically a small test. But i noticed a question with a weird answer, which i can not understand.
Question
How does it affect the performance of a web application when an execution path contains a CPU-heavy operation, such as calculating a long Fibonacci sequence?
Right answer
The current thread will block until the executon is completed and the operating system will spawn new threads to handle incoming requests. This can exhaust the number of allowed threads (255) and degrade performance over time.
Problem
I always thought that node is not creating a new threads unless you're using something like child-process
or workers. I tried to create a simple express server with one endpoint, that is blocking execution forever:
app.get('/', (req, res) => {
console.log('recieved request');
while (true) {}
});
And when i tried to send multiple requests, only one log message has appeared, which means that new thread is not created to handle new request.
So, is this answer just incorrect (even though it seems as a correct one), or am i misunderstanding something?
node.js
multithreading
linkedin-api
threadpool
libuv
0 Answers
Your Answer