socket listen backlog
http://stackoverflow.com/questions/4253454/question-about-listening-and-backlog-for-sockets
The listen backlog is, as Pieter said, a queue which is used by the operating system to store connections that have been accepted by the TCP stack but not, yet, by your program.
Conceptually, when a client connects it's placed in this queue until your Accept() code removes it and hands it to your program.
As such, the listen backlog is a tuning parameter调优参数 that can be used to help your server handle peaks峰值 in concurrent connection attempts.
Note that this is concerned with peaks in concurrent connection attempts and in no way related to the maximum number of concurrent connections that your server can maintain.
For example, if you have a server which receives 10 new connections per second then it's unlikely that tuning the listen backlog will have any affect even if these connections are long lived
and your server is supporting 10,000 concurrent connections (assuming your server isn't maxing out the CPU serving the existing connections!).
However, if a server occasionally experiences short periods when it is accepting 1000 new connections per second then you can probably prevent some connections from being rejected
by tuning the listen backlog to provide a larger queue and therefore give your server more time to call Accept() for each connection.
As for pros优点 and cons缺点, well the pros are that you can handle peaks in concurrent connection attempts better and the corresponding con is that the operating system needs to allocate more space for the listen backlog queue because it is larger. So it's a performance vs resources trade off权衡.
Personally I make the listen backlog something that can be externally tuned via a config file.
How and when you call listen and accept depends upon the style of sockets code that you're using.
With synchronous code you'd call Listen() once with a value, say 10, for your listen backlog and then loop calling Accept().
The call to listen sets up the end point that your clients can connect to and conceptually creates the listen backlog queue of the size specified.
Calling Accept() removes a pending connection from the listen backlog queue, sets up a socket for application use and passes it to your code as a newly established connection.
If the time taken by your code to call Accept(), handle the new connection, and loop round to call Accept() again is longer than the gap间隙 between concurrent connection attempts
then you'll start to accumulate累加 entries登记 in the listen backlog queue.
With asynchronous sockets it can be a little different, if you're using async accepts you will listen once, as before and then post several (again configurable) async accepts.
As each one of these completes you handle the new connection and post a new async accept.
In this way you have a listen backlog queue and a pending accept 'queue' and so you can accept connections faster
(what's more the async accepts are handled on thread pool threads so you don't have a single tight accept loop).
This is, usually, more scalable and gives you two points to tune to handle more concurrent connection attempts.
socket listen backlog的更多相关文章
- [python]socket.listen(backlog)中的backlog含义
http://www.nosa.me/2015/09/16/socket-listenbacklog-%E4%B8%AD-backlog-%E6%8C%87%E7%9A%84%E6%98%AF%E4% ...
- TCP SOCKET中backlog参数的用途是什么? ---图解
recv_queue中的包大小,为内核的包大小,而不是ip包大小. 如果发出去的包太大,需要修改write_queue和tx_queue两个参数,tx_queue主要是流量控制. 多进程必须在sock ...
- 浅谈tcp socket的backlog参数
最近看netty源码碰到ChannelOption.SO_BACKLOG参数,通过跟踪代码发现其实是用于设置底层tcp socket的backlog参数,由于不了解这个参数,有必要彻底的理解一下. 底 ...
- socket listen参数中的backlog
服务器监听时,在每次处理一个客户端的连接时是需要一定时间的,这个时间非常的短(也许只有1ms 或者还不到),但这个时间还是存在的.而这个backlog 存在的意义就是:在这段时间里面除了第一个连接请求 ...
- socket listen参数中的backlog 的意义!
服务器监听时,在每次处理一个客户端的连接时是需要一定时间的,这个时间非常的短(也许只有1ms 或者还不到),但这个时间还是存在的.而这个backlog 存在的意义就是:在这段时间里面除了第一个连接请求 ...
- TCP之listen&backlog
1. listen函数: #include <sys/socket.h> int listen(int sockfd, int backlog); ret-成功返回0 失败返回- list ...
- socket listen/accept
listen函数 摘要:listen函数使用主动连接套接口变为被连接套接口,使得一个进程可以接受其它进程的请求,从而成为一个服务器进程.在TCP服务器编程中listen函数把进程变为一个服务器,并指定 ...
- Socket listen 简要分析
#include <sys/types.h> /* See NOTES */#include <sys/socket.h>int listen(int sockfd, int ...
- Socket之listen() receive()
socket.listen([backlog]) 相比listen方法,它俩就好理解多了,一个是Client用于连接Server的方法,一个是Server用于接收Client的连接申请的方法. 但事 ...
随机推荐
- MySQL-----唯一索引
唯一索引: 单列唯一索引和联合唯一索引 索引是为了加速查找. 唯一索引是加了约束条件.例如主外键. 唯一索引的约束: 约束不能重复(可以为空) 主键不能重复(不能为空) 加速查找 create tab ...
- fielddata breaker与cache size
breaker的估算,是根据语句以及上层的结果数,加上固定的值,不准确. cache.size是cache到结果的size,准确. 所以,配置breaker不能拦截占用内存的聚合查询,而配置cache ...
- 【Codeforces 1086B】Minimum Diameter Tree
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 统计叶子节点个数m 把每条和叶子节点相邻的边权设置成s/cnt就可以了 这样答案就是2*s/m(直径最后肯定是从一个叶子节点开始,到另外一个叶 ...
- 慕课笔记利用css进行布局【混合布局】
<html> <head> <title>混合布局学习</title> <style type="text/css"> ...
- mysql启服务的时候报1067错误解决办法
网上百度了半天没有有效的办法,推荐一个万能的办法: 1.看日志: mysql安装目录下 data文件 -> 后缀为.err 的文件就是日志文件 打开它 : 可以看到错误信息 2.看错 ...
- bzoj3304[Shoi2005]带限制的最长公共子序列 DP
题意:给出三个序列,求出前两个的公共子序列,且包含第三个序列,要求长度最长. 这道题目怎么做呢,f[i][j]表示a串1-i,b串1-j的最长,g[i][j]表示a串i-n,b串j-m最长, 那么只需 ...
- JavaScript判断页面是否已经加载完毕
做页面时经常会遇到当前页面加载完成后,执行某些初始化工作.这时候就要知道如何判断页面(包括IFRAME)已经加载完成,代码如下: < script language = "javasc ...
- codeforces 762E(cdq分治)
题意: n个电台,每个电台有三个属性xi, ri, fi.分别代表电台的坐标,电台的播报范围,以及播报的频率. 对于一对电台i, j,若min(ri, rj) >= |xi - xj|,那么他们 ...
- u启动为苹果笔记本重装win7系统教程
准备更换系统的苹果笔记本一台! 上述需要准备的东西均准备好以后我们就开始今天的教程了!! 首先,将已经制作好启动盘的u启动u盘插入到苹果笔记本上的usb插口,然后开机! 由于苹果笔记本电脑 ...
- cache and database
This article referenced from http://coolshell.cn/articles/17416.html We all know that high concurren ...