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

查看:42
本文介绍了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 RAM 可用.

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 太多了:

   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天全站免登陆