Multithreading – find tutorials and information on load balancing between threads

I know that the term "load balancing" may be very broad, but the topic I'm trying to explain is more specific. I don't know the correct term I'm building a set of server / client applications The server needs to be able to handle a lot of data transmission and client connections, so I began to study multithreading

There are basically three ways to see any type of thread implemented for the server

>A thread that handles all requests (if 500 clients log in, it will destroy the purpose of the thread) > one thread per user (it is risky to create one thread for each of the 500 clients) > a thread pool that equally shares the work for any number of clients (what I am looking for)

The third is what I want to know This includes settings such as:

>Run up to 250 threads at a time > 500 clients will not create 500 threads, but share 250 threads > request queue will be suspended for delivery to threads > threads are not bound to clients, and vice versa > the server determines the threads that send requests based on activity (load balancing)

I haven't found any code yet, but I have information about how to use such a setting and a tutorial on how to do this in Delphi (xe2) Even an appropriate word or name to fill in the topic is enough, so I can search by myself

edit

I find it necessary to explain what this will be used for I will stream commands and images. There will be a dual slot setting with one "main command socket" and another "additional image stream socket" So the real connection is two socket connections

Each connection to the server's main socket creates (or reuses) an object representing all the data required for the connection, including threads, images, settings, etc For each connection to the main socket, a streaming socket is also connected It does not always stream images, but the command socket is always ready

The key is that I already have a threading mechanism (one thread per session object) in my current setting. I want to transfer it to a multi-threaded environment similar to a pool These two connections need a higher level of control over these threads. I can't rely on things like Indy to keep these synchronization. I'd rather know how things work than learn to trust other things to complete the work I.

Solution

IOCP server This is the only high performance solution It is basically asynchronous in user mode (overlapping I / O in'm $- speak). A thread pool issues calls to wsarecv, wsasend and acceptex, and then waits for the completion records of the IOCP queue When something useful happens, the kernel thread pool performs the actual I / O, and then queues the records

You need at least one buffer class and socket class (and there may be other similar high-performance - objectpool and pooledobject classes, so you can create sockets and buffer pools)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>