mruby meets nginx

mruby meets nginx

mruby meets nginx

Hanabi Hack: The first Russian-Japanese hackathon in Moscow

2019/06/29

SAKURA internet Inc.
SAKURA Research Center
Ryosuke Matsumoto / matsumotory / まつもとりー / 松本亮介

2b692bd83f4418103142a053ecf5ff59?s=128

MATSUMOTO Ryosuke

June 29, 2019
Tweet

Transcript

  1. SAKURA internet Inc. (C) Copyright 1996-2019 SAKURA Internet Inc SAKURA

    Research Center mruby meets nginx 2019/06/29 Ryosuke Matsumoto Hanabi Hack: The first Russian-Japanese hackathon in Moscow
  2. • Senior Researcher at SAKURA internet Inc. • Forkwell Technical

    Advisor at Grooves Inc. • Visiting Researcher at GMO Pepabo, Inc. • Ph.D of Informatics, Kyoto University • My interests: Operation technology, Internet foundation technology, System programming, Highly integrated multi-tenant architecture, Hosting service, Cloud platform, C, mruby, Rust • Engineering => Technology <= Research 2 Ryosuke Matsumoto @matsumotory
  3. 3 GitHub: matsumotory

  4. 4 write a paper for academic conferences

  5. 1. Introduction of embedding mruby into nginx 2. Blocking vs

    Non-blocking with nginx + mruby 3. Conclusions 5 Table of Contents
  6. 1. Introduction of embedding mruby into middleware

  7. • System management for network, OS and middleware • Hosting

    service, Cloud platform service • Operation technology for middleware written by C • Apache, nginx, dovecot, postfix, sendmail, bind, proftp… • want to write operation tools for middleware using perl • want to write extension module for middleware • each middleware dependency • Apache module, nginx module, dovecot plugin…. 7 I’m a former web operation engineer
  8. I met mruby in April 2012

  9. 9 mruby / CRuby for middleware

  10. Middleware configuration as code

  11. Basically embed mruby into middleware 11 lNJEEMFXBSFzXBTJNQMFNFOUFECZ$JOUIJTQSFTFOUBUJPO

  12. mruby in Japan meets nginx in Russia!

  13. • ngx_mruby/mod_mruby(http server extension) • dovecot-mruby-plugin (imap server extension) •

    pmilter (milter server) • Trusterd HTTP/2 Web Server • h2o_mruby (Initial implementation with v1.4) • Other system tools: rcon, capcon, pfds, virtualing, ab-mruby • developed the greatest number of mrbgem in mgem-list • also received Ph.D. of informatics 13 My developed middleware with mruby
  14. • Middleware behavior scripting with mruby • Middleware configuration as

    code • limit Ruby methods by mruby • Dynamically control middleware by session parameters • cooperate with microservices • record a session data and utilize the data • implement Service Mesh functions • HTTP(S)ɾTCP/UDP stream 14 Why embed mruby into middleware
  15. • consider several viewpoints • memory management (allocate/free/leak) • performance

    (non-blocking operation) • usability, operation/development technology • Strategy for multi-process/multi-threading • focus on performance like non-blocking in this presentation 15 How embed mruby into middleware
  16. 2. Blocking vs Non-blocking with nginx + mruby

  17. • want to accept as many requests simultaneously as possible

    in single process/thread (C10k) • want to use multi cpu core sufficiently • process blocking operation in non-blocking mode • File I/O, Network I/O, sleep… • monitor I/O state and notify status change like epoll() • generally implement suitable event loop for middleware 17 Non-blocking middleware
  18. • Non-blocking middleware like nginx • mruby blocks middleware processing

    generally • Bottleneck of performance when accepting multiple requests simultaneously • Other responses are delayed in proportion to the time of processing of mruby blocking 18 Non-blocking middleware with mruby
  19. Blocking each request with mruby 19 TFOESFTQPOTF OPOCMPDLJOHNJEEMFXBSFMJLFOHJOYJOTJOHMFQSPDFTT SFDWSFRVFTUBUUIFTBNFUJNF

  20. Blocking each request with mruby 20 TFOESFTQPOTF OPOCMPDLJOHNJEEMFXBSFMJLFOHJOYJOTJOHMFQSPDFTT SFDWSFRVFTUBUUIFTBNFUJNF

  21. Blocking example 21

  22. Non-blocking each request with mruby 22 TFOESFTQPOTF OPOCMPDLJOHNJEEMFXBSFMJLFOHJOYJOTJOHMFQSPDFTT SFDWSFRVFTUBUUIFTBNFUJNF

  23. Non-blocking example 23

  24. 1.change type a blocking method of mruby to non-blocking 2.suspend

    mruby processing until the blocking method is completed • using Fiber of mruby 3.return to event loop of nginx from mruby VM • monitor non-blocking function on nginx 4.nginx process other requests…. 5.resume mruby processing by callback func in event loop 24 Non-blocking middleware nginx with mruby
  25. • We perform the following two experiments. 1. While changing

    the response time on a app server from 1 ms to 50 ms, benchmark the number of simultaneous connections with 100 and measure request/s 2. Fix the response time on the app server to 10 ms, change the number of simultaneous connections from 1 to 100, and measure request/s • We compared the performance of blocking http client and non- blocking http client under these conditions. 25 ngx_mruby blocking vs non-blocking
  26. App server configuration 26

  27. Proxy configuration with blocking operation 27

  28. Proxy configuration with non-blocking 28

  29. Change response time of the App server 29

  30. Change the number of concurrent requests 30

  31. 3. Conclusions

  32. • mruby in Japan meets nginx in Russia • I

    would be very happy if Japanese and Russian engineers could communicate more • Why / How embed mruby into middleware like nginx • connect services dynamically and programmably • blocking/non-blocking • Happy hacking nginx + mruby (ngx_mruby) ! • https://github.com/matsumotory/ngx_mruby 32 Conclusions