-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The load balancing issue in Poco::ActiveThreadPool #4544
Comments
Hi! Poco::AtomicCounter lttCount;
class LongTimeTask : public Poco::Runnable {
Poco::AtomicCounter &_counter;
public:
LongTimeTask(Poco::AtomicCounter &counter) : _counter(counter) {}
void run() override {
_counter++;
puts("ltt task");
Poco::Thread::sleep(2 * 1000);
}
};
Poco::AtomicCounter sttCount;
class ShortTimeTask : public Poco::Runnable {
Poco::AtomicCounter &_counter;
public:
ShortTimeTask(Poco::AtomicCounter &counter) : _counter(counter) {}
void run() override {
_counter++;
puts("stt task");
Poco::Thread::sleep(1);
}
};
int capacity = 2;
Poco::ActiveThreadPool pool(capacity);
for (int i = 0; i < 10; i++) {
LongTimeTask ltt(lttCount);
pool.start(ltt);
ShortTimeTask stt(sttCount);
pool.start(stt);
}
pool.joinAll();
assertEqual(10, lttCount.value());
assertEqual(10, sttCount.value()); Output was testActiveThreadLoadBalancing: ltt task
stt task
stt task
stt task
stt task
stt task
stt task
stt task
stt task
stt task
stt task
ltt task
ltt task
ltt task
ltt task
ltt task
ltt task
ltt task
ltt task
ltt task |
Please see this picture. |
This seems to me like an enhancement request, not a bug. Implementation currently assigns tasks to thread in round-robin way when adding them. Possible improvement is to assign them when they actually start running from a single queue.. |
…project#4544" Optimization allows redistribute tasks to the idle threads
FYI capacity = 2 optimization = false ./Foundation-testrunner testActiveThreadLoadBalancing 0.05s user 0.02s system 0% cpu 11.496 total
capacity = 2 optimization = true ./Foundation-testrunner testActiveThreadLoadBalancing 0.06s user 0.01s system 0% cpu 10.545 total
capacity = 4 optimization = false ./Foundation-testrunner testActiveThreadLoadBalancing 0.06s user 0.02s system 1% cpu 6.605 total
capacity = 4 optimization = true ./Foundation-testrunner testActiveThreadLoadBalancing 0.05s user 0.02s system 1% cpu 6.628 total
capacity = 32 optimization = false ./Foundation-testrunner testActiveThreadLoadBalancing 0.06s user 0.02s system 3% cpu 1.797 total
capacity = 32 optimization = true ./Foundation-testrunner testActiveThreadLoadBalancing 0.06s user 0.02s system 4% cpu 1.692 total |
* make Poco::ActiveThreadPool easy to use (#4544) * code format * Fix ThreadSanitizer thread leak error * enh(ActivePooledThread): Change pointers to references * enh(ActivePooledThread): remove unused method * enh(Poco::ActiveThreadPool): Use std::unique_ptr instead of raw pointer * enh(Poco::ActiveThreadPool): Use C++ static_cast instead of C casting * enh(Poco::ActiveThreadPool): Use standard containers instead of implementing own * enh(Poco::ActiveThreadPool): Change pointer to reference * enh(Poco::ActiveThreadPool): Use smart pointers instead of bare pointers * enh(Poco::ActiveThreadPool): Fix codeql warning: A stack address which arrived via a may be assigned to a non-local variable. * enh(Poco::ActiveThreadPool): More test case * enh(Poco::ActiveThreadPool): std::optional::value unavailable on earlier macOS versions * enh(Poco::ActiveThreadPool): Fix compare function for make heap * enh(Poco::ActiveThreadPool): Add more test case * enh(Poco::ActiveThreadPool): Add more test case * enh(Poco::ActiveThreadPool): Code style * enh(Poco::ActiveThreadPool): Test case * enh(Poco::ActiveThreadPool): Test case * enh(Poco::ActiveThreadPool): Fix test case error * Revert "enh(Poco::ActiveThreadPool): std::optional::value unavailable on earlier macOS versions" This reverts commit cba4673. * enh(macOS): require min deployment macOS version 10.15 which has full support for C++17 * enh(Poco::ActiveThreadPool): Remove useless "{}" * enh(Poco::ActiveThreadPool): Rename member variable m_impl to _impl --------- Co-authored-by: Matej Kenda <[email protected]>
Describe the bug
Each thread in
Poco::ActiveThreadPool
has its ownPoco::NotificationQueue
.If I have 2 types of Runnable like this:
thread#2 will always in idle, and thread#1 will always in busy !!!
The text was updated successfully, but these errors were encountered: