Apache’s multi-threaded high concurrency mode

Advantages: Supports multi-threaded concurrency

Disadvantages: Blocking

What is a thread

A thread is the smallest unit of CPU that can run independently. It can run concurrently in the same process, sharing the memory address space of that process.

When different threads need to occupy the same variable, according to the principle of first come, first served, the first thread to run, the later thread can only wait nearby, that is, join the blocking queue. It causes the thread to block.

Similar scenario: Handling services over a bank counter

Asynchronous I/O principle of NodeJS

Advantages: High concurrency (the most important advantage), suitable for I/O intensive applications

Disadvantages:

  1. Not suitable for CPU intensive applications (The main challenge for Node in CPU intensive applications is that due to the single-threaded JavaScript, if there are long running computations (such as large loops), CPU time slices will not be released and subsequent I/ OS will not be able to be initiated).
  2. Only single-core cpus are supported and cpus cannot be fully utilized
  3. (1) Nnigx reverse proxy, load balancing, open multiple processes, bind multiple ports; (2) Nnigx reverse proxy, load balancing, open multiple processes, bind multiple ports; (2) Open multiple processes to monitor the same port, using the Cluster module. (3) Use the PM2 management process online, and automatically restart the project if there is any problem
  4. Debug is inconvenient, error does not have stack trace

NodeJS is based on an event loop, where each NodeJS piece of logic is written into a callback function that executes asynchronously upon return.

NodeJS does not block, but blocks do not occur in the flow of subsequent callbacks, but in the calculation and processing of the logic by NodeJS itself.

NodeJS can hand over all of its I/O, network communication and other time-consuming operations to worker Threads for callback, so it’s very fast. But the CPU’s normal operation, it can only operate on its own.

Similar scenario: Queue for food and call to pick up the food.

Application scenarios of NodeJS

NodeJS is strong on concurrency, but weak on computation and logic.

As a result, we move the complex logical operations to the front end (client side), while NodeJS only needs to provide asynchronous I/O, which enables high performance handling of high concurrency.

RESTful API

This is the ideal scenario for NodeJS, which can handle tens of thousands of connections without much logic of its own. You just need to request the API and organize the data back.

It’s essentially just looking up some values from some database and putting them together into a response.

Because the response is a small amount of text and the inbound request is a small amount of text, the traffic is low and a single machine can handle the API requirements of even the busiest companies.

Application of a large number of Ajax requests

Real-time chat, client logic strong single-page APP, specific examples such as: localized online music application, localized online search application, localized online APP and so on.

Apache Application Scenarios

Apache because of its multi-threaded high concurrency shared memory address space characteristics, that means that if the server is powerful enough, the processor is high enough core, Apache will work very well, so it is suitable for (concurrent) asynchronous processing relatively less, background computing, complex background business logic applications.

Related articles

12 Benefits of Using Node.js For Web Applications

Why to Use Node.js: Pros and Cons of Choosing Node.js for Back-end Development