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

Heroku と EC Booster と私 & Heroku ちょこっと Deep Dive

Heroku と EC Booster と私 & Heroku ちょこっと Deep Dive

2018-11-09 フィードフォース社内技術勉強会のプレゼン資料です。
https://developer.feedforce.jp/entry/2018/11/14/140000

D6c5403c0b6ef2f9fd51910ea38323a3?s=128

Takashi Masuda

November 09, 2018
Tweet

More Decks by Takashi Masuda

Other Decks in Technology

Transcript

  1. )FSPLVͱ&$#PPTUFSͱࢲ !NBTVUBLB

  2. w 1BB4ʢ1MBUGPSNBTB4FSWJDFʣͷͻͱͭ w ։ൃऀ͸Πϯϑϥͷ؅ཧΛؾʹ͢Δ͜ͱͳ͘ɺ ΞϓϦέʔγϣϯΛσϓϩΠ͢Δ͜ͱ͕ग़དྷΔ IUUQTIFSPLVDPN

  3. w &$αΠτͷӡӦऀ͕࠷୹̑෼͔Β(PPHMFγϣο ϐϯά޿ࠂΛ࢝ΊΒΕΔαʔϏε w ද޲͖͸XFCαʔϏεͰ͸͋Δ͕ɺཪଆͰׂͱ ΰϦΰϦͱόονॲཧ͕ಈ͍͍ͯΔ IUUQTFDCPPTUFSKQ

  4. ࢲ w ૿ాو࢜ʢ!NBTVUBLBʣ w ੩Ԭݝ඿দࢢग़਎ w ೥݄)FSPLVσϏϡʔ  w ೥݄&$#PPTUFSʹδϣΠ

    ϯɻຊ൪؀ڥ͕)FSPLVͩͬͨ w ೥݄&$#PPTUFSͷ)FSPLV पลΛΠΠײ͡ʹ࢝͠ΊΔ  IUUQTNBTVUBLBOFUDIBMPXIUNM
  5. &$#PPTUFS͸)FSPLVͰ ಈ͍͍ͯ·͢ɻ

  6. %ZOPͷมભ XFC  XPSLFS  BE@XPSLFS  4UBOEBSE9  

    4UBOEBSE9 4UBOEBSE9 1FSGPSNBODF. 4UBOEBSE9  ͢΂ͯ̍୆ 4UBOEBSE9
  7. %ZOP w )FSPLVͰΞϓϦέʔγϣϯΛ࣮ߦ͢ΔͨΊͷܰ ྔίϯςφ w αʔόʔͱ೴಺ஔ׵ͯ͠΋͋ͳ͕ͪؒҧ͍Ͱ ͸ͳ͍ IUUQTKQIFSPLVDPNEZOPT

  8. &$#PPTUFSͷ1SPDpMF release: bin/rails db:migrate db:seed # Web app web: bin/rails

    s -p $PORT -e $RAILS_ENV worker: PROCESS_TYPE=worker bundle exec sidekiq -C config/sidekiq.yml # Ad app ad_worker: PROCESS_TYPE=ad_worker bundle exec sidekiq -C config/sidekiq.yml
  9. 1SPDpMF w %ZOPʹΑ࣮ͬͯߦ͞ΕΔίϚϯυΛఆٛͨ͠ϑΝΠϧ w QSPDFTTUZQFDPNNBOEͱ͍͏TZOUBY w )FSPLVͰ͸XFCͱSFMFBTF͸ಛผͳQSPDFTTUZQF w ଞͷQSPDFTTUZQF͸೚ҙʹ૿΍͢͜ͱ͕ग़དྷΔ w

    ͍ͭ͘·Ͱ૿΍ͤΒΕΔͷͩΖ͏ʁ IUUQTEFWDFOUFSIFSPLVDPNBSUJDMFTQSPDpMF
  10. "EEPOͷมભ )FSPLV 1PTUHSFT   )FSPLV 3FEJT -PHHJOH  .POJUPSJOH

    )PCCZ%FW 1SFNJVN 4UBOEBSE /FX3FMJD )BXLF 1BQFSUSBJM -PH%/"  ϓϥϯ͸ঢ়گʹԠ্ͯ͛͡Լ͛ͨ͠
  11. w ಛච͢΂͖఺͸ͳ͠ w ݄಄ʹ1BQFSUSBJM͕਺೔ఀࢭͨͨ͠Ίɺݟ੾Γ Λ͚ͭͯ-PH%/"  ʹҠߦͨ͘͠Β͍  IUUQTMPHEOBDPN

  12. ࠷ۙ΍ͬͨ͜ͱ w )FSPLVΛ5FSSBGPSNͰ؅ཧͯ͠ɺมߋΛίʔυ ͰදݱͰ͖ΔΑ͏ʹͨ͠ w δϣϒͷεέδϡʔϧ࣮ߦΛIFBMUIDIFDLTJP  Ͱ؂ࢹ͠ɺ5FSSBGPSNͰ΋؅ཧͨ͠ w %PDLFSPO)FSPLV࢖ͬͯ3FEBTIΛཱͯͨ

      IUUQTHJUIVCDPNXJMMOFUSFEBTIPOIFSPLV  IUUQTIFBMUIDIFDLTJP
  13. ՝୊ͷҰ෦ w σϓϩΠ͕΍΍஗͍ʢ෼ڧʣ w CVJMEQBDLΛෳ਺࢖͍ͬͯΔͨΊɻ%PDLFSPO)FSPLVʹ͢Δ͔΋ w 8FCΞϓϦέʔγϣϯͷύϑΥʔϚϯεΛݕ౼͖͠Ε͍ͯͳ͍ w ·ͩͦ͜·Ͱ໰୊Ͱ͸ͳ͍͕ɻϨΠςϯγʔ໰୊ʹߦ͖ண͘ؾ͸ ͢Δ

    w ϝτϦΫε؂ࢹ͕ग़དྷ͍ͯͳ͍ w /FX3FMJD"EEPO͸"1.ͳͷͰํ޲ੑ͕ҧ͏
  14. )FSPLVͷྑ͍ͱ͜Ζ w ΠϯϑϥΛ͋·ΓҙࣝͤͣʹαʔϏεΛ࢝ΊΒΕΔ w ࠓͷͱ͜Ζͱͯ΋҆ఆ͍ͯ͠Δ w ʢͨ·ͨ·ͩͱࢥ͏͕ʣϝϯςφϯε΢Οϯυ΢͕·ͩ dճ͔͠ͳ͍ w "84ͱൺ΂੍ͯ໿͕ଟ͍

    w ݩ૊ΈࠐΈΤϯδχΞͷ݂͕૽͙
  15. )FSPLVͷྑ͘ͳ͍ͱ͜Ζ w %ZOPͷछྨ͕গͳ͍ w ྫ4UBOEBSE9 NP ͷͻͱ্͕ͭ1FSGPSNBODF.  NP 

    w গ͠ͷมߋͰྉ͕ۚάοͱ্͕Δ͜ͱ͕͋Δɻ΋͏গ͠બ୒ࢶ͕ ཉ͍͠ w "EEPOͷྉۚઃఆ͕ಠಛ w %ZOPͷॏΈ͕Ճຯ͞ΕΔ͜ͱ͕͋Δʢྫ1SPDFTT4DIFEVMFS "EEPOʣ
  16. ײ૝ w )FSPLV͸ྑ͍αʔϏε w ࠓͷͱ͜Ζɺεέʔϧ໘Ͱෆ҆͸ͳ͍ɻϨΠς ϯγʔͱɺର֎తͳҙຯͰͷηΩϡϦςΟ͸΍ ΍ෆ҆ w "84΍($1΁ͷҠߦ΋ࢹ໺ʹೖΕͯɺ%PDLFSJ[F ͳͲ΍͍ͬͯ͘

  17. None
  18. )FSPLV%FFQ%JWF !NBTVUBLB

  19. )FSPLV%FFQ%JWF !NBTVUBLB ͪΐͬ͜ͱ

  20. σϓϩΠͷྲྀΕʢͬ͘͟Γʣ  )FSPLV"QQΛ࡞Δʢ࠷ॳͷҰճʣ  HJUQVTI͢Δ  4MVH͕࡞ΒΕΔ  4MVHΛಡΈࠐΈɺ৽ͨͳ%ZOP͕࡞ΒΕΔ IUUQTEFWDFOUFSIFSPLVDPNBSUJDMFTIPXIFSPLVXPSLT

  21. 4MVHͱ͸ʁ w TMVHDPNQJMFSʹΑͬͯɺύοέʔδϯά͞Εͨ ΋ͷ w HJUQVTI͢ΔͱϦϙδτϦ͕ύοέʔδϯά͞ ΕΔɻCVJMEQBDLͳͲ΋ؚΊΒΕΔ w ΞϓϦέʔγϣϯىಈ࣌ʹɺ4MVH͸%ZOPʹμ΢ ϯϩʔυˍల։͞ΕΔ

    IUUQTEFWDFOUFSIFSPLVDPNBSUJDMFTTMVHDPNQJMFS
  22. ͜ͷఔ౓͔͠৘ใ͕ͳ͍ IUUQTEBTICPBSEIFSPLVDPNBQQT\BQQOBNF^TFUUJOHT $ heroku apps:info --json -a {app-name} | jq

    .app.slug_size Ͱ΋αΠζ͕෼͔Δ
  23. ͩͬͨΒɺ

  24. 4MVHΛμ΢ϯϩʔυͯ͠ΈΑ͏ʂ

  25. ͕࣌ؒ͋Ε͹࣮ԋ $ APP_NAME={app-name} $ LATEST_SLUG_ID=$(heroku releases --json -a $APP_NAME |

    jq -r '.[0].slug.id') $ SLUG_URL=$(curl -n https://api.heroku.com/apps/${APP_NAME}/slugs/${LATEST_SLUG_ID} \ -H "Accept: application/vnd.heroku+json; version=3" | jq -r '.blob.url') $ curl -Lo ${LATEST_SLUG_ID}.tar.gz $SLUG_URL IUUQTEFWDFOUFSIFSPLVDPNBSUJDMFTQMBUGPSNBQJSFGFSFODFTMVHJOGP ˞࠷৽ͷϦϦʔεʹඥ෇͍ͨ4MVHΛμ΢ϯϩʔυ
  26. 4MVHUBSCBMMͷ த਎ app ├── .bundle ├── ʢϦϙδτϦ಺ͷϑΝΠϧʣ └── vendor ├──

    bundle │ └ʢলུʣ └── ruby-2.4.4 └── bin ├── erb ├── gem ├── irb ├── rake ├── rdoc ├── ri ├── ruby └── ruby.exe -> ruby IFSPLVSVCZCVJMEQBDL Λ࢖͍ͬͯΔ৔߹ɺ SVCZͦͷ΋ͷ΍WFOEPS CVOEMFͳͲ΋ؚ·Εͯ ͍Δɻ
  27. ʢ͓·͚ʣ 4MVHΛखಈͰ࡞ͬͯϦϦʔεͯ͠ΈΑ͏ʂ

  28. ͕࣌ؒ͋Ε͹࣮ԋ $SFBUJOH4MVHTGSPN4DSBUDI IUUQTEFWDFOUFSIFSPLVDPNBSUJDMFTQMBUGPSNBQJSFGFSFODFTMVHJOGP  SVCZͷCVJMEQBDLΛμ΢ϯϩʔυ͠ల։ɺSVCZTDSJQUΛ௥ ՃɺUBSCBMMʹ͢Δ  4MVH$SFBUF"1*Λୟ͘ͱɺΞοϓϩʔυ༻63-͕ฦͬͯ͘ Δ 

    Ξοϓϩʔυ༻63-ʹUBSCBMMΛΞοϓϩʔυ͢Δ  1045BQQTBQQSFMFBTFT͢Ε͹ɺϦϦʔε׬ྃ
  29. ੍ݶ͸͍Ζ͍Ζ͋Δ w 4MVHαΠζ͸$PNQJMFͯ͠.J#·ͰʢѹॖαΠζʣ w ʹ.J#͔Β.J#ʹ্͕ͬͨ w ʹ.J#͔Β.J#ʹ্͕ͬͨ w 4MVH$PNQJMF࣌ؒ͸෼·Ͱ w

    ϢʔβʹΑΔΞϓϦ΁ͷHJUૢ࡞͸࣌ؒʹճ·Ͱ w ϦϙδτϦαΠζ͸ඇѹॖͰ(#·Ͱ w ͦͷଞ IUUQTEFWDFOUFSIFSPLVDPNBSUJDMFTMJNJUT
  30. ࢼ͠ʹɺ

  31. 4MVHαΠζΛݮΒͯ͠ΈΑ͏ʂ

  32.  4MVHʹؚΊΔϑΝΠϧΛݮΒ͢  IFSPLVSFQPQMVHJOΛ࢖͏

  33. 4MVHʹؚΊΔϑΝΠϧΛݮΒ͢ w HJUϦϙδτϦ͔ΒෆཁͳϑΝΠϧΛ࡟আ͢Δ w 4MVHʹؚΊͨ͘ͳ͍ϑΝΠϧΛTMVHJHOPSFʹॻ ͘ IUUQTEFWDFOUFSIFSPLVDPNBSUJDMFTTMVHDPNQJMFSJHOPSJOHpMFTXJUITMVHJHOPSF

  34. IFSPLVSFQPQMVHJOΛ࢖͏ $ heroku plugins:install heroku-repo $ heroku repo:gc -a {app-name}

    $ heroku repo:purge_cache -a {app-name} $ git commit --allow-empty -m 'Decrease slug size' $ git push heroku master IUUQTHJUIVCDPNIFSPLVIFSPLVSFQP
  35. IFSPLVSFQPHD  (&5IUUQTBQJIFSPLVDPNBQQT\BQQOBNF^CVJME NFUBEBUBͯ͠ɺϦϙδτϦ(&5༻63-Λऔಘ͢ΔɻUBSCBMM͕ ಘΒΕΔ  IFSVLVSVOͯ͠ɺμ΢ϯϩʔυͨ͠ϦϙδτϦʹରͯ͠ɺ HJUHDBHHSFTTJWF͢Δ  UBSCBMMʹݻΊͯɺͰಘΒΕͨ165༻63-ʹ165͢Δ

     ࣍ճͷσϓϩΠͰ͸εϦϜʹͳͬͨHJUϦϙδτϦ͕࢖ΘΕΔ IUUQTHJUIVCDPNIFSPLVIFSPLVSFQPCMPCWDPNNBOETHDKT
  36. IFSPLVSFQPQVSHF@DBDIF  (&5IUUQTBQJIFSPLVDPNBQQT\BQQOBNF^CVJME NFUBEBUBͯ͠ɺΩϟογϡ(&5༻63-Λऔಘ͢ΔɻUBS CBMM͕ಘΒΕΔ  IFSVLVSVOͯ͠ɺμ΢ϯϩʔυͨ͠Ωϟογϡͷ͏ͪɺ WFOEPSIFSPLVҎ֎Λ͢΂ͯ࡟আ͢Δ  UBSCBMMʹݻΊͯɺͰಘΒΕͨ165༻63-ʹ165͢Δ

     ࣍ճͷσϓϩΠͰ͸৽نʹCVOEMFJOTUBMM౳ߦΘΕΔ IUUQTHJUIVCDPNIFSPLVIFSPLVSFQPCMPCWDPNNBOETQVSHF@DBDIFKT
  37. ࢀߟWFOEPSIFSPLVͷத਎ vendor └── heroku ├── buildpack_ruby_version (ruby-2.4.4) ├── buildpack_version (v196)

    ├── bundler_version (1.15.2) ├── ruby_version (ruby 2.4.4p296 (2018-03-28 revision 63013) [x86_64-linux]) ├── rubygems_version (2.6.14.1) ├── secret_key_base ([SECRET]) └── stack (heroku-16) ˞IFSPLVSVCZCVJMEQBDLΛ࢖͍ͬͯΔ৔߹ɻ ׅހ಺͸ϑΝΠϧͷத਎
  38. ࢀߟCVJMENFUBEBUB"1*ͷ ϨεϙϯεʢQSJWBUF"1* ʣ $ curl -n https://api.heroku.com/apps/github-organization-watcher/build-metadata \ -H "Accept:

    application/vnd.heroku+json; version=3.build-metadata" { "app":{ "id":"<UUID>", "name":"github-organization-watcher" }, "cache_delete_url":"<CACHE_URL>", "cache_get_url":"<CACHE_URL>", "cache_put_url":"<CACHE_URL>", "repo_delete_url":"<REPO_URL>", "repo_get_url":"<REPO_URL>", "repo_put_url":"<REPO_URL>" } # <CACHE_URL> # https://s3-external-1.amazonaws.com/heroku_repos/heroku.com/cache/<NUMBERS>.tgz? AWSAccessKeyId=<SECRET>&Signature=<SECRET>&Expires=<NUMBERS> # <REPO_URL> # https://s3-external-1.amazonaws.com/heroku_repos/heroku.com/<NUMBERS>.tgz? AWSAccessKeyId=<SECRET>&Signature=<SECRET>&Expires=<NUMBERS>
  39. ෼͔ͬͨ͜ͱ w IFSPLVSFQPHD͸ϦϙδτϦαΠζ͕ݮΔͩ ͚ɻσϓϩΠ͸ଟগ଎͘ͳΔͱࢥ͏͕ɺ4MVHα Πζ͸ݮΒͳ͍ w IFSPLVSFQPQVSHF@DBDIF͕4MVHαΠζΛݮ Β͢

  40. ͞Βʹ෼͔ͬͨ͜ͱ w 4MVHͷUBSCBMM͸4ͷIFSPLVTMVHTVTόέοτʹ͋Δ Α͏ͩ w ϦϙδτϦͷUBSCBMM͸4ͷIFSPLV@SFQPTόέοτͷ IFSPLVDPNҎԼʹ͋ΔΑ͏ͩ w ΩϟογϡͷUBSCBMM͸4ͷIFSPLV@SFQPTόέοτͷ DBDIFҎԼʹ͋ΔΑ͏ͩ

    ˞)FSPLVͷ3FHJPO͕VTͷ৔߹ɻ4ͷ3FHJPO͸͢΂ͯ7JSHJOJB T FYUFSOBM ͩͬͨ
  41. σϓϩΠͷྲྀΕʢ࠶ܝʣ  )FSPLV"QQΛ࡞Δʢ࠷ॳͷҰճʣ  HJUQVTI͢Δ  4MVH͕࡞ΒΕΔ  4MVHΛಡΈࠐΈɺ৽ͨͳ%ZOP͕࡞ΒΕΔ IUUQTEFWDFOUFSIFSPLVDPNBSUJDMFTIPXIFSPLVXPSLT

  42. σϓϩΠͷྲྀΕʢ࠶ܝʣ  )FSPLV"QQΛ࡞Δʢ࠷ॳͷҰճʣ  HJUQVTI͢Δ  4MVH͕࡞ΒΕΔ  4MVHΛಡΈࠐΈɺ৽ͨͳ%ZOP͕࡞ΒΕΔ IUUQTEFWDFOUFSIFSPLVDPNBSUJDMFTIPXIFSPLVXPSLT

  43. 4MVH UH[ ϦϙδτϦ UH[ Ωϟογϡ UH[ HJUQVTI 4MVHDPNQJMFS (JUϦϙδτϦ #VJMEQBDL

    T ૝૾ਤ
  44. ײ૝ w )FSPLV͸ྑ͍αʔϏεʢೋճ໨ʣ w 4MVH΍CVJMENFUBEBUB͔Β૝૾Λૡཱ͖ͯΒΕ Δ w ۀ຿ͰαʔϏεΛ࡞Δͱ͖ɺ·ͣ͸)FSPLVͰ࡞ ΕΔ͔ߟ͑Δͱྑ͍ͱࢥͬͨ

  45. ࡶײ w ࠓճ͸ʮۀ຿Ͱಘͨ஌ࣝ ЋʯΛ࢖ͬͯൃද͢ Δ͜ͱ͕ग़དྷͨ w ձ͕ࣾ৽͍ٕ͠ज़ΛࣗવͱֶशͰ͖Δ৔Ͱ͋Δ ͱɺ݈શͩͱࢥͬͨ w ൃදͷ৔Ͱʮݸਓͷֶशʯͱʮۀ຿Ͱಘͨ஌ࣝʯ

    Λબ୒Ͱ͖Δͱྑ͍
  46. ৘ใऩू w IUUQTEFWDFOUFSIFSPLVDPNDBUFHPSJFTIFSPLVBSDIJUFDUVSF w Ұ࣍৘ใɻॆ࣮͓ͯ͠ΓಡΈ΍͍͢ w IUUQTCMPHIFSPLVDPN IUUQTEFWDFOUFSIFSPLVDPNDIBOHFMPH w )FSPLVͷ࠷৽৘ใ

    w IUUQCIBUFOBOFKQTFBSDIUBH R)FSPLVTBGFPOTPSUSFDFOUVTFST w ΧδϡΞϧͳ৘ใ w )FSPLV+14MBDL6TFS(SPVQ w ࠷ۙ4JHO6Qͨ͠
  47. ͓ΘΓ