简体   繁体   中英

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? 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 * 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

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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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