lemunozm / message-io

Fast and easy-to-use event-driven network library.
Apache License 2.0
1.11k stars 74 forks source link

FramedTcp handling the nagle algorithm to improve the performance #77

Open lemunozm opened 3 years ago

lemunozm commented 3 years ago

This PR handles the Nagle algorithm in FramedTcp allowing to send a message immediately without sending partially (whatever possible). In other words: it disabled the algorithm until the message is fully in the OS sending buffer, and then enables it to send the full message without waiting for another possible message.

This protocol is message-oriented. This means that receiving less than a message has no meaning for the receiver who needs to wait for the remaining data to produce a meaningful message (which implies allocating in a Decoder). For that reason, sending partial data before having the whole message does not improve anything. What's more, it saturates the network.

Although this feature implies a latency reduction since once the complete message is OS output buffer it is sent, could also imply an impact on the throughput. Anyway, the user of a FramedTcp transport would want latency versus throughput. If throughput is the target, they will probably send big messages that will be less impacted by this change, or even more probably they prefer to choose TCP transport that fits better for throughput.

NOTE: Conceptually it should work, but how to evaluate this improvement?