Skip to content

Commit

Permalink
improved accept performance of the standalone daemon with EV backend …
Browse files Browse the repository at this point in the history
…by up to 1000%
  • Loading branch information
kraih committed Sep 24, 2011
1 parent e077135 commit 0a59916
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 40 deletions.
4 changes: 3 additions & 1 deletion Changes
@@ -1,6 +1,6 @@
This file documents the revision history for Perl extension Mojolicious.

1.99 2011-09-22 00:00:00
1.99 2011-09-24 00:00:00
- Deprecated direct hash access to the flash in
Mojolicious::Controller.
- Added EXPERIMENTAL group function to Mojolicious::Lite.
Expand All @@ -11,6 +11,8 @@ This file documents the revision history for Perl extension Mojolicious.
- Updated WebSocket implementation to ietf-15.
- Improved documentation.
- Improved CSS of some built-in templates.
- Improved accept performance of the standalone daemon with EV
backend by up to 1000%.
- Fixed CSS of built-in exception template.
- Fixed close event bug in Mojo::IOLoop.
- Fixed small redirect_to bug. (judofyr, sri)
Expand Down
9 changes: 4 additions & 5 deletions lib/Mojo/IOLoop.pm
Expand Up @@ -21,9 +21,7 @@ has iowatcher => sub {
};
has max_accepts => 0;
has max_connections => 1000;
has [qw/on_lock on_unlock/] => sub {
sub {1}
};
has [qw/on_lock on_unlock/];
has resolver => sub {
my $resolver = Mojo::IOLoop::Resolver->new(ioloop => shift);
weaken $resolver->{ioloop};
Expand Down Expand Up @@ -392,7 +390,7 @@ sub _listening {
return unless keys %$servers;
my $i = keys %{$self->{connections}};
return unless $i < $self->max_connections;
return unless $self->on_lock->($self, !$i);
if (my $cb = $self->on_lock) { return unless $self->$cb(!$i) }

# Start listening
$_->resume for values %$servers;
Expand All @@ -404,7 +402,8 @@ sub _not_listening {

# Check if we are listening
return unless delete $self->{listening};
$self->on_unlock->($self);
return unless my $cb = $self->on_unlock;
$self->$cb();

# Stop listening
$_->pause for values %{$self->{servers} || {}};
Expand Down
37 changes: 17 additions & 20 deletions lib/Mojo/IOLoop/Server.pm
Expand Up @@ -125,26 +125,23 @@ sub listen {
$self->{handle} = $handle;

# TLS
if ($args->{tls}) {

# No TLS support
croak "IO::Socket::SSL 1.43 required for TLS support" unless TLS;

# Options
my %options = (
SSL_startHandshake => 0,
SSL_cert_file => $args->{tls_cert} || $self->_cert_file,
SSL_key_file => $args->{tls_key} || $self->_key_file,
);
%options = (
SSL_verify_callback => $args->{tls_verify},
SSL_ca_file => -T $args->{tls_ca} ? $args->{tls_ca} : undef,
SSL_ca_path => -d $args->{tls_ca} ? $args->{tls_ca} : undef,
SSL_verify_mode => $args->{tls_ca} ? 0x03 : undef,
%options
) if $args->{tls_ca};
$self->{tls} = {%options, %{$args->{tls_args} || {}}};
}
return unless $args->{tls};
croak "IO::Socket::SSL 1.43 required for TLS support" unless TLS;

# Options
my %options = (
SSL_startHandshake => 0,
SSL_cert_file => $args->{tls_cert} || $self->_cert_file,
SSL_key_file => $args->{tls_key} || $self->_key_file,
);
%options = (
SSL_verify_callback => $args->{tls_verify},
SSL_ca_file => -T $args->{tls_ca} ? $args->{tls_ca} : undef,
SSL_ca_path => -d $args->{tls_ca} ? $args->{tls_ca} : undef,
SSL_verify_mode => $args->{tls_ca} ? 0x03 : undef,
%options
) if $args->{tls_ca};
$self->{tls} = {%options, %{$args->{tls_args} || {}}};
}

sub generate_port {
Expand Down
1 change: 0 additions & 1 deletion lib/Mojo/IOLoop/Stream.pm
Expand Up @@ -27,7 +27,6 @@ sub DESTROY {
sub new {
my $self = shift->SUPER::new;
$self->{handle} = shift;
$self->{handle}->blocking(0);
$self->{buffer} = '';
return $self;
}
Expand Down
9 changes: 1 addition & 8 deletions lib/Mojo/IOWatcher.pm
Expand Up @@ -51,13 +51,9 @@ sub is_readable {

sub not_writing {
my ($self, $handle) = @_;

# Make sure we only watch for readable events
my $poll = $self->_poll;
$poll->remove($handle)
if delete $self->{handles}->{fileno $handle}->{writing};
$poll->remove($handle);
$poll->mask($handle, POLLIN);

return $self;
}

Expand Down Expand Up @@ -112,12 +108,9 @@ sub timer { shift->_timer(pop, after => pop, started => time) }

sub writing {
my ($self, $handle) = @_;

my $poll = $self->_poll;
$poll->remove($handle);
$poll->mask($handle, POLLIN | POLLOUT);
$self->{handles}->{fileno $handle}->{writing} = 1;

return $self;
}

Expand Down
7 changes: 2 additions & 5 deletions lib/Mojo/IOWatcher/EV.pm
Expand Up @@ -16,8 +16,7 @@ sub not_writing {

my $fd = fileno $handle;
my $h = $self->{handles}->{$fd};
my $w = $h->{watcher};
if ($w) { $w->set($fd, EV::READ) if delete $h->{writing} }
if (my $w = $h->{watcher}) { $w->set($fd, EV::READ) }
else {
weaken $self;
$h->{watcher} = EV::io($fd, EV::READ, sub { $self->_io($fd, @_) });
Expand Down Expand Up @@ -50,14 +49,12 @@ sub writing {

my $fd = fileno $handle;
my $h = $self->{handles}->{$fd};
my $w = $h->{watcher};
if ($w) { $w->set($fd, EV::WRITE | EV::READ) }
if (my $w = $h->{watcher}) { $w->set($fd, EV::WRITE | EV::READ) }
else {
weaken $self;
$h->{watcher} =
EV::io($fd, EV::WRITE | EV::READ, sub { $self->_io($fd, @_) });
}
$h->{writing} = 1;

return $self;
}
Expand Down

0 comments on commit 0a59916

Please sign in to comment.