单缓冲区;多个插座; Linux下的单个系统调用 [英] Single buffer; multiple sockets; single syscall under Linux

查看:83
本文介绍了单缓冲区;多个插座; Linux下的单个系统调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Linux是否有任何本机内核功能可以使send()将提供的缓冲区发送到一组套接字?某种矢量I/O,除了套接字句柄(而不是缓冲区).

Does Linux have any native kernel facility that enables send()ing a supplied buffer to a set of sockets? A sort-of vectored I/O, except for socket handles rather than for a buffer.

目标是减少在以下情况下涉及的u/k转换次数:例如,您需要向n个客户端广播一些状态更新,这将需要遍历每个套接字并发送.

The objective being to reduce the number of u/k transitions involved in situations where-in for example you need to broadcast some state update to n clients which would require iterating through each socket and sending.

一个限制是必须支持TCP套接字(不受我的控制)

One restriction is that TCP sockets must be supported (not under my control)

推荐答案

答案是否定的,Linux和posix系统都没有您想要的呼叫.我担心拥有它没有任何好处,因为每个数据流将遵循不同的路径,这使得在内核中而不是在用户空间中复制缓冲区.在用户到内核之间不进行复制并不必然意味着在内核模式下进行复制会更好.

The answer is no, neither linux nor posix systems have the call you want. I fear that you don't get any advantage of having it, as each of the data streams will follow different paths and that makes copying the buffers in kernel than in user space. Not making copies in user-to-kernel doesn't neccesarily mean doing in kernel mode is better.

无论哪种方式,在Linux中,只要有源代码,就可以实现这种mwrite(或msend)系统调用.但是,恐怕您除了头疼之外什么都不会得到.实现此问题的唯一方法是某种分条复制"方法,但我认为您不会获得任何好处.

Either way, in linux you can implement this kind of mwrite (or msend) system call, as you have the source code. But I'm afraid you won't get anything but a head pain. The only approach to this implementation is some kind of copy-on-divert method, but I don't think you'll get any advantage.

最后,一旦完成第一个 write(2)调用,则在下一个调用中再次交换用户缓冲区的可能性就太低了,使得第二个和下一个副本缓冲区将具有非常低的开销,因为页面将全部位于核心内存中.您需要一个负载非常大的系统,才能在两次系统调用之间的时间里换掉用户缓冲区.

Finnaly, once you have finished the first write(2) call, the probability of having to swap in the user buffer again in the next is far too low, making the second and next copies of the buffer will have very low overhead, as the pages will be all in core memory. You need a very high loaded system to get the user buffer swapped out in the time between syscalls.

这篇关于单缓冲区;多个插座; Linux下的单个系统调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆