Short polling, long polling, long connections, and short connections in the HTTP protocol

Source: Internet
Author: User
Tags socket error

Today began their own study of Nodejs, see poll, under study

HTTP protocol Description:

The HTTP protocol is a request/response paradigm, and each HTTP response is generated by a corresponding HTTP request; The HTTP protocol is stateless, and there is no relationship between multiple HTTP requests.

In the case of long-connected applications, the client side generally does not actively shut down their connection between the client and the server if the connection is not closed, there will be a problem, as the client connection more and more, the server sooner or later can not carry the time, At this time, the server side needs to take some policies, such as the closure of some long-term no read and write events occurred connection, so as to avoid some malicious connection caused server-side service damage, if the condition is allowed to the client machine for granularity, limit the maximum number of connections per client, This can completely avoid an egg-hurting client from compromising the backend service.

The generation of long and short connections is based on client and server shutdown policies, specific application scenarios with specific strategies, no perfect choice, only the right choice

Application Scenario Differences:
1. General long connection (the pursuit of real-time high scene) for a few client-end to server-end frequent communication , for example: Database connection with long connection, if with short connection frequent communication will cause socket error, and frequent socket Creation is also a waste of resources.
2. HTTP services like Web sites typically use short links (for resource-prone scenarios) because long connections can be resource-intensive for the server, and tens of thousands or even billions of clients, such as Web sites, with short connections can save resources .

Short polling and long polling

and short connections and long connections have essential differences
1. Short polling: repeatedly sending HTTP requests, querying whether the target event is complete, advantages: Writing simple, disadvantage: wasting bandwidth and server resources
2. Long polling: Hold the HTTP request (dead loop or sleep, etc.) on the server until the target time occurs, returning the HTTP response. Pros: No more frequent requests in the absence of messages, disadvantages: writing complex

Application:

Long polling generally used in web IM, im high demand for real-time, HTTP long polling control is always on the server side, and the data is on the server side, so the real-time high;
Like Sina's meager IM, friend net IM and WEBQQ are all implemented with HTTP long polling;
NodeJS's asynchronous mechanism seems to be able to handle the server bottleneck caused by HTTP long polling, which needs to be researched.

HTTP short polling generally used in the real-time requirements are not high, such as Sina's meager unread bar number query is browser-side every time query.

Short polling, long polling, long connections, and short connections in the HTTP protocol

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.