From 78cf164e3568d87e97f7897b85ca24a746e35455 Mon Sep 17 00:00:00 2001 From: Alex Ghiculescu Date: Wed, 17 Mar 2021 14:11:38 -0500 Subject: [PATCH] Micro optimisations in `wait_for_less_busy_worker` feature (#2579) * Micro optimisations in `wait_for_less_busy_worker` feature Two small things: - https://github.com/puma/puma/pull/2079/files#r422738756 -> swap the order of calls so that the faster call (float comparison) runs first. - https://github.com/puma/puma/pull/2079/files#r596114279 -> don't call `.to_f` on option that we already know is a float. * Update server.rb * Update thread_pool.rb * Update thread_pool.rb --- lib/puma/server.rb | 3 +-- lib/puma/thread_pool.rb | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/puma/server.rb b/lib/puma/server.rb index 8985b83c27..0b42460c59 100644 --- a/lib/puma/server.rb +++ b/lib/puma/server.rb @@ -327,8 +327,7 @@ def handle_servers break if handle_check else pool.wait_until_not_full - pool.wait_for_less_busy_worker( - @options[:wait_for_less_busy_worker].to_f) + pool.wait_for_less_busy_worker(@options[:wait_for_less_busy_worker]) io = begin sock.accept_nonblock diff --git a/lib/puma/thread_pool.rb b/lib/puma/thread_pool.rb index 7a8ff83ee0..c1100807b9 100644 --- a/lib/puma/thread_pool.rb +++ b/lib/puma/thread_pool.rb @@ -240,11 +240,12 @@ def wait_until_not_full # @version 5.0.0 def wait_for_less_busy_worker(delay_s) + return unless delay_s && delay_s > 0 + # Ruby MRI does GVL, this can result # in processing contention when multiple threads # (requests) are running concurrently return unless Puma.mri? - return unless delay_s > 0 with_mutex do return if @shutdown