I have a network daemon which receives messages of a fixed length (44 Bytes) on a TCP socket.
I am trying to determine what the best length in bytes I should be reading with sysread is. I can of course do a loop that does a sysread for 44 bytes, but I’d like to come up with an optimal size.
I can see an advantage to not having say, a megabyte worth of data to do substr on, but I can also see why doing a thousand sysread calls can cause slowness.
Is there a good size recommendation for doing sysreads over the public internet?
Edit:
The script gets a bunch of the 44 byte messages, they are queued up.
The larger the better!
sysreadwill return as soon any bytes are available.Since you’re never guaranteed to get a whole message and since you’re never guaranteed to not have more than one message, you need to have a loop on the Perl side. Since you already have a loop on the Perl side, so you might as well get as much data as possible from the system in one go to avoid needless system calls.
Pick a size and monitor
$buf‘s size. If it often approachesREAD_SIZE, increaseREAD_SIZE.