- 1. Composition of application
- 2. Types of applications
- 3. Application service process
- 4. Application bottleneck
- 5. Distributed application
- 6. Multi process node js
First of all, we should clarify what is large-scale application. In fact, it is a matter of different opinions, and it is a philosophical problem, not a technical problem. If someone asks you, how big is a website that can sell online, such as UNIQLO? You may say big, because it’s really complicated compared with the logic of blogs and enterprise official websites you usually see. Or small, it means that you have developed a more complex system than it. What about Taobao? There should be a reference for the comparison between large and small.
1. Composition of application
Can a complete web application consist of only one language or one technology? impossible. Because a complete web application is actually a complex of multiple technologies. There are many solutions to a problem, such as many back-end logic solutions, such as Java, PHP, python, ruby, etc.
Briefly, the components of the application may include:
Web interface display logic; Back end business logic; Cache; database Message queuing.
In fact, log analysis and data analysis can also be added, but the above are the most well-known.
2. Types of applications
I / O intensive; CPU intensive.
For common Internet products, its bottleneck is not in the logic of back-end business, but in I / O, that is, the reading and output of data returned to users. Compared with applications, read in refers to obtaining data from the database, while output refers to outputting these data to the user’s browser after certain processing, so this is I / O intensive.
CPU intensive refers to applications that do frequent computing tasks, node JS is really a short board in this regard.
3. Application service process
As shown in the figure, the user sends a request through the browser, the network card receives the TCP connection, notifies the kernel, and the kernel calls the corresponding server program.
Response return procedure
As shown in the following figure, in order to return data, the web application must first obtain the data, call the disk driver through the kernel and read the data into the cache, so that the data can be obtained and processed in the web application, and finally call the kernel to send the data to the client through the network card.
4. Application bottleneck
Usually, the bottleneck of I / O-Intensive is the reading and writing of disks. Therefore, when purchasing ECs, you can buy SSD disks to improve performance. Generally, the data of database software is stored on files. First of all, consider adding memory cache to solve this bottleneck, cache frequently accessed data, and see whether it can solve the problems of the current scene, such as using redis. Secondly, it is considered to build or expand database clusters to improve concurrency.
The CPU intensive application bottleneck is on the CPU, which can only be solved by adding CPU processing core.
5. Distributed application
Large scale ordinary applications and distributed applications are actually different concepts. Readers can simply understand the distributed application as a team. Each member is a node. If members cooperate to complete a large project, there will be some communication costs between members. Some members even quarrel with each other, talk openly and secretly, and shirk their responsibilities. It is also possible that members are ill, recuperate at home and can’t work, and so on. In the face of these problems, node The advantages of JS are not well shown (it is not impossible to do, but there is no perfect infrastructure).
The real definition of distributed is to deploy different service modules in multiple different servers, take the process as the basic unit, send them to the server, communicate and work together through remote call (RPC), and finally provide services to the outside world.
Compare node JS current distributed infrastructure, go language infrastructure is much more perfect, especially in the docker project, which fully proves the advantages of go language, which is why node JS community “Daniel” TJ holowaychuk turned to go language because he wanted to develop distributed applications.
6. Multi process node js
After understanding some of the above knowledge points, readers should know that node JS has little to do with large applications. Most learn node The developer of JS is a front-end developer, so he doesn’t know the basic knowledge of the back-end. When searching for some information on the network, he found node JS can only use a single core, and I heard that TJ holowaychuk turned to the go camp, so some developers created node JS is not suitable for developing large-scale applications.
Node. The problem that JS can only use a single core has been solved, and egg. JS is used later The eggcluster module in JS framework solves this problem very well by using multiple processes.
That’s why node JS is not suitable for large projects. For more details, please refer to node JS, please pay attention to other related articles of developeppaer!