简体   繁体   English

套接字和文件都建议缓冲区大小

[英]Both socket and file recommended buffer size

Please, Linux kernel hackers, what is a reasonable buffer size for write(2) syscall to sockets or files, performance-wise? 请问,Linux内核黑客, write(2)系统调用到套接字或文件的合理缓冲区大小是什么,性能方面呢? It's clear that it's some pagesize multiple, but which one? 很明显,这是一些页面大小,但是哪一个? Does it matter? 有关系吗? What is "too small" and "too big"? 什么是“太小”和“太大”?

depends on how big your delay to the peer is, let's say you have a 100MBps connection, and a delay of 50ms, then you can calculate 取决于你对同伴的延迟有多大,假设你有一个100MBps的连接,延迟50ms,那么你可以计算

100MBps * 0.050 sec / 8 = 0.625MB = 625KB

but the default window size in Linux 2.6 is around 110KB, which will limit your throught out to around 2.2MBps (110KB / 0.050) so, to fix that you can you setsockopt 但是Linux 2.6中的默认窗口大小约为110KB,这会将你的通过限制在大约2.2MBps(110KB / 0.050)左右,所以要解决这个问题,你可以使用setsockopt

int ret, sock, buf_size;
sock = socket(AF_INET, SOCK_STREAM, 0);
buf_size = 625*1024;
ret = setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&buf_size, sizeof(buf_size));
ret = setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (char *)&buf_size, sizeof(buf_size));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM