当前位置:网站首页>Polling and long polling
Polling and long polling
2022-06-25 12:28:00 【Yu Qin】
polling : To put it bluntly, the client requests the server regularly , It is the client's active request to promote data update ;
Long polling : To put it bluntly, it is also the client request server , But the server does not return immediately , Instead, the content is returned to the client only when it is updated , In terms of process , It can be understood that the server pushes content to the client ;
You can see the difference :
polling :
1: It consumes a lot of server memory and broadband resources , Because the server keeps requesting , A lot of times No new data updates , Therefore, most requests are invalid requests
2: Data is not necessarily updated in real time , It depends on the set request interval , Basically there will be delays .
Long polling :
1: Solved two major problems of polling , Real time data update ;
2: The only disadvantage is that the server consumes more memory when it is suspended ;
web In communication A long connection Long polling
be based on HTTP Long connection of , It's a long polling method “ Server push ” Technology , It makes up for HTTP The disadvantages of simple request response mode , It greatly enhances the real-time and interactivity of the program .
What is long connection 、 Long polling ?
The simple point is that the client keeps sending requests to the server and then goes to the latest data information . there ' constantly ' In fact, there is a stop . It's just that our eyes can't tell if it stops , It's just a quick stop and start connecting immediately .
Application scenarios
A long connection 、 Long polling is generally applied to webIM、ChatRoom And some website applications that need timely interaction .web Wechat QR code webQQ HI Web version ,Facebook IM etc.
Advantages and disadvantages
polling : The client sends to the server regularly Ajax request , After receiving the request, the server immediately returns the response information and closes the connection .
advantage : Back end programming is easier .
shortcoming : Most of the requests are useless , Waste bandwidth and server resources .
example : Suitable for small applications .
Long polling : The client sends to the server Ajax request , The server receives the request hold Live connection , The response information is not returned and the connection is closed until there is a new message , After the client processes the response information, it sends a new request to the server .
advantage : Not frequent requests without messages , Low cost of resources .
shortcoming : The server hold Connections consume resources , There is no guarantee for the order of data returned , Difficult to manage maintenance .
example :WebQQ、Hi Web version 、Facebook IM.
A long connection : Embed a hidden image in the page iframe, I will hide this iframe Of src Property is set to request a long connection or to adopt xhr request , The server continuously inputs data to the client based on the energy source .
advantage : Instant message arrival , No useless requests ; Management is relatively convenient .
shortcoming : Server maintenance of a long connection will increase overhead .
example :Gmail Chat
Flash Socket: Embed a usage in the page Socket Class Flash Program JavaScript By calling this Flash Provided by the program Socket Interface and server side Socket Interface to communicate ,JavaScript Control the display of the page after receiving the information sent by the server .
advantage : Real instant messaging , Not pseudo instant .
shortcoming : Client must be installed Flash plug-in unit ; Not HTTP agreement , Can't automatically cross the firewall .
example : Online interactive games .
边栏推荐
- Dark horse shopping mall ---2 Distributed file storage fastdfs
- Huikan source code -- Huikan app system secondary development source code sharing
- R language dplyr package filter function filters the data rows in the specified list whose contents in the dataframe data are not (not equal to one of the specified vectors)
- Execution order of MySQL query statements join, on and where
- Why should Apple change objc_ Type declaration for msgsend
- The R language cartools package divides data, the scale function scales data, and the NaiveBayes function of e1071 package constructs a naive Bayesian model
- A set of automated paperless office system (oa+ approval process) source code: with data dictionary
- Thinkphp3 use phpword to modify the template and download it
- 如果你也想做自媒体,不妨听大周给您点建议
- Installation and removal of MySQL under Windows
猜你喜欢

Explain AHP in human language (very detailed principle + simple tool implementation)

ECSHOP commodity wholesale multi attribute multi specification multi inventory batch purchase ECSHOP wholesale plug-in ECSHOP multi attribute order
![[data midrange] what is the oneid of the data midrange? Isn't the master data fragrant?](/img/51/9aceaaeed1f6db7c60685d53477eba.png)
[data midrange] what is the oneid of the data midrange? Isn't the master data fragrant?

Explanation of ideas and sharing of pre-processing procedures for 2021 US game D (with pre-processing data code)

15. Notes on the button style of WPF

黑馬暢購商城---3.商品管理

An easy-to-use seal design tool - (can be converted to ofd file)

一套自动化无纸办公系统(OA+审批流)源码:带数据字典

What are redis avalanche, penetration and breakdown?

K8s, docker compose install MySQL 8.0.18
随机推荐
Kotlin study notes
devsecops与devops的理解与建设
【数据中台】数据中台的OneID是个什么鬼,主数据它不香吗?
Heyangdao store management system -- share the development source code of heyangdao system
What are redis avalanche, penetration and breakdown?
Implementing Domain Driven Design - using the ABP framework - Summary of a series of articles
R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses the lrtest function of epidisplay package to perform multiple model
实现领域驱动设计 - 使用ABP框架 - 系列文章汇总
如果你也想做自媒体,不妨听大周给您点建议
R language dplyr package filter function filters the data rows in the specified list whose contents in the dataframe data are not (not equal to one of the specified vectors)
PyCaret 成功解决无法从‘sklearn.model_selection._search‘导入名称“_check_param_grid”
Today, I will explain to you what is DFI and its development prospects
R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses the summary function to obtain the summary statistical information
An article clearly explains MySQL's clustering / Federation / coverage index, back to table, and index push down
20、wpf之MVVM命令绑定
High imitation blue playing network disk file sharing to make money network disk PHP system source code
sklearnex 让你的 sklearn 机器学习模型训练快得飞起?
R语言caTools包进行数据划分、scale函数进行数据缩放、e1071包的naiveBayes函数构建朴素贝叶斯模型
flutter常用命令及问题
Understanding and construction of devsecops and Devops