以编程方式评估somaxconn的值,以设置listen backlog参数 [英] programatically evaluating the value of somaxconn, to set the listen backlog parameter

查看:676
本文介绍了以编程方式评估somaxconn的值,以设置listen backlog参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于服务器端编程,我使用listen函数作为:

  int listen(int sockfd,int backlog); 

我知道积压应小于或等于在主机系统上设置的somaxconn将运行我的服务器程序。
如果我使用SOMAXCONN作为积压,它将相当于硬编码为通常在tcp.h中定义为128的SOMAXCONN的值。



但是,somaxconn是可调参数sysctl,可以通过更改/ proc / sys / net / core / somaxconn的值来修改,或者使用sysctl修改net.core.somaxconn



人们通常修饰somaxconn以获得更好的系统性能。
我希望我的程序通过评估系统的somaxconn,在程序启动时利用优势。



我可以打开文件/ proc / sys / net / core / somaxconn,并读取包含的值,但它似乎是一个不起眼的方式做事情,特别是因为我认为文件路径somaxconn可能会有所不同,根据发行版。



是否有一个API或示例代码,允许评估somaxconn,在c / c ++?



还告诉我,如果我缺少一些关键点,导致错误的思考。



我也想将我的应用程序移植到Windows,所以Windows程序员也可以有一些有用的见解分享!

$ b $

解决方案

根据您的平台,sysctl()使用kern.ipc.somaxconn可能是您要找的。

但是,如果我正确理解您的问题,您的目标是始终使用最大可能的积压大小。我的理解是,传递给listen()的积压值将默认限制为系统配置的限制。所以你的解决方案可以简单地调用listen()与一个非常大的积压值。


For server side programming I use the listen function as:

int listen(int sockfd, int backlog); 

I understand that the backlog should be less than or equal to the somaxconn set on the host system where I would run my server program. If I use SOMAXCONN as the backlog, it will be equivalent to hard-coding it to the value of SOMAXCONN that is usually defined in tcp.h as 128.

However, somaxconn is a tunable sysctl parameter, that can be modified by changing the value of /proc/sys/net/core/somaxconn or by using sysctl to modify net.core.somaxconn

People usually modify somaxconn to attain better system performance. I would like my program to take advantage by evaluating the system's somaxconn, at the time when the program was started.

I could open the file /proc/sys/net/core/somaxconn and read the contained value, but it seems quite an inelegant way of doing things, specially because I think that the filepath to somaxconn may vary, depending upon the distro.

Is there an API or sample code, that allows evaluating the somaxconn, in c/c++ ?

Also tell me if I am missing some crucial point, leading to flawed thinking.

I also want to port my application to Windows, so Windows programmers may also have some useful insights to share!

Thanks in advance, to all fellow hacks.

解决方案

Depending on your platform, sysctl() with kern.ipc.somaxconn may be what you're looking for.

However, if I understand your question correctly, your goal is to always use the maximum possible backlog size. It is my understanding that the backlog value passed to listen() will be silently limited to the system's configured limit. So your solution could be simply to call listen() with a "very large" backlog value.

这篇关于以编程方式评估somaxconn的值,以设置listen backlog参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆