What specifically makes Node.js more scalable than Apache?

Honestly, I have not fully understood it yet - and even understand how Node.js works as a single thread using the event model. I just don’t understand how it is better than Apache, and how it scales horizontally if it is single-threaded.

+69
apache scalability
May 16 '13 at 4:12
source share
2 answers

I found that this blog post by Tomislav Kapan explains this very well:
Why the hell would I use Node.js? Phased introduction

My interpretation of its essence, for Node 0.10, compared to Apache:

Good details

  • Node.js avoids thread reversal for each request or does not require processing a pool of requests for a set of threads such as Apache. Therefore, it has less overhead for processing requests and has a quick response.
  • Node.js can delegate the execution of a request to a separate component and focus on new requests until the delegated component returns with the processed result. This is asynchronous code and is made possible by the event model. Apache executes requests in sequential order in the pool and cannot reuse a thread when one of its modules just waits for the task to complete. Apache then queues the requests until the thread in the pool is again available.
  • Node.js speaks JavaScript , and therefore runs very quickly and processes JSON extracted from external web API sources such as MongoDB, which reduces the time required for each request. Apache modules such as PHP may take longer because they cannot parse and manipulate JSON efficiently, because they need marshalling to process the data.

Bad parts

Note. Most of the unfinished parts listed below will be improved with the next version 0.12, what you need to know.

  • Node.js sucks in computationally intensive tasks , because whenever it does something for a long time, it queues all other incoming requests because of a single thread. Apache typically has more threads, and the OS will carefully and fairly plan CPU time between these threads, while still allowing new threads to process, albeit a bit slower. Unless all available threads in Apache process requests, Apache also runs queue requests.
  • Node.js does not fully utilize multi-core processors , unless you create a Node.js cluster or flip child processes. Ironically, if you do the last two, you can add an even more complex task, the same problem as Apache. Logically, you could also deploy more Node.js processes, but this is not controlled by Node.js. You will need to check your code to see what works best; 1) multithreading from Node.js with clusters and child processes, or 2) several Node.js. processes

emollients

All server platforms have an upper limit. Node.js and Apache both reached it at some point.

  • Node.js will reach its fastest when you have complex computing tasks.
  • Apache will reach it faster when you throw tons of small requests that require long sequential execution.

Three things you could do to increase the bandwidth of Node.js

  • Use multi-core processors by creating a cluster , use child processes, or use a multi-processor orchestra such as Phusion Passenger .
  • Establish work roles associated with the message queue . This will be the most efficient solution for intensive computing queries with intensive computing; unload them on a working farm. This will allow you to split your servers into two parts; 1) public clearing servers that accept requests from users, and 2) servers of private workers who perform long-term tasks. Both are associated with a message queue. Clerical servers add messages to the queue (incoming long requests). Worker roles listen for incoming messages, process them, and can return the result to the message queue. If a request / response is required, the administrator can wait asynchronously when the response message arrives in the message queue. Examples of message queues are RabbitMQ and ZeroMQ .
  • Install a load balancer and increase the number of servers. Now that you use equipment efficiently and delegate long-term tasks, you can scale horizontally. If you have a load balancer, you can add additional servers. Using the message queue, you can add more production servers. You could even set it up in the cloud so you can scale on demand.
+83
Feb 15 '14 at 4:06
source share

It depends on how you use it. Node.js is single-threaded by default, but using the (relatively) new cluster module you can scale horizontally across multiple threads.

In addition, your database needs will also determine how scalable with Node is. For example, using MySQL with Node.js will not do you nearly as much good as using MongoDB, due to the event-driven nature of both MongoDB and Node.js.

The following link has many good system tests with various settings: http://www.techempower.com/benchmarks/

Node.js does not rank the highest, but compared to other settings using nginx (no apache in their tables, but close enough), this is pretty good.

Again, this greatly depends on your needs. I believe that if you just use static websites, it is recommended that you stick to a more traditional stack. However, people did some amazing things with Node.js for other needs: http://blog.caustik.com/2012/08/19/node-js-w1m-concurrent-connections/ (c10k? Ha!)

Edit: It's worth mentioning that you really don't β€œreplace” just apache Node.js. You would replace apache and php (in a typical lamp stack).

+37
May 16 '13 at 4:39
source share



All Articles