关于so​​cket rmem_max和wmem_max [英] About socket rmem_max and wmem_max

查看:214
本文介绍了关于so​​cket rmem_max和wmem_max的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对socket rmem_max和wmem_max有疑问。

以下是我的linux机器的输出。



cat / proc / sys / net / core / rmem_max

212992

cat / proc / sys / net / core / rmem_default

212992
cat / proc / sys / net / core / wmem_max

212992

cat / proc / sys / net / core / wmem_default

212992.



所以我想验证上述值是否按预期进行。我创建了两个进程(客户端套接字和服务器套接字)都是LOCAL unix套接字(AF_UNIX)。我已经让服务器程序在执行recv()调用之前无限期地休眠。



客户端套接字在一个连续循环中向服务器套接字发送1024个字节。

但即使发送了多个,我也不会收到错误212992字节。我的理解是,由于服务器无限期地休眠,它不能从内核套接字缓冲区获取数据,同时客户端继续将数据推送到服务器。所以这些数据都将存储在内核缓冲区中。由于send()具有212992字节(wmem_max)的限制,因此在使用足够的内核缓冲区后,send()客户端调用将失败。



但是这没有发生,我可以看到超过113271663的数量正在进行而没有任何问题,而send()调用根本没有失败。



wmem_default和rmem_default的价值是多少?





有人可以澄清linux中send()和recv()的最大套接字缓冲区是什么,以及如何在没有任何故障的情况下将这些巨大的数据存储在linux内核套接字缓冲区中?



我尝试过:



成功发送1024个字节(i = 139453022)

发送1024个字节成功(i = 139453023)

成功发送1024个字节(i = 139453024)

成功发送1024个字节(i = 139453025)

已发送1024字节成功(i = 139453026)

成功发送1024字节(i = 139453027)

...



139453027已经通过send()内核调用发送了1024个块的数量而没有任何失败。





//下面是服务器程序无限期睡眠



for(;;){

int completed,n,num;

printf(等待连接... \ n);

n = sizeof(远程);

if((sock_serv = accept(sock,(struct sockaddr) *)& remote,& n))== -1){

perror(接听电话失败);

退出(1);

}



printf(服务器插座已连接。\ n);

睡眠(100000) ; //无限期睡眠

完成= 0;

do {

num = recv(sock_serv,str,1024,0) ;

;

;

;

}

I have a following doubt related to socket rmem_max and wmem_max.
Below is the output taken from my linux machine.

cat /proc/sys/net/core/rmem_max
212992
cat /proc/sys/net/core/rmem_default
212992
cat /proc/sys/net/core/wmem_max
212992
cat /proc/sys/net/core/wmem_default
212992.

so i thought of verifying whether the above values are wroking as expected or not. I have created two process(client socket and server socket) both are LOCAL unix sockets(AF_UNIX). I have made the server program to sleep for indefinite period of time before recv() call has been executed.

Client socket is sending 1024 bytes to server socket in a continuos while loop.
But i dont get a error even after sending more than 212992 bytes. My understanding is that since server is sleeping indefinitely it wont able to get the data from kernel socket buffer at the same time client is keep on pushing the data to the server. So all these data will be stored in the kernel buffer. since send() has the limitation of 212992 bytes(wmem_max) , send() client call should fail after enough kernel buffer has been used.

But this is not happening, i could see more than 113271663 number of ietrations are ongoing without any problem and send() call is not at all failing.

What is the value of wmem_default and rmem_default denotes?


Can someone please clarify what is the maximum socket buffers available in linux for send() and recv() and how this huge data is stored in linux kernel socket buffers wihtout any failure?

What I have tried:

Sent 1024 bytes successfully (i=139453022)
Sent 1024 bytes successfully (i=139453023)
Sent 1024 bytes successfully (i=139453024)
Sent 1024 bytes successfully (i=139453025)
Sent 1024 bytes successfully (i=139453026)
Sent 1024 bytes successfully (i=139453027)
...

139453027 number of 1024 chunks has been sent via send() kernel call without any failure.


//below is the server program sleeping indefinitely

for(;;) {
int completed, n, num;
printf("Waiting for a connection...\n");
n = sizeof(remote);
if ((sock_serv = accept(sock, (struct sockaddr *)&remote, &n)) == -1) {
perror("accept call failed");
exit(1);
}

printf("server socket Connected.\n");
sleep(100000); // indefinite sleep
completed = 0;
do {
num = recv(sock_serv, str, 1024, 0);
;
;
;
}

推荐答案

这是一个有趣的行为,如果我不得不猜测,那就是你正在使用AF_UNIX本地套接字看到这种行为。指定本地套接字时,内核会以完全不同的方式处理它。本地套接字本质上只是系统文件,因为这样做效率更高,因此文件的大小可能不会完全相同。



我猜是否你使用了实际的AF_INET套接字,你就会开始看到重传/丢失/丢弃的数据包。
This is interesting behavior, if I had to guess, it's the fact that you're using an AF_UNIX local socket that seeing this behavior. When you specify a "local" socket, the kernel handles it completely differently. Local sockets are essentially just system files, because it's more efficient to do so, so the file may not be size restricted exactly the same way.

I'm guessing if you used actual AF_INET sockets, you'd start to see retransmissions/lost/dropped packets.


这篇关于关于so​​cket rmem_max和wmem_max的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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