Efficient multithreaded server P&L: -7 (≃ -62 USD)
I have some epoll server code that I tweaked to run the server in a thread.
Now I'm taking this code and changing it so that each client connection is multiplexed by multiple threads.
这个想法是每个线程都有一个环形缓冲区,当一个套接字被接受时,一条消息被放在环形缓冲区上,线程开始监听那个用户。
所有其他线程都会收到所有用户的通知,因此他们也可以向他们回显数据。
这是高效的,因为一个线程可以服务数以万计的连接并且有多个线程。
一个问题是多线程的一个通用问题,它是从一个线程为多种事件中的一种提供服务。我依赖于我正在轮询 ringbuffer 和 epoll 的事实。
The idea is that each thread has a ringbuffer, when a socket is accepted, a message is put on the ringbuffer and the thread begins listening to that user.
All the other threads are notified of all the users so they can also echo data to them.
This is efficient as a thread can serve thousands-millions of connections and there are multiple threads.
One problem, which is a generic problem for multithreading is servicing one of multiple kinds of events from one thread. I rely on the fact I am polling a ringbuffer and epoll.