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

200万 Webサイトを支える ロリポップ!と mruby

harasou
July 11, 2015

200万 Webサイトを支える ロリポップ!と mruby

200万以上のWebサイトを支えるインフラで、リソース制御として使われている mod_mruby の採用事例を紹介します。

harasou

July 11, 2015
Tweet

More Decks by harasou

Other Decks in Technology

Transcript

  1. ུ֓ਤᶃ  IUUQEPTEFUFDUPSIUUQBDDFTTMJNJUUFS "QBDIF ਌ϓϩηε NSVCZ XPSLFS NSVCZ XPSLFS NSVCZ

    XPSLFS NSVCZ XPSLFS NSVCZ ڞ༗ϝϞϦ HMPCBMMPDL ᶄΧ΢ϯλ ΠϯΫˠॲཧˠσΫϦ MPDBMNFNDBDIF ,74 ᶃUSZ@MPDL ᶅVOMPDL
  2. ઃఆᶃIUUQBDDFTTMJNJUUFS 1 LoadModule mruby_module modules/mod_mruby.so 2 3 <IfModule mod_mruby.c> 4

    mrubyPostConfigMiddle access_limitter_init.rb cache 5 mrubyChildInitMiddle access_limitter_worker_init.rb cache 6 7 <FilesMatch ^.*\.php$> 8 mrubyAccessCheckerMiddle access_limitter_start.rb cache 9 mrubyLogTransactionMiddle access_limitter_end.rb cache 10 </FilesMatch> 11 </IfModule> access_limitter_apache.conf
  3. ઃఆᶃIUUQBDDFTTMJNJUUFS access_limitter_start.rb 1 threshold = 2 2 3 Server =

    get_server_class 4 r = Server::Request.new 5 cache = Userdata.new.shared_cache 6 global_mutex = Userdata.new.shared_mutex 7 8 limit = AccessLimitter.new r, cache, { :target => r.filename } 9 10 timeout = global_mutex.try_lock_loop(50000) do 11 begin 12 limit.increment 13 if limit.current > threshold 14 Server.return Server::HTTP_SERVICE_UNAVAILABLE 15 end 16 rescue => e 17 raise "AccessLimitter failed: #{e}" 18 ensure 19 global_mutex.unlock 20 end 21 end
  4. ઃఆᶃIUUQBDDFTTMJNJUUFS access_limitter_end.rb 1 2 3 Server = get_server_class 4 r

    = Server::Request.new 5 cache = Userdata.new.shared_cache 6 global_mutex = Userdata.new.shared_mutex 7 8 limit = AccessLimitter.new r, cache, { :target => f.filename } 9 10 timeout = global_mutex.try_lock_loop(50000) do 11 begin 12 limit.decrement 13 rescue => e 14 raise "AccessLimitter failed: #{e}" 15 ensure 16 global_mutex.unlock 17 end 18 end
  5. ઃఆᶄNSVCZDHSPVQ 1 <IfModule mod_mruby.c> 2 mrubyFixupsMiddle resouce_manage_start.rb cache 3 mrubyLogTransactionMiddle

    resouce_manage_end.rb cache 4 </IfModule> 1 r = Apache::Request.new 2 u = r.finfo.user 3 4 c = Cgroup::CPU.new u 5 if c.exist? 6 c.modify 7 else 8 c.create 9 end 10 c.attach resource_manage_start.rb mod_mruby.conf
  6. ੑೳݕূ!TBXBOPCPMZ  ඵͰ ϦΫΤετͷϧʔϧͰϒϩοΫͯ͠Έͨɻ 1 config = { 2 :counter_key

    => r.hostname, 3 :magic_str => "....", 4 5 :behind_counter => -500, 6 7 :threshold_counter => 1000, 8 :threshold_time => 5, 9 10 :expire_time => 60, 11 } http://qiita.com/sawanoboly/items/74368e002631bed3afb7
  7. BC OD ͷ݁Ռ  EPTEFUFDUPSͳ͠ Concurrency Level: 30 Time taken

    for tests: 2.756 seconds Complete requests: 6000 Failed requests: 0 Requests per second: 2177.34 [#/sec] (mean) Time per request: 13.778 [ms] (mean) Time per request: 0.459 [ms] (mean, across all concurrent requests) Transfer rate: 493.30 [Kbytes/sec] received  EPTEFUFDUPS͋ΓˍϒϩοΫͳ͠ Concurrency Level: 30 Time taken for tests: 3.940 seconds Complete requests: 6000 Failed requests: 0 Total transferred: 1392000 bytes HTML transferred: 24000 bytes Requests per second: 1522.99 [#/sec] (mean) Time per request: 19.698 [ms] (mean) Time per request: 0.657 [ms] (mean, across all concurrent requests) Transfer rate: 345.05 [Kbytes/sec] received