diff options
Diffstat (limited to 'src/thread_pool.zig')
-rw-r--r-- | src/thread_pool.zig | 28 |
1 files changed, 4 insertions, 24 deletions
diff --git a/src/thread_pool.zig b/src/thread_pool.zig index 704d4783e..9608c1bca 100644 --- a/src/thread_pool.zig +++ b/src/thread_pool.zig @@ -213,7 +213,7 @@ fn _wait(self: *ThreadPool, _is_waking: bool, comptime sleep_on_idle: bool) erro var is_idle = false; var is_waking = _is_waking; var sync = @bitCast(Sync, self.sync.load(.Monotonic)); - var idle_network_ticks: u32 = 0; + var checked_count: usize = 0; while (true) { if (sync.state == .shutdown) return error.Shutdown; @@ -275,13 +275,7 @@ fn _wait(self: *ThreadPool, _is_waking: bool, comptime sleep_on_idle: bool) erro const HTTP = @import("http"); io.tick() catch {}; - const end_count = HTTP.AsyncHTTP.active_requests_count.loadUnchecked(); - - if (end_count > 0) { - if (comptime sleep_on_idle) { - idle_network_ticks = 0; - } - + if (HTTP.AsyncHTTP.active_requests_count.loadUnchecked() > 0) { var remaining_ticks: isize = 5; while (remaining_ticks > 0 and HTTP.AsyncHTTP.active_requests_count.loadUnchecked() > HTTP.AsyncHTTP.max_simultaneous_requests) : (remaining_ticks -= 1) { @@ -290,26 +284,12 @@ fn _wait(self: *ThreadPool, _is_waking: bool, comptime sleep_on_idle: bool) erro } } - const idle = HTTP.AsyncHTTP.active_requests_count.loadUnchecked() == 0; - if (sleep_on_idle and io.hasNoWork()) { - if (comptime @hasField(AsyncIO, "pending_count")) { + if (checked_count > 99999) { HTTP.cleanup(false); self.idle_event.waitFor(comptime std.time.ns_per_s * 60); } else { - idle_network_ticks += @as(u32, @boolToInt(idle)); - - // If it's been roughly 2ms since the last network request, go to sleep! - // this is 4ms because run_for_ns runs for 10 microseconds - // 10 microseconds * 400 == 4ms - if (idle_network_ticks > 400) { - idle_network_ticks = 0; - // force(true) causes an assertion failure - // judging from reading mimalloc's code, - // it should only be used when the thread is about to shutdown - HTTP.cleanup(false); - self.idle_event.wait(); - } + checked_count += 1; } } |