avck
avck

Reputation: 3693

How can node use more than 100% CPU if it is single threaded?

I am running an express.js server. When I send some load the cpu usage spikes to over 140%.

I understand that since the system I am running the server on has 4 cores so it can go upto 400% as well.

My question is:

  1. How can node.js application consume more than 100% despite being single threaded?
  2. To improve the performance should I run the server in cluster mode? Currently a lot of requests are in http_request_waiting state.

Upvotes: 2

Views: 1653

Answers (1)

kavigun
kavigun

Reputation: 2365

Although the node is a single-threaded model that efficiently works on a single thread to serve the requests. But, it's underlying IO model is multi-threaded. There are two libuv components that act during the process one is event-pool and the other one is thread-pool and this thread pool is allocated with blocking operations like file reading, database queries, and IO operations.

Upvotes: 2

Related Questions