IOCP是否真的可以扩展以进行聊天? [英] Is IOCP really scalable for a chat?

查看:131
本文介绍了IOCP是否真的可以扩展以进行聊天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个网络服务器,并且某些客户端像聊天一样将数据写入其他客户端.如果我使用IOCP(IO完成端口)设计,并且我有4个线程在等待消息.当那些线程接收到数据时,我需要序列化对客户端列表的访问以获取客户端的套接字描述符,我需要重新发送接收到的数据.

通过这样做,我认为我失去了IOCP提供的所有可伸缩性.假设我的4个线程现在在客户端列表周围使用Mutexs或Critical Sections.

更具体而言:客户端具有名称,因此一个客户端按名称写入一个或多个客户端.然后,当每条消息到达服务器时,我必须找到与这些名称相关的套接字描述符.

所以我的问题是:
1- IOCP是否仍然比异步套接字(WSAAsyncSelect)具有更好的/可伸缩性,而该套接字具有一个专用线程来处理消息(在这种情况下)的窗口?
2-有一个更好的设计可以避免使用互斥对象/CS?

Supose i have a network server and some clients writes data to other clients, just like a chat. If i use and IOCP (IO Completion Port) design and i have 4 threads waiting for messages. When those threads received data i need to serialize the access to the client list to get the socket descriptor of the client/s i need to resend the received data.

By doing this i think i am loosing all the scalability that IOCP offers. Becase my 4 threads now use Mutexes or Critical Sections around the client list.

To be more especific: clients has names, so one client writes to one or more clients by name. Then i have to find the socket descriptors related to those names when each message arrive to the server.

So my questions are:
1- Is IOCP still superior/scalable than Asynchronous sockets (WSAAsyncSelect) with one dedicated thread to the window that process the messages (for this case)?
2- There is a better design to avoid the use of Mutexes/CSs?

推荐答案

1.取决于您如何使用它.细节决定成败.

2.是的.客户端列表只能由一个线程访问.该线程可以告诉其他4个线程使用IOCP或标准Windows消息重新发送.
1. Depends on how you use it. The devil is in the details.

2. Yes. The client list should be accessed by only one thread. This thread can tell the other 4 threads to resend using IOCP or standard windows message.


1-您可以在客户端列表周围使用单个写入器多个读取器锁.

2-您可以引用计数客户端对象,然后只需要将客户端列表上的锁保持足够长的时间即可获取客户端对象,而不是整个发送操作.
1 - You could use a single writer multiple reader lock around your client list.

2 - You could reference count the client objects, you then only need to hold the lock on the client list for long enough to obtain the client object rather than for the whole send operation.


这篇关于IOCP是否真的可以扩展以进行聊天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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