Windows posix 套接字性能
我正在寻找有关 Windows 网络编程的信息。主要是如何让单个可执行文件能够应对1000个连接。
我们在 unix 上使用 select() FD_ISSET 等,这工作得非常快。在 Windows 上,这些 API 非常差。 FD_SET 慢很多,但即使解决这个问题,Windows 也比 HPUX 慢很多。
我正在寻找一个 win32 API 调用,我可以使用它来代替不需要太多 CPU/时间的 select() 调用。目前,我们将 50% 的时间(和 CPU)花费在 select() 上,而在 unix 上,时间花费在 send() 和 receive() 上,这正是我所期望的。
谢谢 尼尔
I am looking for information on Windows network programming. Mainly how to get a single executable to cope with 1000 connections.
We use select() FD_ISSET etc on unix and this works very quick. On Windows these APIs are very poor. FD_SET is lots slower but even when working around this, Windows is lots slower than HPUX.
I'm looking for a win32 API call which I can use instead of the select() call which doesnt require so much CPU/time. Currently we spend 50% of the time (and CPU) in select(), where as on unix the time spent in send() and recv(), which is what I would expect.
Thanks
Neil
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能正在寻找 Windows I/ O 完成端口。这是来自 文章 http://doc.sch130.nsc.ru/www.sysinternals.com/index.shtml" rel="nofollow">SysInternals 伙计们。
You are probably looking for Windows I/O Completion Ports. Here's an article from SysInternals guys.
如果您真的热衷于可扩展套接字编程,那么没有什么比 Windows 上的 IO 完成端口更好的了。
话虽如此,您的程序可能需要对完成端口模型进行大量重写。
然而,即使使用 select()/FD_ISSET 也可以提高性能。
具体方法如下:
在winsock2.h中,fd_set被定义为一个SOCKET数组和一个元素计数器。
同样在winsock2.h中,您会发现FD_SET在该数组的末尾添加了一个SOCKET,并且FD_ISSET在数组中进行线性搜索。
现在,如果您更改宏以使用 SOCKET 的排序数组,即
,则依赖于数组大小的 FD_ISSET 可以大大提高(虽然 FD_SET 的性能会有所下降,但我们假设 FD_SET 是一个很少的操作)。
在 Unix 上, select() 的性能更好,因为它们将 FD_SET 作为位图,FD_SET/FD_ISSET 只是测试或设置一个位。在 Windows 上,此技术不适用,因为套接字不是一个小的正文件描述符编号,它是一个句柄,并且句柄的标量值可能很大。
If you are really into the scalable sockets programming, nothing would outperform IO completion ports on Windows.
Having said this, you program would likely need a big rewrite for completion ports model.
However, it is possible to improve performance even with select()/FD_ISSET.
Here is how it can be done:
in winsock2.h fd_set is defined as an array of SOCKETs and a element counter
Also in winsock2.h you'll find that FD_SET adds a SOCKET at the end of this array, and FD_ISSET is doing a linear search in the array.
Now if you change macros to use sorted array of SOCKETs, i.e
then dependent on the size of the array FD_ISSET can be greatly improved (while performance of FD_SET will degrade somewhat, but we're assuming that FD_SET is a seldom operation).
On Unixes, performance of select() is better since they FD_SET as bitmap, FD_SET/FD_ISSET would just test or set a bit. On Windows this technique would not be applicable because socket is not a small positive file descriptor number, it is a HANDLE and scalar value of a handle can be large.