Is there an “optimal” buffer size when using send ()?

Say you transfer a file of arbitrary length to pieces over TCP / IP:

looping...
    read(buffer, LENGTH)
    send(mysocket, buffer, LENGTH, flags)

My question is what would be the optimal LENGTH value? Or does it not matter at all? I saw everything from 256 bytes to 8192 bytes.

+3
source share
3 answers

Depends on what you mean by optimal. For optimal bandwidth usage, you want to maximize the packet size in order to send at least the size of the network packet (which is usually around 1500 bytes on Ethernet). If you read 4096 or 8192 bytes from the disk, this would be a good value.

+2
source

, - .

ATM 54- .

. YMMV.

0

If you send large amounts of data through a high latency connection, you can get higher throughput with a large send buffer. Here is a good explanation: http://www.onlamp.com/pub/a/onlamp/2005/11/17/tcp_tuning.html

0
source

Source: https://habr.com/ru/post/1791088/


All Articles