python udp socket 缓冲区大小,Linux UDP接收缓冲区的最大大小

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

5GB for rmem_max:

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

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

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.

解决方案

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 was too much:

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

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

-18446744071562067968

Setting to 5000000000 yields:

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

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

705032704

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)

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值