当前位置:网站首页>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 .
边栏推荐
- Mpai data science platform random forest classification \ explanation of regression parameter adjustment
- 20、wpf之MVVM命令绑定
- 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
- 网络上开户买股票是否安全呢?
- Fun pocket mall -- sharing the development source code of fun pocket app system
- Dynamic proxy
- R language dplyr package summary_ The at function calculates the count number, mean and median of multiple data columns (specified by vectors) in the dataframe data, and specifies na RM parameter, spe
- A set of automated paperless office system (oa+ approval process) source code: with data dictionary
- 19、wpf之事件转命令实现MVVM架构
- R语言dist函数计算dataframe数据中两两样本之间的距离返回样本间距离矩阵,通过method参数指定距离计算的方法、例如欧几里得距离
猜你喜欢

一款好用的印章设计工具 --(可转为ofd文件)

【数据中台】数据中台的OneID是个什么鬼,主数据它不香吗?

ECSHOP quickly purchases goods, simplifies the shopping process, and improves the user experience through one-step shopping

Explain factor analysis in simple terms, with case teaching (full)

刷入Magisk通用方法

What is the primordial universe

Dark horse shopping mall ---1 Project introduction - environment construction

【OceanBase】OceanBase简介及其与MySQL的比较

Black Horse Chang Shopping Mall - - - 3. Gestion des produits de base

ECSHOP video list_ ECSHOP uploading video, video classification, video list playing video function
随机推荐
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
学习笔记 2022 综述 | 自动图机器学习,阐述 AGML 方法、库与方向
一篇文章讲清楚MySQL的聚簇/联合/覆盖索引、回表、索引下推
Kotlin基础
Does sklearex make your sklearn machine learning model training fly fast?
High imitation blue playing network disk file sharing to make money network disk PHP system source code
ARM 立即数
The source code of the hottest online disk money making system in 2022 imitates Lanzou online disk / Chengtong online disk / sharing money making cloud disk system / online disk VIP Download System
Mysql database logs binlog save aging (expire\u logs\u days)
2022年首期Techo Day腾讯技术开放日将于6月28日线上举办
Kotlin学习笔记
Hook technology
Mpai data science platform random forest classification \ explanation of regression parameter adjustment
thinkphp3.2.5 GIF. class. php for php7.4
R语言dplyr包filter函数过滤dataframe数据中指定数据列的内容不是(不等于指定向量中的其中一个)指定列表中的数据行
What are redis avalanche, penetration and breakdown?
Is it safe to open an account and buy stocks on the Internet?
The latest IT learning route in 2020
How to use ARIMA model for prediction?
Zunpin Yongyao advertising e-commerce system -- Zunpin Yongyao advertising e-commerce app system development source code sharing