[Moscow.pm] Вакансия: AnyEvent in Mail.ru

Ivan Petrov i.petro.77.00 на gmail.com
Ср Июл 24 04:13:54 PDT 2013


>>>> кодом. Но это дело привычки скорее.
>>> 
>>> А почему, кстати, голый ЭниЭвент, а не Coro, скажем?
>>> 
>> 
>> В основном - производительность.

> А поподробнее можно? Может я че не заметил, но если там копейки, то выигрыш в читаемости важнее.

apache:[~]$ cat http_coro 
#!/usr/bin/perl

use warnings;
use strict;

use utf8;
use open qw(:std :utf8);

use Coro::Twiggy;
use Coro;

my $srv = Coro::Twiggy->new(host => '127.0.0.1', port => 8081);
$srv->register_service(sub {
    return [
        200,
        [ 'Content-Type', 'text/html' ],
        [ 'ok' ]
    ]
});


Coro::schedule;
apache:[~]$ cat http_ae  
#!/usr/bin/perl

use warnings;
use strict;

use utf8;
use open qw(:std :utf8);

use Twiggy::Server;
use AnyEvent;
my $srv = Twiggy::Server->new(host => '127.0.0.1', port => 8082);
$srv->register_service(sub {
    sub {
        my ($cb) = @_;
        $cb->(
            [
                200,
                [ 'Content-Type', 'text/html' ],
                [ 'ok' ]
            ]
        )
    }
});

AE::cv->recv;

apache:[~]$ perl http_coro &
apache:[~]$ perl http_ae &

apache:[~]$ ab -n 100000 -c 500 http://127.0.0.1:8081/ 
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:        
Server Hostname:        127.0.0.1
Server Port:            8081

Document Path:          /
Document Length:        2 bytes

Concurrency Level:      500
Time taken for tests:   35.719 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      4600000 bytes
HTML transferred:       200000 bytes
Requests per second:    2799.60 [#/sec] (mean)
Time per request:       178.597 [ms] (mean)
Time per request:       0.357 [ms] (mean, across all concurrent requests)
Transfer rate:          125.76 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  115 414.8      0    7014
Processing:     3   49  49.3     43    2470
Waiting:        3   49  49.3     43    2470
Total:         10  164 423.1     44    7706

Percentage of the requests served within a certain time (ms)
  50%     44
  66%     46
  75%     51
  80%     55
  90%     88
  95%   1045
  98%   1066
  99%   1690
 100%   7706 (longest request)
apache:[~]$ ab -n 100000 -c 500 http://127.0.0.1:8082/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 127.0.0.1 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:        
Server Hostname:        127.0.0.1
Server Port:            8082

Document Path:          /
Document Length:        2 bytes

Concurrency Level:      500
Time taken for tests:   28.868 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      4600000 bytes
HTML transferred:       200000 bytes
Requests per second:    3464.04 [#/sec] (mean)
Time per request:       144.340 [ms] (mean)
Time per request:       0.289 [ms] (mean, across all concurrent requests)
Transfer rate:          155.61 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1  26.3      0    1001
Processing:     1  143 1832.8     25   28836
Waiting:        1  143 1832.8     25   28836
Total:          6  144 1834.4     25   28868

Percentage of the requests served within a certain time (ms)
  50%     25
  66%     25
  75%     25
  80%     26
  90%     35
  95%     35
  98%     35
  99%     35
 100%  28868 (longest request)


То есть AE в данном простейшем тесте быстрее чем Coro в 1.24 раза.

я для себя давно уже определил, что даже если бы Coro был медленнее в
4 раза, то  я бы все равно использовал Coro ибо простота написания
приложений + простота внесения в них изменений + простота *ввода в
проект нового человека* перевешивают все остальное.

но и в целом 20% оверхеда не такая уж страшная вещь.


Подробная информация о списке рассылки Moscow-pm