Home > Common Problem > What is a long connection?

What is a long connection?

coldplay.xixi
Release: 2020-06-28 15:14:14
Original
4960 people have browsed it

Long connection means that multiple data packets can be sent continuously on one connection. During the connection maintenance period, if no data packets are sent, both parties need to send link detection packets. It is mostly used for frequent operations and point-to-point communication. And the number of connections cannot be too many.

What is a long connection?

Long connection is:

1. Definition

Short connection means that when the communicating parties have data exchange, a connection is established. After the data is sent, the connection is disconnected, that is, each connection only completes the sending of one business.

Long connection means that multiple data packets can be sent continuously on one connection. During the connection maintenance period, if no data packets are sent, both parties need to send link detection packets.

Long connection is mostly used for frequent operations, point-to-point communication, and the number of connections cannot be too many. Each TCP connection requires a three-step handshake, which takes time. If each operation is a short connection, the processing speed will be reduced a lot if it is operated again. Therefore, it will not be disconnected after each operation, and the data will be sent directly the next time it is processed. The package is OK and there is no need to establish a TCP connection. For example: the database connection uses a long connection. If short connections are used for frequent communication, socket errors will occur, and frequent socket creation is also a waste of resources.

HTTP services like WEB websites generally use short links, because long connections will consume certain resources for the server, and like WEB websites, there are thousands or even hundreds of millions of client connections so frequently. Using a short connection will save some resources. If you use a long connection and there are thousands of users at the same time, it is conceivable if each user occupies one connection. Therefore, the amount of concurrency is large, but each user needs to use a short connection if they do not need frequent operations.

In short, the choice of long connection and short connection depends on the situation.

Related learning recommendations: PHP Programming from beginner to master

2. Application

(1), mobile push principle

The principle of mobile push service is very simple, that is, by establishing a connection link between the mobile phone and the server, when there is a message that needs to be sent to the mobile phone, it can be sent through this link. Although the usage process of the push service is slightly different, it is generally similar to the APNS of IOS

1. The first is the application registration message push.

2. IOS and APNS Server require deviceToken. The application accepts deviceToken.

3. The application sends the deviceToken to the PUSH server program.

4. The server program sends a message to the APNS service.

5. The APNS service sends messages to the iPhone application

(2). Push scheme evaluation criteria

The recognized evaluation of the push scheme takes 4s Standards: 1.Safe (safe) 2. Stable (stable) 3.Save (saving power, traffic and cost) 4.Slim (small size)

1.Safe (safe)

The push solution should support transparent transmission and various encryption schemes to ensure the security of information transmission.

The ID system of the push solution should be independent of the ID system of the existing website or service, so as to ensure the accuracy of information delivery after users log in on different mobile phones and avoid network transmission failure due to failure of unbinding events. resulting in misdelivery of information.

2. Stable (stable)

Stability includes two parts: one is the stability of the server side, and the other is the stability of the mobile phone side.

Server-side stability, because the use of long-term connection solutions imposes great overhead and requirements on the server. The push solution has high requirements for server development. Server stability under massive thread connections is very challenging. General evaluation criteria include:

- Peak value when online at the same time (generally evaluated as server stability when one million concurrent connections are made)

- Average message delay time during high concurrency (generally processed as 1 minute) 1 million messages evaluation)

- Service stability (generally required to be available more than 99.9% throughout the year, with backup, load balancing, etc.)

In view of the difficulty of developing a stable server, It is not recommended for small teams to develop by themselves. It is recommended to use stable third-party push solutions, such as Getui, Butterfly, etc.

The stability of the mobile phone is mainly due to China's complex network conditions and mobile phone model adaptation, which makes it difficult for mobile phones to stably connect to the Internet for a long time, so stability is very important. The general evaluation criteria include:

- The proportion of users who are connected to the Internet for more than 23.5 hours a day (indicating the stability of the Internet)

- The reception rate within 9 hours after the message is sent (indicating the arrival rate)

Generally speaking, push solutions To adapt the network to different operators, provinces, and models, the workload of self-development is relatively large

3.Save

Power saving application Pay attention to CPU hibernation, generally use the service shortened standby time percentage to judge

To save traffic, pay attention to the modification of the protocol and the processing of redundant data packets, generally use the no-load standby monthly traffic to judge

To save costs Considering the number of simultaneous connections a single server can carry, the more simultaneous connections it can carry, the lower the cost. The top level in the industry is GeTui’s single server with 500,000 connections

4.Slim (small size)

The push service should be as small as possible without affecting the size and complexity of the main program. Generally, it should be less than 300K.

The above is the detailed content of What is a long connection?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template