Skip to content

Commit

Permalink
Micro optimisations in wait_for_less_busy_worker feature (puma#2579)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ghiculescu authored and JuanitoFatas committed Sep 9, 2022
1 parent b3eab1a commit ee83d53
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/puma/server.rb
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/puma/thread_pool.rb
Expand Up @@ -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
Expand Down

0 comments on commit ee83d53

Please sign in to comment.