8/20 I have a socket protocol that sends each message as a header packet
+ 1 or more data packets, and I'd like to collapse this into a single
packet for small messages by copying them into a stack-allocated buffer
and then just sending that. Any ideas about what sort of cutoff to
use? I don't really have the time or need to obsessively optimize
it, just curious. Thanks.
\- Hello, so you are not going to send *anything* unless the
"cut off" is reached? What if it isnt reached for a "long time"?
This may be ok in some cases, but say this is a control channel
of some kind, that delay may not be acceptable. Naive buffering
can lead to some weird problems. Here is an example on the flip
side, reading from the network: a process using a packet
filter may not return to user level until the BPF buffer fills.
Normally on a busy link this isnt a signficant issue. But on
totally dead network ... say a LAN at home with one machine ...
this may be a long long time and can lead to weird problems
[liek dealing with signals]. So either you have to add some
timeout code or doin a polling [select] read rather than read-
ing directly, i.e. not do things the naive way. I assume
you have already determined Nagling wont solve the problem
for you? If you do something, I'd be curious to hear if it
make any measurable difference at all. Ok tnx. --psb
\_ No, it's more like this:
xyzSend(msg) {
if (length(msg) < CUTOFF) {
msg = makeHeader(msg) + msg
send(msg)
}
else {
send(makeHeader(msg)
send(msg)
}
90% of the messages are 4 bytes long, so squeezing those is a
no brainer and the network usage is cut by half. The rest vary
in length and most are << 1500 bytes. I figure a cutoff of
1024 is reasonable.
\_ Do you know what the Nagle Algorithm is?
\_ Try to fit the whole TCP/IP packet size into a single ethernet
MTU (1500 bytes).
\_ Go for less than that, I'd shoot for aroud 1400 bytes or so
to make sure your TCP/IP headers aren't pushing you above 1500.
If you want to be anal you'd probably want to do smallest MTU
to host detection as well, not that hard. Generally if you
are caring about shit like this you should pick up the Stevens
networking book and read the pertinant chapters. It is a pretty
easy read and you will be much better at this sort of stuff.
\_ That's what I said. 1500 including the TCP/IP headers.
\_ Use writev or sendto or sendmsg, then there is no copying. |