New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run all request processing handler on fiber and support simple async methods #344

Merged
merged 34 commits into from Feb 22, 2018

Conversation

Projects
None yet
2 participants
@matsumotory
Copy link
Owner

matsumotory commented Feb 19, 2018

  • Support all request processing handler on fiber
  • Support Nginx::Async.sleep

Pull-Request Check List

@matsumotory matsumotory changed the title Run all request processing handler on fiber and support a simple async method [WIP] Run all request processing handler on fiber and support a simple async method Feb 19, 2018

@matsumotory matsumotory changed the title [WIP] Run all request processing handler on fiber and support a simple async method [WIP] Run all request processing handler on fiber and support simple async methods Feb 19, 2018

@matsumotory

This comment has been minimized.

Copy link
Owner

matsumotory commented Feb 19, 2018

[memo in japanese]


52417ac のcommitによってスーパーメモリリークが解消されたところで、全handlerがfiber経由するようになったので、v1系とv2で性能比較してみた。遅くはなっているが、それほど遅くもなっていない的な感じ。

  • 環境

    • Vagrant ubuntu 16
    • CPUはマックのコアを2つcorei7
    • メモリは8GB割り当て
    • build.shでビルド
  • nginx.conf.default

一番方式のオーバヘッドが顕著になるようにRubyのコードはコストが軽量なものにしておく。

    server {
        listen       58080;
        server_name  localhost;


        location /mruby {
                mruby_content_handler_code 'Nginx.echo "hello mruby #{Nginx.module_version}"';
        }

    }
  • 起動コマンド
./build/nginx/sbin/nginx -c conf/nginx.conf.default
  • ベンチコマンド
$ ab -c 100 -n 100000 -l -k http://127.0.0.1:58080/mruby

v1の性能

$ curl http://127.0.0.1:58080/mruby
hello mruby 1.20.2
Server Hostname:        127.0.0.1
Server Port:            58080

Document Path:          /mruby
Document Length:        Variable

Concurrency Level:      100
Time taken for tests:   2.578 seconds
Complete requests:      100000
Failed requests:        0
Keep-Alive requests:    99049
Total transferred:      14095245 bytes
HTML transferred:       1900000 bytes
Requests per second:    38788.47 [#/sec] (mean)
Time per request:       2.578 [ms] (mean)
Time per request:       0.026 [ms] (mean, across all concurrent requests)
Transfer rate:          5339.19 [Kbytes/sec] received

v2の性能

$ curl http://127.0.0.1:58080/mruby
hello mruby 2.0.0-dev
Server Software:        nginx/1.13.8
Server Hostname:        127.0.0.1
Server Port:            58080

Document Path:          /mruby
Document Length:        Variable

Concurrency Level:      100
Time taken for tests:   3.317 seconds
Complete requests:      100000
Failed requests:        0
Keep-Alive requests:    99049
Total transferred:      14395245 bytes
HTML transferred:       2200000 bytes
Requests per second:    30147.40 [#/sec] (mean)
Time per request:       3.317 [ms] (mean)
Time per request:       0.033 [ms] (mean, across all concurrent requests)
Transfer rate:          4238.08 [Kbytes/sec] received

まとめ

fiberで包んだノンブロッキング対応のmruby実行方式によって、

Requests per secondがv1の38788.47 [#/sec]から30147.40 [#/sec]になった。もうちょいこの差が埋まるように色々最適化していく。とはいえ、色々ルーチン書くのであれば十分に実用しそうではある。


メモリの使用量は、ベンチを何回か取った後に見たところ、v1は16MBに対してv2は50MBぐらいになっている。この値からは増えないけど、処理が色々増えたぶんメモリは増えたなぁ

matsumotory added some commits Feb 21, 2018

@matsumotory matsumotory changed the title [WIP] Run all request processing handler on fiber and support simple async methods Run all request processing handler on fiber and support simple async methods Feb 22, 2018

@matsumotory

This comment has been minimized.

Copy link
Owner

matsumotory commented Feb 22, 2018

Doooooone

@matsumotory matsumotory merged commit 3bfb74d into v2-dev Feb 22, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment