Umstellung auf PSGI

Aus OpenBib Wiki
Version vom 28. September 2015, 08:44 Uhr von Flimm (Diskussion | Beiträge)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu: Navigation, Suche

Inhaltsverzeichnis

Allgemeines

Um die Flexibilität des Einsatzes von OpenBib für die Zukunft zu erhöhen, ist eine Umstellung von mod_perl auf PSGI geplant. Mit PSGI sind verschiedene Vorteile verbunden:

Moderate Performancesteigerung

Mit dem Apache-Benchmark wurden Belastungstests durchgeführt:

ab -n 200 -c 20 "http://sake.ub.uni-koeln.de/portal/kug/databases/id/ebooks/titles/id/100967562.html?l=de"

Grundlage ist - falls nicht anders angegeben - ein Frontend-lighthttpd, der auf den jeweiligen Dienst unter Port 8008 zugreift.

Alte Version mit mod_perl

Server Software:        Apache/2.2.22
Server Hostname:        sake.ub.uni-koeln.de
Server Port:            8008

Document Path:          /portal/kug/databases/id/ebooks/titles/id/100967562.html?l=de
Document Length:        25534 bytes

Concurrency Level:      20
Time taken for tests:   68.772 seconds
Complete requests:      200
Failed requests:        0
Write errors:           0
Total transferred:      5195200 bytes
HTML transferred:       5106800 bytes
Requests per second:    2.91 [#/sec] (mean)
Time per request:       6877.236 [ms] (mean)
Time per request:       343.862 [ms] (mean, across all concurrent
requests)
Transfer rate:          73.77 [Kbytes/sec] received

Neue Version mit PSGI unter mod_perl

Server Software:        Apache/2.2.22
Server Hostname:        sake.ub.uni-koeln.de
Server Port:            80

Document Path:          /portal/kug/databases/id/ebooks/titles/id/100967562.html?l=de
Document Length:        26004 bytes

Concurrency Level:      20
Time taken for tests:   68.475 seconds
Complete requests:      200
Failed requests:        0
Write errors:           0
Total transferred:      5292000 bytes
HTML transferred:       5200800 bytes
Requests per second:    2.92 [#/sec] (mean)
Time per request:       6847.548 [ms] (mean)
Time per request:       342.377 [ms] (mean, across all concurrent requests)
Transfer rate:          75.47 [Kbytes/sec] received 

Connection Times (ms)
             min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:  2377 6715 1781.6   6422   12857
Waiting:     2377 6713 1781.4   6422   12857
Total:       2377 6715 1781.6   6422   12858

Percentage of the requests served within a certain time (ms)
 50%   6422
 66%   6880
 75%   7142
 80%   7330
 90%   9587
 95%  10531
 98%  11915
 99%  12638
100%  12858 (longest request)

Die neue Version ist unter mod_perl circa genauso schnell wie wie die native mod_perl-Version.

Neue Version mit PSGI unter starman

Server Software:        lighttpd/1.4.28
Server Hostname:        sake.ub.uni-koeln.de
Server Port:            80

Document Path:          /portal/kug/databases/id/ebooks/titles/id/100967562.html?l=de
Document Length:        26004 bytes

Concurrency Level:      20
Time taken for tests:   58.846 seconds
Complete requests:      200
Failed requests:        0
Write errors:           0
Total transferred:      5283000 bytes
HTML transferred:       5200800 bytes
Requests per second:    3.40 [#/sec] (mean)
Time per request:       5884.646 [ms] (mean)
Time per request:       294.232 [ms] (mean, across all concurrent requests)
Transfer rate:          87.67 [Kbytes/sec] received

Connection Times (ms)
             min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       0
Processing:  2135 5650 656.6   5760    6960
Waiting:     2135 5650 656.6   5760    6960
Total:       2135 5650 656.5   5760    6961

Percentage of the requests served within a certain time (ms)
 50%   5760
 66%   5824
 75%   5862
 80%   5894
 90%   5963
 95%   6018
 98%   6655
 99%   6861
100%   6961 (longest request)

Um Resourcen zu sparen wurde starman mit der Option --preload-app gestartet. Die neue Version ist etwas schneller unter starman. Insgesamt liefert starman die Webseiten aber deutlich homogener als mod_perl via PSGI (longest request).

Neue Version mit PSGI unter Gazelle

Server Software:        gazelle
Server Hostname:        sake.ub.uni-koeln.de
Server Port:            80

Document Path:          /portal/kug/databases/id/ebooks/titles/id/100967562.html?l=de
Document Length:        26004 bytes

Concurrency Level:      20
Time taken for tests:   75.967 seconds
Complete requests:      200
Failed requests:        0
Write errors:           0
Total transferred:      5281400 bytes
HTML transferred:       5200800 bytes
Requests per second:    2.63 [#/sec] (mean)
Time per request:       7596.706 [ms] (mean)
Time per request:       379.835 [ms] (mean, across all concurrent requests)
Transfer rate:          67.89 [Kbytes/sec] received 

Connection Times (ms)
             min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       0
Processing:  4708 7359 697.4   7363    9505
Waiting:     4708 7359 697.4   7362    9504
Total:       4709 7359 697.4   7363    9505

Percentage of the requests served within a certain time (ms)
 50%   7363
 66%   7567
 75%   7766
 80%   7812
 90%   8151
 95%   8388
 98%   9101
 99%   9472
100%   9505 (longest request)

Etwas schlechtere Performance als die native mod_perl-Version.

Neue Version mit PSGI unter starlet (0.24)

Server Software:        Plack::Handler::Starlet
Server Hostname:        sake.ub.uni-koeln.de
Server Port:            80

Document Path:          /portal/kug/databases/id/ebooks/titles/id/100967562.html?l=de
Document Length:        26004 bytes

Concurrency Level:      20
Time taken for tests:   71.898 seconds
Complete requests:      200
Failed requests:        0
Write errors:           0
Total transferred:      5284600 bytes
HTML transferred:       5200800 bytes
Requests per second:    2.78 [#/sec] (mean)
Time per request:       7189.787 [ms] (mean)
Time per request:       359.489 [ms] (mean, across all concurrent requests)
Transfer rate:          71.78 [Kbytes/sec] received 

Connection Times (ms)
             min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:  3112 6955 847.4   7122    8413
Waiting:     3112 6954 847.7   7118    8413
Total:       3113 6955 847.3   7122    8413

Percentage of the requests served within a certain time (ms)
 50%   7122
 66%   7256
 75%   7373
 80%   7452
 90%   7610
 95%   7727
 98%   8071
 99%   8235
100%   8413 (longest request)

Die Performance ist etwas schlechter als bei starman und mod_perl, jedoch auf gleichem Level wie die native mod_perl-Version.

Neue Version mit PSGI unter uWSGI/nginx

Server Software:        nginx/1.1.19
Server Hostname:        sake.ub.uni-koeln.de
Server Port:            80

Document Path:          /portal/kug/databases/id/ebooks/titles/id/100967562.html?l=de
Document Length:        26784 bytes

Concurrency Level:      20
Time taken for tests:   62.517 seconds
Complete requests:      200
Failed requests:        0
Write errors:           0
Total transferred:      5438400 bytes
HTML transferred:       5356800 bytes
Requests per second:    3.20 [#/sec] (mean)
Time per request:       6251.722 [ms] (mean)
Time per request:       312.586 [ms] (mean, across all concurrent requests)
Transfer rate:          84.95 [Kbytes/sec] received 

Connection Times (ms)
             min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:  1352 6000 918.0   6179    6982
Waiting:     1352 6000 918.0   6178    6982
Total:       1353 6000 917.8   6179    6982

Percentage of the requests served within a certain time (ms)
 50%   6179
 66%   6269
 75%   6328
 80%   6382
 90%   6492
 95%   6666
 98%   6859
 99%   6866
100%   6982 (longest request)

In der Kombination mit uWSGI und nginx funktionierte jedoch die Internationalisierung mit Maketext::Gettext nicht und damit ist weiterhin starman der Favorit.

Neue Version mit PSGI unter twiggy

Server Software:        lighttpd/1.4.28
Server Hostname:        sake.ub.uni-koeln.de
Server Port:            80

Document Path:          /portal/kug/databases/id/ebooks/titles/id/100967562.html?l=de
Document Length:        26004 bytes

Concurrency Level:      20
Time taken for tests:   281.572 seconds
Complete requests:      200
Failed requests:        0
Write errors:           0
Total transferred:      5283000 bytes
HTML transferred:       5200800 bytes
Requests per second:    0.71 [#/sec] (mean)
Time per request:       28157.187 [ms] (mean)
Time per request:       1407.859 [ms] (mean, across all concurrent requests)
Transfer rate:          18.32 [Kbytes/sec] received

Connection Times (ms)
             min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing: 13301 26878 2490.6  26972   38959
Waiting:    13301 26878 2490.6  26972   38959
Total:      13301 26879 2490.5  26972   38959

Percentage of the requests served within a certain time (ms)
 50%  26972
 66%  27072
 75%  27129
 80%  27177
 90%  27282
 95%  27399
 98%  34739
 99%  37528
100%  38959 (longest request)

Gegenüber starman fällt twiggy in der Performance deutlich ab.

Neue Version mit PSGI unter feersum (Feersum 1.401 on EV 4.03)

Server Software:        lighttpd/1.4.28
Server Hostname:        sake.ub.uni-koeln.de
Server Port:            80

Document Path:          /portal/kug/databases/id/ebooks/titles/id/100967562.html?l=de
Document Length:        0 bytes

Concurrency Level:      20
Time taken for tests:   37.642 seconds
Complete requests:      200
Failed requests:        161
  (Connect: 0, Receive: 0, Length: 161, Exceptions: 0)
Write errors:           0
Non-2xx responses:      161
Total transferred:      90615 bytes
HTML transferred:       59409 bytes
Requests per second:    5.31 [#/sec] (mean)
Time per request:       3764.182 [ms] (mean)
Time per request:       188.209 [ms] (mean, across all concurrent requests)
Transfer rate:          2.35 [Kbytes/sec] received

Connection Times (ms)
             min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:     0 3764 8723.4      0   37633
Waiting:        0 3764 8723.4      0   37632
Total:          0 3764 8723.5      1   37633

Percentage of the requests served within a certain time (ms)
 50%      1
 66%      1
 75%      1
 80%      6
 90%  19487
 95%  26424
 98%  33485
 99%  36160
100%  37633 (longest request)

Während des Benchmarks hat sich jeodch der feersum-Prozess spontan beendet.

Feersum try_conn_write: Ungültiger Dateideskriptor
close at write shutdown: Ungültiger Dateideskriptor
Speicherzugriffsfehler (Speicherabzug geschrieben)

Derzeit also auch noch keine Alternative für ein Produktionssystem.

Neue Version mit PSGI unter Monoceros (0.27)

Bei Monoceros lief nicht einmal Apache Bench durch:

apr_poll: The timeout specified has expired (70007)
Total of 195 requests completed

Insofern auch noch nicht fuer den Produktionseinsatz - unabhaengig von

http://de.slideshare.net/kazeburo/yapc2013psgi-plack

geeignet.

Wie viele Worker sind bei starman ideal?

Hierzu wird die Heartbeat-Resource für haproxy verwendet

ab -n 30000 -c 30 "http://sake.ub.uni-koeln.de/portal/kug/server_is_active"

Verwendet wird starman 0.3001.

20 Worker

Server Software:        lighttpd/1.4.28
Server Hostname:        sake.ub.uni-koeln.de
Server Port:            80

Document Path:          /portal/kug/server_is_active
Document Length:        0 bytes

Concurrency Level:      30
Time taken for tests:   219.449 seconds
Complete requests:      30000
Failed requests:        0
Write errors:           0
Total transferred:      5700000 bytes
HTML transferred:       0 bytes
Requests per second:    136.71 [#/sec] (mean)
Time per request:       219.449 [ms] (mean)
Time per request:       7.315 [ms] (mean, across all concurrent requests)
Transfer rate:          25.37 [Kbytes/sec] received

Connection Times (ms)
             min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:    90  219  75.1    213    2529
Waiting:       90  219  75.1    213    2529
Total:         90  219  75.1    213    2529

Percentage of the requests served within a certain time (ms)
 50%    213
 66%    222
 75%    228
 80%    232
 90%    244
 95%    259
 98%    296
 99%    345
100%   2529 (longest request)


15 Worker

Server Software:        lighttpd/1.4.28
Server Hostname:        sake.ub.uni-koeln.de
Server Port:            80

Document Path:          /portal/kug/server_is_active
Document Length:        0 bytes

Concurrency Level:      30
Time taken for tests:   224.288 seconds
Complete requests:      30000
Failed requests:        0
Write errors:           0
Total transferred:      5700000 bytes
HTML transferred:       0 bytes
Requests per second:    133.76 [#/sec] (mean)
Time per request:       224.288 [ms] (mean)
Time per request:       7.476 [ms] (mean, across all concurrent requests)
Transfer rate:          24.82 [Kbytes/sec] received

Connection Times (ms)
             min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       1
Processing:   137  224  58.3    213    2018
Waiting:      137  224  58.3    213    2018
Total:        137  224  58.3    213    2018

Percentage of the requests served within a certain time (ms)
 50%    213
 66%    219
 75%    223
 80%    227
 90%    248
 95%    271
 98%    315
 99%    429
100%   2018 (longest request)

10 Workers

Server Software:        lighttpd/1.4.28
Server Hostname:        sake.ub.uni-koeln.de
Server Port:            80

Document Path:          /portal/kug/server_is_active
Document Length:        0 bytes

Concurrency Level:      30
Time taken for tests:   208.780 seconds
Complete requests:      30000
Failed requests:        0
Write errors:           0
Total transferred:      5700000 bytes
HTML transferred:       0 bytes
Requests per second:    143.69 [#/sec] (mean)
Time per request:       208.780 [ms] (mean)
Time per request:       6.959 [ms] (mean, across all concurrent requests)
Transfer rate:          26.66 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       8
Processing:    58  209  45.8    203    1875
Waiting:       58  209  45.8    203    1875
Total:         59  209  45.8    203    1875

Percentage of the requests served within a certain time (ms)
 50%    203
 66%    207
 75%    210
 80%    212
 90%    220
 95%    231
 98%    273
 99%    332
100%   1875 (longest request)

8 Workers

Server Software:        lighttpd/1.4.28
Server Hostname:        sake.ub.uni-koeln.de
Server Port:            80

Document Path:          /portal/kug/server_is_active
Document Length:        0 bytes

Concurrency Level:      30
Time taken for tests:   206.400 seconds
Complete requests:      30000
Failed requests:        0
Write errors:           0
Total transferred:      5700000 bytes
HTML transferred:       0 bytes
Requests per second:    145.35 [#/sec] (mean)
Time per request:       206.400 [ms] (mean)
Time per request:       6.880 [ms] (mean, across all concurrent requests)
Transfer rate:          26.97 [Kbytes/sec] received

Connection Times (ms)
             min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       1
Processing:    58  206  41.5    199    1347
Waiting:       58  206  41.5    199    1347
Total:         59  206  41.5    199    1347

Percentage of the requests served within a certain time (ms)
 50%    199
 66%    205
 75%    208
 80%    211
 90%    223
 95%    251
 98%    303
 99%    376
100%   1347 (longest request)

6 Workers

Server Software:        lighttpd/1.4.28
Server Hostname:        sake.ub.uni-koeln.de
Server Port:            80

Document Path:          /portal/kug/server_is_active
Document Length:        0 bytes

Concurrency Level:      30
Time taken for tests:   211.239 seconds
Complete requests:      30000
Failed requests:        0
Write errors:           0
Total transferred:      5700000 bytes
HTML transferred:       0 bytes
Requests per second:    142.02 [#/sec] (mean)
Time per request:       211.239 [ms] (mean)
Time per request:       7.041 [ms] (mean, across all concurrent requests)
Transfer rate:          26.35 [Kbytes/sec] received

Connection Times (ms)
             min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       1
Processing:    36  211  43.3    204    1063
Waiting:       36  211  43.3    204    1063
Total:         36  211  43.3    204    1063

Percentage of the requests served within a certain time (ms)
 50%    204
 66%    210
 75%    214
 80%    217
 90%    226
 95%    239
 98%    324
 99%    437
100%   1063 (longest request)

5 Workers (default)

Server Software:        lighttpd/1.4.28
Server Hostname:        sake.ub.uni-koeln.de
Server Port:            80

Document Path:          /portal/kug/server_is_active
Document Length:        0 bytes

Concurrency Level:      30
Time taken for tests:   200.442 seconds
Complete requests:      30000
Failed requests:        0
Write errors:           0
Total transferred:      5700000 bytes
HTML transferred:       0 bytes
Requests per second:    149.67 [#/sec] (mean)
Time per request:       200.442 [ms] (mean)
Time per request:       6.681 [ms] (mean, across all concurrent requests)
Transfer rate:          27.77 [Kbytes/sec] received

Connection Times (ms)
             min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       3
Processing:    36  200  43.7    193    1209
Waiting:       36  200  43.7    193    1209
Total:         37  200  43.7    193    1209

Percentage of the requests served within a certain time (ms)
 50%    193
 66%    200
 75%    204
 80%    208
 90%    220
 95%    241
 98%    301
 99%    400
100%   1209 (longest request)

4 Workers

Server Software:        lighttpd/1.4.28
Server Hostname:        sake.ub.uni-koeln.de
Server Port:            80

Document Path:          /portal/kug/server_is_active
Document Length:        0 bytes

Concurrency Level:      30
Time taken for tests:   153.732 seconds
Complete requests:      30000
Failed requests:        0
Write errors:           0
Total transferred:      5700000 bytes
HTML transferred:       0 bytes
Requests per second:    195.14 [#/sec] (mean)
Time per request:       153.732 [ms] (mean)
Time per request:       5.124 [ms] (mean, across all concurrent requests)
Transfer rate:          36.21 [Kbytes/sec] received

Connection Times (ms)
             min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       1
Processing:    29  154  38.9    146     896
Waiting:       29  154  38.9    146     896
Total:         30  154  38.9    146     896

Percentage of the requests served within a certain time (ms)
 50%    146
 66%    150
 75%    153
 80%    156
 90%    165
 95%    181
 98%    239
 99%    337
100%    896 (longest request)

Fazit

Viel hilft nicht immer viel. Auf mehr als 10 Worker sollte man besser verzichten. Interessant ist, dass 4 Worker mit deutlichem Abstand - 5 bis 10 Worker geben sich fast nichts - bei der gewählten Abfrage die beste Performance bringt. Dennoch sieht die Realität manchmal dann doch etwas anders aus, als es die Benchmarks auszusagen scheinen. Bei 4 Workern bricht die OpenBib-Anwendung im Realbetrieb nach spätestens 30 Sekunden zusammen.... Mit 20 Workern, die wir nun verwenden, ist alle ok.

Stolperfallen

Umstellungen

use base 'OpenBib::Handler::PSGI'

anstelle von

use base 'OpenBib::Handler::Apache' 

Also entfernen von:

use Apache2::Const -compile => qw(:common :http);
use Apache2::Reload;
use Apache2::Request ();
use Apache2::SubRequest (); # internal_redirect
return $self->print_page($config->{tt_admin_tname},$ttdata);

anstelle von der Ausgabe ueber den Request-Handle $r

$self->print_page($config->{tt_admin_tname},$ttdata);
return Apache2::Const::OK;
my $query  = $r;

anstelle von

my $query  = Apache2::Request->new($r);
$self->query->method('GET');
$self->query->content_type('text/html');
$self->query->headers_out->add(Location => $new_location);
$self->query->status(Apache2::Const::REDIRECT);

auf

$self->header_add('Content-Type' => 'text/html');
$self->redirect($new_location);
my $return_uri = uri_escape($r->request_uri);

anstelle

my $return_uri = uri_escape($r->parsed_uri->unparse);
Meine Werkzeuge
Namensräume
Varianten
Aktionen
Navigation
Werkzeuge