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的连接申请的方法. 但事 ...
随机推荐
- [bzoj3531][Sdoi2014][旅行] (主席树+树链剖分)
Description S国有N个城市,编号从1到N.城市间用N-1条双向道路连接,满足从一个城市出发可以到达其它所有城市.每个城市信仰不同的宗教,如飞天面条神教.隐形独角兽教.绝地教都是常见的信仰. ...
- 九度oj 题目1196:成绩排序
题目1196:成绩排序 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5192 解决:1792 题目描述: 用一维数组存储学号和成绩,然后,按成绩排序输出. 输入: 输入第一行包括一个整数 ...
- CentOS下LVS DR模式负载均衡配置详解
一安装LVS准备: 1.准备4台Centos 6.2 x86_64 注:本实验关闭 SELinux和IPtables防火墙. 管理IP地址 角色 备注 192.168.1.101 LVS主调度器(Ma ...
- React & search & keyboard ghost
React & search & keyboard ghost DOM events https://www.w3schools.com/jsref/dom_obj_event.asp ...
- 【区间DP+好题】String painter
https://www.bnuoj.com/v3/contest_show.php?cid=9149#problem/G [题意] 给定两个长度相同的字符串A,B.每次操作都能把A中的任意一个子段变成 ...
- 家的范围 Home on the Range(洛谷 2733)
题目背景 农民约翰在一片边长是N (2 <= N <= 250)英里的正方形牧场上放牧他的奶牛.(因为一些原因,他的奶牛只在正方形的牧场上吃草.)遗憾的是,他的奶牛已经毁坏一些土地.( 一 ...
- 【NOIP2016】天天爱跑步(树上差分)
题意: 小c同学认为跑步非常有趣,于是决定制作一款叫做<天天爱跑步>的游戏.?天天爱跑步?是一个养成类游戏,需要 玩家每天按时上线,完成打卡任务.这个游戏的地图可以看作一一棵包含 N个结点 ...
- UVa 12563_Jin Ge Jin Qu hao
[题意]在KTV唱歌,假设每首歌最长180s,时间结束时如果还有歌正在唱,则将此歌唱完.为使唱歌时间最长,规定最后唱长达678s的<劲歌金曲>[介是个嘛?] 假设你正在唱KTV,在剩余的t ...
- response的作用
response.addCookies(),添加Cookie. response.sendRedirect()页面跳转,客户端跳转.(能够取到request)
- mysql性能调优——锁优化
影响mysql server性能的相关因素 需求和架构及业务实现优化:55% Query语句优化:30% 数据库自身优化:15% 很多时候大家看到数据库应用系统中性能瓶颈出现在数据库方面,就希望通过数 ...