Skip to content

Commit

Permalink
Try creating a new Thread once a second if exhausted
Browse files Browse the repository at this point in the history
Instead of completely not try anymore.  Also, always prod the affinity
workers, even if thread creation will not work.
  • Loading branch information
lizmat committed Nov 11, 2017
1 parent fe1f863 commit 5737449
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/core/ThreadPoolScheduler.pm
Expand Up @@ -453,12 +453,12 @@ my class ThreadPoolScheduler does Scheduler {
# The supervisor sits in a loop, mostly sleeping. Each time it wakes up,
# it takes stock of the current situation and decides whether or not to
# add threads.
my constant SUPERVISION_INTERVAL = 0.01;
my constant NUM_SAMPLES = 5;
my constant SUPERVISION_INTERVAL = 0.01;
my constant NUM_SAMPLES = 5;
my constant EXHAUSTED_RETRY_AFTER = 100;
method !maybe-start-supervisor(--> Nil) {
unless $!supervisor.DEFINITE {
$!supervisor = Thread.start(:app_lifetime, :name<Supervisor>, {

sub add-general-worker(--> Nil) {
$!state-lock.protect: {
$!general-workers := push-worker(
Expand Down Expand Up @@ -533,7 +533,13 @@ my class ThreadPoolScheduler does Scheduler {
scheduler-debug-status "Per-core utilization (approx): $smooth-per-core-util%"
if $scheduler-debug-status;

unless $!exhausted {
# exhausted the system allotment of low level threads
if $!exhausted {
$!exhausted = 0 if ++$!exhausted > EXHAUSTED_RETRY_AFTER;
}

# we can still add threads if necessary
else {
self!tweak-workers($!general-queue, $!general-workers,
&add-general-worker, $cpu-cores, $smooth-per-core-util)
if $!general-queue.DEFINITE && $!general-queue.elems;
Expand All @@ -542,10 +548,12 @@ my class ThreadPoolScheduler does Scheduler {
&add-timer-worker, $cpu-cores, $smooth-per-core-util)
if $!timer-queue.DEFINITE && $!timer-queue.elems;

self!prod-affinity-workers: $!affinity-workers
if $!affinity-workers.DEFINITE;
}

# always need to prod affinity workers
self!prod-affinity-workers: $!affinity-workers
if $!affinity-workers.DEFINITE;

CATCH {
when X::AdHoc {
if .payload.starts-with("Could not create a new Thread") {
Expand Down

0 comments on commit 5737449

Please sign in to comment.