Many students may have heard of nodejs and know that it can run JavaScript on the server, but they may not be very clear about its usage scenario. Recently, they have also been learning nodejs, so I made a summary;
Advantages of NodeJs:
What are the problems with many server-side languages (PHP, JAVA,), now the server-side language creates a thread for each user link when users access the server, but each thread consumes about 2M memory. If a server with 8G memory can link about 4,000 users. If the number of users has a large number of links, the number of servers must be increased. Moreover, there are many ways for users to link at the same time (such as apps, web pages to access simultaneously), which involves the issue of server sharing, so how the server supports the maximum number of users at the same time becomes a problem;
NodeJS modified the client-to-server link method to solve this problem. It does not create a new thread for each client, but instead starts an event processed internally for each client link. Therefore, NodeJS has the ability to handle client links of up to tens of thousands of users at the same time;
NodeJS is suitable for development applications:
When an application needs to process a large number of concurrent input/output, and does not require very complex processing within the application before sending a response to the client, we should consider using NodeJs for application development, for example:
1. Chat server: If there are many people chatting, the concurrent link between the user and the server is large, but the data processing on the server side is not complicated;
2. Servers of comprehensive service websites and e-commerce websites: On the server side of this type of website, it is often possible to receive up to thousands of pieces of data per second and need to write these data to the database. NodeJs can quickly write these data into the cache through its queue mechanism, and then take out the data from the cache area and write it to the database through each separate processing. If it is another server (such as the Apache server or Tomcat server), since these servers use blocking I/O mechanisms, each piece of data needs to be written in the database for a while (after the previous one is finished before the next one is written), but NodeJs uses a non-blocking I/O mechanism, so it can implement the write of these data into the database without having to wait for a period of time for each piece of data to be written;
Summarize:
A slightly larger system cannot be handled by a development language. It is often mixed with several types, such as C and C++ for server-side development, Java for business logic, PHP for front-end display, and also requires message middleware, etc.
Nodejs can quickly prototype on the server side (it turns out that only things can be done by C-system and Java, and the performance is still very high), and the amount of code will be relatively small; the other point is its syntax advantages, js closures, etc. But it is not suitable for CPU-intensive processing, and can only be solved by turning around. It is said that someone will share this research results in QCon this time, so you can pay attention to it.
Each language has its suitable field. There is no need to force a language to solve everything. It has the characteristics of other languages. Only by constantly tradeoff to make the system is the goal.
These are all summaries seen in the series, I hope to correct them