ZLMediaKit / ZLToolKit

一个基于C++11的轻量级网络框架,基于线程池技术可以实现大并发网络IO
MIT License
1.98k stars 588 forks source link

Uneven load distribution between threads on the TCP server #172

Closed TheMadius closed 1 year ago

TheMadius commented 1 year ago

Hello. There was a problem with uneven load distribution on the TCP server. With the simultaneous mass addition of RTSP flows, the following problem arises image

When adding a delay, the following distribution occurs

image

Is it possible to achieve such results without adding a delay?

Goga1992 commented 1 year ago

I confirm. I observe the same uneven load when adding video streams very quickly

xia-chu commented 1 year ago

The load balancing algorithm of zltoolkit is not round robin, So some imbalances are reasonable.

There is a thread load evaluation algorithm inside the zltoolkit, which has latency and may not be accurately evaluated in the short term.

The load balancing algorithm of zltoolkit is not round robin, So some imbalances are reasonable。

There is a thread load evaluation algorithm inside the zltoolkit, which has latency and may not be accurately evaluated in the short term.

TRANS_BY_GITHUB_AI_ASSISTANT

xia-chu commented 1 year ago

This is the load evaluation algorithm:

https://github.com/ZLMediaKit/ZLToolKit/blob/e6fd7c78ec228888b010ab9ecf9680ca19b13ea2/src/Thread/TaskExecutor.h#L25

xia-chu commented 1 year ago

This is the algorithm for obtaining the thread with the lowest load:

https://github.com/ZLMediaKit/ZLToolKit/blob/e6fd7c78ec228888b010ab9ecf9680ca19b13ea2/src/Thread/TaskExecutor.cpp#L126

TheMadius commented 1 year ago

Thank you