Skip to content

Commit

Permalink
small optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jul 5, 2012
1 parent 5fa2485 commit 2ab447f
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -138,10 +138,9 @@ sub server {
$self->$cb($stream, $id);

# Enforce connection limit (randomize to improve load balancing)
if (defined $self->{accepts}) {
$self->{accepts} -= int(rand 2) ? 1 : 2;
$self->max_connections(0) if $self->{accepts} <= 0;
}
$self->max_connections(0)
if defined $self->{accepts}
&& ($self->{accepts} -= int(rand 2) + 1) <= 0;

# Stop listening
$self->_not_listening;
Expand Down

0 comments on commit 2ab447f

Please sign in to comment.