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

mruby-2017-yeah

 mruby-2017-yeah

「ここまで出来るmruby」
builderscon Tokyo 2017

Kazuhiko Yamashita

August 05, 2017
Tweet

More Decks by Kazuhiko Yamashita

Other Decks in Technology

Transcript

  1. ܰྔ3VCZ $ valgrind ruby -e 'puts “buildercon Tokyo 2017 Yeah!!!!”

    ==3537== HEAP SUMMARY: ==3537== in use at exit: 2,719,641 bytes in 23,303 blocks ==3537== total heap usage: 48,117 allocs, 8,876,176 bytes allocated $ valgrind mruby -e 'puts “buildercon Tokyo 2017 Yeah!!!!” ==3638== HEAP SUMMARY: ==3638== in use at exit: 0 bytes in 0 blocks ==3638== total heap usage: 4,468 allocs, 483,579 bytes allocated লϝϞϦ
  2. NPE@NSVCZ "QBDIF)551% mrubyFixupsFirst (ap_hook_fixups) mrubyLogTransactionLast (ap_hook_log_transaction) ɾ ɾ ɾ request

    *G.PEVMFNPE@NSVCZD NSVCZ'JYVQT'JSTUFUDIUUQEDPOGEIPPLSCDBDIF *G.PEVMF # hook.rb Apache.echo "hello world!" "QBDIFͷϑοΫΛར༻͠ɺNSVCZΛ࣮ߦ
  3. NSCHFNΛ։ൃ͢Δ NSVCZNSCHFNUFNQMBUF /mruby-builderscon |--mrblib | |—mrb_builderscon.rb |—Rakefile |--src | |--mrb_builderscon.c

    | |--mrb_builderscon.h |--test | |--mrb_builderscon.rb |--mrbgem.rake NSVCZͷ֦ுϞδϡʔϧͰ͋ΔNSCHFNͷςϯϓϨʔτΛࣗಈͰੜ੒͢ΔNSCHFN࡞ͬͨʯ IUUQCMPHNBUTVNPUPSKQ Q ਺ߦͷઃఆϑΝΠϧͰίʔυͷ਽ܗɺ ίϯύΠϧఆٛɺςετɺ3FBENFɺ ϥΠηϯεϑΝΠϧΛ࡞੒
  4. ΑΓਂ͘જΔͨΊʹ main thread(pid:X) signal thread kill -HUP X SignalThread.trap(:HUP) do

    configure.reload end reload ᶃγάφϧىಈ ᶄ)61γάφϧΛϝΠϯεϨουͷ1*%΁ૹΔ NSVCZTJHOBMUISFBE
  5. NSVCZ͸௥͍΍͍͢ /mruby-builderscon |--mrblib | |—mrb_builderscon.rb |—Rakefile |--src | |--mrb_builderscon.c |

    |--mrb_builderscon.h |--test | |—mrb_builderscon.rb |--build_config.rb |--mruby CVJME@DPOpHSC NSVCZ 3VCZͷ%4-ͰNSVCZͷϏϧυઃఆ NSVCZͷιʔεҰࣜ .#  HJUIVCDPNNSVCZNSVCZ
  6. HEC $ gdb mruby/bin/mruby (gdb) b mrb_sym2name (gdb) run example/builderscon.rb

    (gdb) p name $3 = 0x70d4b0 “Lazy” … (gdb) p mrb->symtbl[0] $6 = {lit = 1 '\001', len = 9, name = 0x474950 "inherited"} (gdb) p mrb->symtbl[1] $7 = {lit = 1 '\001', len = 12, name = 0x4748b2 "__attached__"} (gdb) p mrb->symtbl[2] $8 = {lit = 0 '\000', len = 11, name = 0x6c1e20 "BasicObject"}
  7. mrb->symtbl [0] name =>inherited [1] name => __attached__ … [10]

    name => Lazy … [31] name => USR1 NSVCZ4ZNCPM 4ZNCPM5BCMF mrb_value :USR1 => sym => 10
  8. BGUFSNSVCZ # gdb /usr/sbin/nginx core.11528 GNU gdb (GDB) Red Hat

    Enterprise Linux 7.6.1-94.el7 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details.
  9. NSCHFNSBLF NSCHFNͷґଘؔ܎ ίϯύΠϧΦϓγϣϯΛఆٛ MRuby::Gem::Specification.new('mruby-signal-thread') do |spec| spec.license = 'MIT' spec.authors

    = 'pyama86' spec.cc.flags << "-DMRB_THREAD_COPY_VALUES" spec.add_dependency 'mruby-thread' spec.add_test_dependency 'mruby-process' end
  10. $3VCZͱͷࠩҟ͸ϚΫϩͰରॲ͢Δ #define VALUE mrb_value #define ID mrb_sym #define SYM2ID(mrb, o)

    mrb_sym2str(mrb, mrb_symbol(o)) #define ID2SYM(o) mrb_symbol(o) $3VCZͰ͸ఆٛࡁΈɺNSVCZͰ͸ະఆٛͳ ϚΫϩ΍ϝιου͸ͦΕͳΓʹ͋Δ
  11. server { listen 443 ssl http2; ssl on; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;

    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; ssl_session_timeout 1d; ssl_session_cache shared:SSL:50m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; server_name example.com; root /var/www/releases; } º 
  12. OHY@NSVCZূ໌ॻͷಈతಡΈࠐΈ ਃ͠ࠐΈ ϖʔδ HPMBOH &DIP TJEFLJR .Z42- OHY@NSVCZ SFEJT NSVCZ@TTM@IBOETIBLF@IBOEMFS@DPEF

    TTM/HJOY44-OFX EPNBJOTTMTFSWFSOBNF SFEJT6TFSEBUBOFXSFEJT TTMDFSUJpDBUF@EBUBSFEJT<\EPNBJO^DSU> TTMDFSUJpDBUF@LFZ@EBUBSFEJT<\EPNBJO^LFZ> 
  13. NPE@NSVCZ NSVCZBDDFTTMJNJUUFS BMCB BDDFTTMPH MJNJUZNM MPDBM NFNDBDIF BDDFTT MJNJUUFS ϩάղੳ

    ੍ݶઃఆ࡞੒ ੍ݶઃఆ͕ଘࡏ͢Δ৔߹ʹϝϞϦಡΈࠐΈ MPDBMNFNDBDIF ΠϯϝϞϦ,74  Λར༻͢Δ͜ͱͰઃఆͷ࠶ಡࠐΛෆཁʹ IUUQTHJUIVCDPNNBUTVNPUPSZNSVCZMPDBMNFNDBDIF
  14. 1SPYZ DPOUBJOFS MJTUFO DPOUBJOFS ىಈ ఀࢭ DPOUBJOFS Ԡ౴ 'BTU$POUBJOFSΞʔΩςΫνϟ 'BTU$(*͔Βண૝

    ϦΫΤετܖػʹ௒ߴ଎ʹ
 ίϯςφΛىಈ ੜ·ΕมΘΓͷաఔͰ
 ΑΓڧ͘ɺ૿͑Δ
  15. NSVCZOFUXPSLBOBMZ[FS /FUXPSL"OBMZ[FSDPMMFDU FUI   <  \  

    TSD@IPTU    ETU@IPTU    TSD@QPSU    ETU@QPSU    UPUBM@TFOU    UPUBM@SFDW    TFOU@IJTUPSZ<>    SFDW@IJTUPSZ<>  ^ > ࢦఆͨ͠ΠϯλʔϑΣʔεΛ ࢦఆͨ͠ඵ਺Ωϟϓνϟ͠ɺ ίϯςφͷར༻ঢ়گΛ೺Ѳ IUUQTHJUIVCDPNQZBNBNSVCZOFUXPSLBOBMZ[FS
  16. NSVCZOFUXPSLBOBMZ[FS σόΠεΦʔϓϯ JG EBUBQEQDBQ@PQFO@MJWF JG@OBNF $"1563&@-&/(5)   FCVG /6--

    \ NSC@SBJTFG NSC &@36/5*.&@&3303 QDBQPQFOFSSPS4 NSC@TUS@OFX@DTUS NSC FCVG  ^ EMUQDBQ@EBUBMJOL EBUBQE  JG EMU%-5@&/.# \ ࢦఆඵ਺଴ͭ TMFFQ TFD  QBDLFU@MPPQ@DPOGD\NSC EBUB^ ࢦఆඵ਺όοϑΝʹ஝ੵͨ͠ύέοτΛίʔϧόοΫϝιουͰूܭ͢Δ QDBQ@EJTQBUDI EBUBQE NBY IBOEMF@FUI@QBDLFU D  QDBQ@DMPTF EBUBQE  ^
  17. NSVCZJQWTBEN 1SPYZ DPOUBJOFS TTI TTI DPOUBJOFS TTI 1SPYZ DPOUBJOFS TTI

    TTI DPOUBJOFS TTI TTI ίϯςφύέοτϧʔςΟϯά τϥϯεϙʔτ૚ͷ૊Έ߹Θͤ͸
  18. NSVCZJQWTBEN IUUQTHJUIVCDPNQZBNBNBEBN NBEBNBQQMZ DBUTBNQMFTBNQMFKTPO  JQWTBEN-O *17JSUVBM4FSWFSWFSTJPO TJ[F  1SPU-PDBM"EESFTT1PSU4DIFEVMFS'MBHT

    3FNPUF"EESFTT1PSU'PSXBSE8FJHIU"DUJWF$POO*O"DU$POO 5$1SS 3PVUF 3PVUF +40/Ͱ*174Λߏ੒