objs/src/http/modules/perl/blib/lib/nginx.pm usr/lib/perl/5.14
objs/src/http/modules/perl/blib/arch/auto/nginx/nginx.so usr/lib/perl/5.14/auto/nginx
http { perl_modules /etc/nginx/perl; perl_require rmqsux.pm; ...
server { listen 80; server_name test01.dev; location / { perl rmqsux::amqppull; } }
whoareyou@test01:/etc/nginx/perl# cat rmqsux.pm package rmqsux; use nginx; use Net::RabbitMQ; use vars; rmqsux::connectmyrabbit; sub try (&@) { my($try,$catch) = @_; eval { &$try }; if ($@) { local $_ = $@; &$catch; } } sub catch (&) { $_[0] } sub connectmyrabbit { try { $mq = Net::RabbitMQ->destroy(); } catch { $mq = Net::RabbitMQ->new(); }; $mq->connect("192.168.1.100", { user => "test", password => "test", vhost => "testhost" }); $mq->channel_open(1); } sub disconnectmyrabbit { $mq->disconnect(); my $r = shift; $r->send_http_header("text/html"); $r->print("disconnected\n<br/>"); $r->status(200); } sub amqppull { my $r = shift; try { $mq->publish(1, "test", "qawsed"); } catch { rmqsux::connectmyrabbit; $mq->publish(1, "test", "oops died here"); }; $r->send_http_header("text/html"); return OK if $r->header_only; $r->print("send completed\n<br/>"); $r->status(200); $r->flush; } 1; __END__
silenkov@sn00p:/home$ ab -c 300 -n 100000 http://test01.dev/ 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 test01.dev (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: nginx Server Hostname: test01.dev Server Port: 80 Document Path: / Document Length: 20 bytes Concurrency Level: 300 Time taken for tests: 10.402 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Total transferred: 13500000 bytes HTML transferred: 2000000 bytes Requests per second: 9613.40 [#/sec] (mean) Time per request: 31.206 [ms] (mean) Time per request: 0.104 [ms] (mean, across all concurrent requests) Transfer rate: 1267.39 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 14 126.9 2 3007 Processing: 1 14 30.0 9 1543 Waiting: 1 13 30.0 8 1543 Total: 3 29 136.8 11 3230 Percentage of the requests served within a certain time (ms) 50% 11 66% 15 75% 16 80% 16 90% 20 95% 49 98% 56 99% 1009 100% 3230 (longest request)
Source: https://habr.com/ru/post/155225/
All Articles