Linux UDP接收缓冲区的最大大小 [英] Linux UDP max size of receive buffer

查看:1335
本文介绍了Linux UDP接收缓冲区的最大大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Linux UDP接收缓冲区的最大大小是多少?我以为它仅受可用RAM的限制,但是当我设置时

What's the maximum size of Linux UDP receive buffer? I thought it's limited only by available RAM, but when I set

rmem_max为5GB:

5GB for rmem_max:

echo 5000000000 > /proc/sys/net/core/rmem_max

和4GB的实际套接字缓冲区(在Erlang中):

and 4GB for the actual socket buffer (in Erlang):

gen_udp:listen(Port, [{recbuf, 4000000000}])

当我测量缓冲区利用率时,它显示:

When I measure the buffer utilization, it shows:

# netstat -u6anp | grep 5050
udp6  1409995136      0 :::5050  :::*       13483/beam.smp

我不能超过这个1.4GB.对于较小的缓冲区大小,例如500MB,实际缓冲区大小与配置的值匹配.我的系统是Debian 6.0,机器上有50GB的可用内存.

I can't exceed this 1.4GB. For smaller buffer sizes, like e.g. 500MB, actual buffer size matched the configured value. My system is Debian 6.0, the machine has 50GB RAM available.

推荐答案

在Linux中似乎有一个限制. 我尝试成功将rmem_max设置为2 ^ 32-1.

It seems that there is a limit in linux. I have tried setting rmem_max to 2^32-1 with success.

   root@xxx:/proc/sys/net/core# echo 2147483647 > rmem_max
   root@xxx:/proc/sys/net/core# cat rmem_max
   2147483647

2 ^ 32太多了:

2^32 was too much:

   root@xxx:/proc/sys/net/core# echo 2147483648 > rmem_max
   root@xxx:/proc/sys/net/core# cat rmem_max
   -18446744071562067968

设置为5000000000会产生:

Setting to 5000000000 yields:

   root@xxx:/proc/sys/net/core# echo 5000000000 > rmem_max
   root@xxx:/proc/sys/net/core# cat rmem_max
   705032704

我已经在python中测试了设置和获取套接字的接收缓冲区

I have tested in python that setting and getting socket receive buffer with

   ss.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, bufferSize)
   print ss.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF)

如果'bufferSize'小于1024 ^ 3,程序将打印两倍的'bufferSize',否则回落到256.

If 'bufferSize' is less then 1024^3 program prints doubled 'bufferSize', otherwise it falls back to 256.

值705032704 * 2 = 141006540​​8接近netstat获得的1409995136.

The value 705032704*2 = 1410065408 is close to the 1409995136 obtained by netstat.

这篇关于Linux UDP接收缓冲区的最大大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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