简体   繁体   English

减少在套接字上发送的调用是否有意义?

[英]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. 目前正与插座的工作,我想知道是否是有意义的减少调用量send了性能。

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? 据我了解,有一个发送缓冲区,数据没有立即发送(?),但是我想知道内核在实际发送数据之前要等待多长时间,如果我调用send会导致多少开销多次而不是一次?

For TCP, there is a send buffer controlled by the Nagle algorithm (and its interaction with delayed acks from the receiver). 对于TCP,有一个由Nagle算法控制的发送缓冲区(及其与接收方的延迟确认的交互)。

There isn't equivalent delay/buffering mechanism for UDP. UDP没有等效的延迟/缓冲机制。

You haven't said which protocol you're using, but if it is TCP you probably don't need to do anything. 您尚未说出正在使用哪个协议,但是如果它是TCP,则可能无需执行任何操作。 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. 对于延迟敏感的代码,仅是为了避免系统调用开销而缓冲写入仍然是值得的,但是我想您已经知道这是否是您的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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