mirror of
https://github.com/Zygo/bees.git
synced 2025-06-16 17:46:16 +02:00
bees: dynamic thread pool size based on system load average
Add -g / --loadavg-target parameter to track system load and add or remove bees worker threads dynamically to keep system load close to the loadavg target. Thread count may vary from zero to the maximum specified by -c or -C, and is adjusted every 5 seconds. This is better than implementing a similar load average scheme from outside of the process (though that is still possible) because the in-process load tracker does not disrupt the performance timing feedback mechanisms as a freezer cgroup or SIGSTOP would when controlling bees from outside. The internal load average tracker can also adjust the number of active threads while an external tracker can only choose from the maximum or zero. Also fix a bug where a Task could deadlock waiting for itself to exit if it tries to insert a new Task after the number of worker threads has been set to zero. Also correct usage message for --scan-mode (values are 0..2) since we are touching adjacent lines anyway. Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
#include "crucible/chatter.h"
|
||||
#include "crucible/error.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <utility>
|
||||
|
||||
// for gettid()
|
||||
@ -118,4 +119,37 @@ namespace crucible {
|
||||
return syscall(SYS_gettid);
|
||||
}
|
||||
|
||||
double
|
||||
getloadavg1()
|
||||
{
|
||||
double loadavg[1];
|
||||
const int rv = ::getloadavg(loadavg, 1);
|
||||
if (rv != 1) {
|
||||
THROW_ERRNO("getloadavg(..., 1)");
|
||||
}
|
||||
return loadavg[0];
|
||||
}
|
||||
|
||||
double
|
||||
getloadavg5()
|
||||
{
|
||||
double loadavg[2];
|
||||
const int rv = ::getloadavg(loadavg, 2);
|
||||
if (rv != 2) {
|
||||
THROW_ERRNO("getloadavg(..., 2)");
|
||||
}
|
||||
return loadavg[1];
|
||||
}
|
||||
|
||||
double
|
||||
getloadavg15()
|
||||
{
|
||||
double loadavg[3];
|
||||
const int rv = ::getloadavg(loadavg, 3);
|
||||
if (rv != 3) {
|
||||
THROW_ERRNO("getloadavg(..., 3)");
|
||||
}
|
||||
return loadavg[2];
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user