Depth analysis of the Java Web technology insider reading notes

Recalling the history of this book review will be added, reason is nothing of interest, furthermore this article is to summarize the main and add their own thinking

0. Introduction

The ability to learn is more important than the mastery of knowledge itself , will inevitably arise in the process of learning the knowledge of many of the challenges and overcome these problems ( identify problems - analyze the problem - solve problems ), many such process is cumulative up ( cumulative, good memory as bad written, must have a clear record, even after forgetting can also quickly picked up ). Furthermore industry learn to avoid the limitations of superficiality (limitation refers only know after the back-end development end development, in theory, people will naturally interested to learn about front-end, hardware, algorithms, etc., superficiality means learning new technologies often only learn how to use, not the why), but how it can learn so many things ? This requires finding common knowledge and logic behind after the general logic of the development is the basis of knowledge of data structures, such as network theory, and design patterns and so on, will naturally find common logic learning easier.

1. The in-depth Web request

The web2.0 era, the Internet network architecture has changed from the traditional C / S structure is more convenient B / S Architecture (B / S architecture can be seen as a special C / S), web era?

Browser server mode on both sides has brought benefits to service users and developers have brought benefits , the traditional C / S To customize the application layer protocol, B / S is using HTTP protocol, the use of uniform HTTP, so there are many, such as Apache, Nginx, Tomcat, JBoss, etc., there are many common framework based on HTTP servers, which do not write their own, directly used, which greatly simplifies the development of the service provider

1.1B / S Network Architecture Overview

HTTP protocol layer based on a unified interaction data referenced to, HTTP is stateless communication uses a short length of the connecting

Stateless means the agreement for the transaction no memory.
In the default short connection HTTP / 1.0 in . The client and server once for each HTTP operation, once the connection is established, the task will end disconnected. When an HTML Web page or other type of client browser to access the Web contains other resources (such as JavaScript files, image files, CSS files, etc.), when confronted with such a Web resource, the browser will be re-established an HTTP session .
From the HTTP / 1.1 cases, long default connection for holding the connection characteristics. A long connection using the HTTP protocol, it will be added in response to the first line of code:
Connection: Keep-Alive
in the case of using a long connection, when a complete page opened for transferring data between the client and the HTTP server TCP connection It does not close, the client to access the server again, it will continue to use a connection has been established. Keep-Alive not permanently remain connected, it has a hold time, may be set at this time to a different server software (e.g., Apache) in. Achieve a long connection requires a client and server support long connection.
Long and short connection protocol HTTP connection, the connection is substantially long and short protocol TCP connections.
Note: Before you actually read and write operations, you must establish a connection between the client and server side, when the write operation is completed, the two sides no longer need this connection can be released in this connection. To establish a connection rely on "three-way handshake", release the need to "handshake" so that each is required to establish a connection resource consumption and time consumption.
Short link TCP, TCP long connection
Long established TCP connection can save more and closed operations, reduce waste and save time. For customers frequently requested resources, it is more suitable for long connection. But there is a problem here, the survival function of the probing cycle is too long, there is just detect it alive TCP connections, are more gentle approach, encountered a malicious connections, keep-alive function is not enough to make up. In the long connection of application scenarios, client-side generally will not take the initiative to close the connection between the connection between them, Client and server If you have not turned off, there will be a problem, as more and more client connections, server Sooner or later there could not carry the time, this time the server side need to take some strategies, such as closing the connection does not read some of the time of the incident, to avoid malicious connections leading to server-side services damaged; if the conditions before allowing it to be the client machine is the particle size, limiting the maximum length of the number of connections for each client, which can completely avoid a boring compromised client backend services.

Short connections for the server management simpler, there are useful links are connected, no additional control. However, if the customer requests frequently, will waste time and bandwidth on the establishment of TCP and closing operations. Long connections used for frequent operation, point to point communications, and the number of connections can not be too often. Each TCP connection requires three-way handshake, it will take time, if each operation are the first connection, then operate if the processing speed will be much lower, so do not disconnect after each operation, send data packets directly when processing times OK, do not establish a TCP connection. For example: with a long connection to the database connection, if the connection is frequent communication with short socket will cause an error, and frequently socket creation is a waste of resources.

And like WEB site http services are generally short link because a long connection to the server, it will consume some resources, like WEB site so often thousands or even millions of client connections will be more connected with the short Province some resources, if long connection, but at the same time there are thousands of users, if each user occupies one connection, then it can be imagined. So concurrent capacity, but each user does not need to use the case of short frequent operation even better.

1. Request the DNS domain name to an IP address corresponding
2.LB
3. From the distributed cache, file system, database, get data, and return
4. browser parses find other static resources, and initiate another HTTP request ( these requests are likely on CDN)

Reproduced in: https: //www.jianshu.com/p/a1520e73d876

Guess you like

Origin blog.csdn.net/weixin_34221775/article/details/91177084