My question is about sockets programming in Python on Linux, but since Python's socket
module is just a wrapper over system calls (recv
, recvfrom
etc.), it's not strongly about Python.
So, according to docs, when we call a recv
method,
For best match with hardware and network realities, the value of bufsize should be a relatively small power of 2, for example, 4096
What does it mean?
best match with hardware and network realities
Mostly I care about the performance.
Will it be a bottleneck in my network software, if I pass my custom buffer (that I use as a data container later in my code, it's just a memoryview if it matters) with some not-power-of-two custom size to socket.recv_into method?
It'll be just one line of code, clear and short.
But my buffer's size can be 17 or 51 or whatever, so I'm wondering, should I implement some internal ring-like buffer with a "good" size (like 4096) and use it to read the data from a socket in chunks with such a "good" size and write it there, and then copy to my buffer?
Does it have any sense in terms of performance?
Or my current scheme (when I read the data from a socket in chunks with a "bad" size, that doesn't match "power of 2" rule) is fine?
In other words: will it affect the performance, if we read from sockets in chunks with 1023 size, rather than 1024?