Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Trusterd: HTTP/2 Web Server scripting with mruby

Trusterd: HTTP/2 Web Server scripting with mruby

mrubyで振る舞いを記述可能な高速に動作するHTTP/2 Webサーバ

MATSUMOTO Ryosuke

January 28, 2015
Tweet

More Decks by MATSUMOTO Ryosuke

Other Decks in Technology

Transcript

  1. ߴ଎ʢ೥݄ݱࡏʣ HTTP/2  Server  \ size  of  content 6  bytes 4,096

     bytes ngh)pd(single  thread) 148,841 73,812 ngh)pd(mul=  thread) 347,152 104,244 =ny-­‐ngh)pd(single  thread) 190,223 82,047 trusterd(single  thread) 204,769 92,068 trusterd(mul=  process) 509,059 134,542 H2O(single  thread) 216,453 112,356 H2O(mul=  thread) 379,623 146,343 第7回フクオカRuby大賞 本審査 5 HTTP/1  Server  \ size  of  content 6  bytes 4,096  bytes nginx(single  thread) 21,708 22,366 nginx(mul=  process) 67,349 56,203 ࢀߟɿಉ؀ڥͷ)551ͷ݁Ռɹ ※ https://github.com/matsumoto-r/trusterd#benchmarks
  2. ։ൃͷܦҢ •  աڈʹNPE@NSVCZOHY@NSVCZΛ։ൃ –  ߴ଎ɾলϝϞϦʹ8FCαʔόΛػೳ֦ு –  3VCZͰ͋Δఔ౓ৼΔ෣͍Λهड़Մೳ –  ಈతͳઃఆɾ֦ுΛ3VCZͰهड़Մೳ • 

    NPE@NSVCZOHY@NSVCZͷଥڠ఺ –  ੑೳ͕"QBDIF΍OHJOYʹґଘ –  ઃఆͷ֦ு΍࣮૷͕Ϟδϡʔϧ࢓༷ʹґଘ –  ݁ہຊମͷઃఆ͔ΒಀΕΒΕͳ͍ɾࠞࡏ 第7回フクオカRuby大賞 本審査 6
  3. 3VCZͰઃఆ͕ॻ͚Δ 第7回フクオカRuby大賞 本審査 10 root_dir = "/usr/local/trusterd" s = HTTP2::Server.new({

    :port => 8080, :document_root => “#{root_dir}/htdocs”, :server_name => “Trusterd/0.0.1”, :tls => false, :worker => “auto”, }) s.run
  4. 3VCZͰػೳ֦ுͰ͖Δ 第7回フクオカRuby大賞 本審査 11 s.set_map_to_strage_cb { if s.r.uri == ”/”

    s.r.filename = "#{root_dir}/index.html” end if s.r.uri =~ /^.*\.rb$/ s.enable_mruby fi } s.set_content_cb { s.r.rputs "hello trusterd world from cb” }
  5. 3VCZͰػೳ֦ுͰ͖Δ 第7回フクオカRuby大賞 本審査 12 f = File.open "#{root_dir}/logs/access.log", "a" s.set_logging_cb

    { f.write "client_ip:'#{s.conn.client_ip}' date:'#{s.r.date}' status:#{s.r.status} content_length:#{s.r.content_length} uri:'#{s.r.uri}' filename:'#{s.r.filename}' user_agent:'#{s.r.user_agent}'\n" } s.set_access_check_cb { s.r.set_status 403 if deny }
  6. 3VCZͰػೳ֦ுͰ͖Δ 第7回フクオカRuby大賞 本審査 13 s.set_map_to_strage_cb { # Experiment: reverse proxy

    # client <=HTTP/2=> trusterd <=HTTP/1=> Upstream if s.r.uri == /^/upstream(¥/.*)/ s.upstream_uri = $1 s.upstream = “http://127.0.0.1:8081” end }