your doubt is:
threads in the Node thread pool and multiple threads in PHP handle events. Why is Node fast?
when PHP starts multithreading concurrently, it needs to use more resources and deal with more things.
and you need to write your own logic for multithreading, but are you sure it does so even though it consumes a lot of CPU?
Node is natural, fresh and dedicated to dealing with IO, with no redundant code under historical baggage.
it has low CPU consumption, handles things as soon as it is given, receives multiple points directly, and then returns after seeing whether the corresponding thread should be created to get the result according to the specific matter.
as you said, CPU is more efficient, and IO, can continue to execute other code without blocking and waiting.
Nodejs
has the advantage of event-driven
, that is, asynchronous operations
.
for example, for multi-file IO operations, Nodejs can be read asynchronously. After reading, the event listener function is called, and the listening and execution of IO events for each file are separated. Instead of starting multiple processes as in java
, each process does a separate file IO operation.
it's not really high, it's fast asynchronous processing .
can meet the requirements of a general situation, just like 10 people lining up to enter the door and 10 people flocking to the door. Node satisfies this 10 people to enter the door at the same time. But if the scene is 100 people entering the door at the same time, the memory is soaring, then the node is dead. If it's java, slow down, but at least it won't hang up.
to put it simply, node is going to be processed at the same time, so you don't have to wait one by one.
java these slows need to be done one by one, not in a hurry. However, there are many frameworks that support asynchronous execution of java/php.
it is very efficient, ah, it is a runtime-level thing, and it is all marked with the language level of Java. So is jvm's sense of existence so weak? In addition, javascript has a large number of quick users, which is also an advantage. As for those who compare with this and that, they are all propaganda. Don't worry about it.
< hr >
I think it makes more sense to see IO. You can refer to teacher Park Ling's preliminary study on the implementation of Asynchronous Icano of Node.js