简体   繁体   中英

Does it make sense to reduce calls to send on a socket?

Currently working with sockets, I am wondering whether it makes sense to reduce the amount of calls to send for performance.

As far as I understood, there is a send buffer and the data is not dispatched immediately (?), but then I am wondering how long the kernel waits before actually sending the data and how much overhead would be caused by it if I call send multiple times instead of once?

For TCP, there is a send buffer controlled by the Nagle algorithm (and its interaction with delayed acks from the receiver).

There isn't equivalent delay/buffering mechanism for UDP.

You haven't said which protocol you're using, but if it is TCP you probably don't need to do anything. For latency-sensitive code it can still be worth buffering writes just to avoid the syscall overhead, but I suppose you'd already know if that was your situation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM