Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

• 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

Slide 3

Slide 3 text

3 GitHub: matsumotory

Slide 4

Slide 4 text

4 write a paper for academic conferences

Slide 5

Slide 5 text

1. Introduction of embedding mruby into nginx 2. Blocking vs Non-blocking with nginx + mruby 3. Conclusions 5 Table of Contents

Slide 6

Slide 6 text

1. Introduction of embedding mruby into middleware

Slide 7

Slide 7 text

• 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

Slide 8

Slide 8 text

I met mruby in April 2012

Slide 9

Slide 9 text

9 mruby / CRuby for middleware

Slide 10

Slide 10 text

Middleware configuration as code

Slide 11

Slide 11 text

Basically embed mruby into middleware 11 lNJEEMFXBSFzXBTJNQMFNFOUFECZ$JOUIJTQSFTFOUBUJPO

Slide 12

Slide 12 text

mruby in Japan meets nginx in Russia!

Slide 13

Slide 13 text

• 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

Slide 14

Slide 14 text

• 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

Slide 15

Slide 15 text

• 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

Slide 16

Slide 16 text

2. Blocking vs Non-blocking with nginx + mruby

Slide 17

Slide 17 text

• 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

Slide 18

Slide 18 text

• 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

Slide 19

Slide 19 text

Blocking each request with mruby 19 TFOESFTQPOTF OPOCMPDLJOHNJEEMFXBSFMJLFOHJOYJOTJOHMFQSPDFTT SFDWSFRVFTUBUUIFTBNFUJNF

Slide 20

Slide 20 text

Blocking each request with mruby 20 TFOESFTQPOTF OPOCMPDLJOHNJEEMFXBSFMJLFOHJOYJOTJOHMFQSPDFTT SFDWSFRVFTUBUUIFTBNFUJNF

Slide 21

Slide 21 text

Blocking example 21

Slide 22

Slide 22 text

Non-blocking each request with mruby 22 TFOESFTQPOTF OPOCMPDLJOHNJEEMFXBSFMJLFOHJOYJOTJOHMFQSPDFTT SFDWSFRVFTUBUUIFTBNFUJNF

Slide 23

Slide 23 text

Non-blocking example 23

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

• 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

Slide 26

Slide 26 text

App server configuration 26

Slide 27

Slide 27 text

Proxy configuration with blocking operation 27

Slide 28

Slide 28 text

Proxy configuration with non-blocking 28

Slide 29

Slide 29 text

Change response time of the App server 29

Slide 30

Slide 30 text

Change the number of concurrent requests 30

Slide 31

Slide 31 text

3. Conclusions

Slide 32

Slide 32 text

• 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