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

ChatWorkとPHPと私

tan-yuki
October 08, 2017

 ChatWorkとPHPと私

PHPConference 2017
ChatWork株式会社 田中佑樹

tan-yuki

October 08, 2017
Tweet

More Decks by tan-yuki

Other Decks in Technology

Transcript

  1. © ChatWork ✔ Java ✔ JavaScript ✔ PHP ɹScala ✔

    Vim ాத༎थ ChatWorkגࣜձࣾ ɹɹtan-yuki ɹɹtan_yuki ɹ৽ׁग़਎ ɹChatWork͔Ε͜Ε5೥໨ ɹೣ͕1ඖ
  2. © ChatWork ͜ͷεϥΠυͷ໨త ▸ ͜Μͳਓͨͪʹฉ͍ͯ΋Β͍͍ͨ ▸ ϨΨγʔ͔Β୤٫͍ͨ͠ͱࢥ͍ͬͯΔ ▸ ֦େͭͭ͋͠Δاۀɾ૊৫ ▸

    ͜Μͳ͜ͱ͕Θ͔Δ ▸ ϨΨγʔ୤٫ͷͨΊͷઓུͷҰྫ ▸ ϨΨγʔ୤٫Λ௅ઓͨ͠ਓͨͪͷྺ࢙
  3. © ChatWork νϟοτϫʔΫ͕Ͱ͖Δ·Ͱ ▸ 2010೥ ▸ ࣾ಺πʔϧͱͯ͠ͷνϟοτϫʔΫΛ։ൃ ▸ Skypeͷෆຬͩͬͨ෦෼Λվྑ ▸

    ͨ·ͨ·UstreamͰެ։ͨ͠ͱ͜Ζɺେ൓ڹʂ ▸ 2011೥ ▸ ਖ਼ࣜͳϓϩμΫτͱͯ͠ϩʔϯν͢Δ
  4. © ChatWork ੵΈॏͳ͍ٕͬͯ͘ज़తෛ࠴ ▸ ͱʹ͔͘εϐʔυॏࢹ ▸ ։ൃɺ։ൃɺ։ൃɾɾɾ ▸ ޙΖΛৼΓฦΒͳ͍ ▸

    ਓһ૿Ճ ▸ ૿͑ଓ͚Δ҉໧஌ ▸ ࢲ͸͜͜Β΁ΜͰೖࣾʢ2013೥4݄ʣ ▸ Ҏલ͔Β࢖༻͍ͯͨ͠ಠࣗϑϨʔϜϫʔΫΛݩʹ։ൃΛ͢͢ΊΔ
  5. © ChatWork ಠࣗϑϨʔϜϫʔΫ ▸ ECFʢEC Frameworkʣ ▸ ࣾ಺ͷಠࣗϑϨʔϜϫʔΫʢPHP4ϕʔεʣ ▸ ಈతͳWebϖʔδΛαΫοͱ࡞Δ͜ͱΛ໨తͱ͍ͯ͠Δ

    ▸ શ෦ೖΓɺAll in OneͳϑϨʔϜϫʔΫ ▸ Smarty template, QueryBuilder, Validator, scaffolding, Form ▸ TestFramework, Mail, i18n, ….
  6. © ChatWork ChatWork on ECF ▸ EC studioͷ੡඼͸͢΂ͯECFͰ࡞ΒΕ͍ͯͨ ▸ νϟοτϫʔΫ΋ྫ֎Ͱ͸ͳ͍

    ▸ ECF͸؆୯ͳಈతϖʔδΛ࡞ΔͨΊʹಛԽ͠ ͨϑϨʔϜϫʔΫ ▸ Ajaxલఏͷνϟοτπʔϧͷ૝ఆͳΜͯͳ͍
  7. ։ൃ؀ڥ MAMP Vagrant, Ansible ϦϦʔε खಈσϓϩΠ (SFTP) Jenkins όʔδϣϯ؅ཧ SVN

    Git, Github CI - TravisCI ϨϏϡʔख๏ ௚઀આ໌ PullRequestϕʔε © ChatWork ։ൃͷঢ়گʢ2014೥ࠒʣ
  8. © ChatWork Internet GAE (Comet) ▸ εέʔϧ͠ʹ͍͘ઃܭ ▸ ݻఆ୆਺αʔόʔ ▸

    ΄ͱΜͲશͯͷ͜ͱΛWebαʔόʔͰ ಉظతʹॲཧ͍ͯ͠Δ ▸ ϑΝΠϧΞ οϓϩʔυ͕WebαʔόʔΛ ܦ༝ͯ͠S3΁Ξοϓϩʔυ͍ͯ͠Δ ໰୊఺ Tokyo S3 RDS(MySQL) ELB EC2 EC2 (groonga) 1 2 3 1 2 3
  9. © ChatWork Internet Tokyo ߏ੒ਤ ʢରࡦޙʣ GAE (Comet) BigQuery (API

    Logs) 2 Auto Scaling EC2 (Web Server) ElastiCache (Session) DynamoDB (Flags) S3 (Logs) RDS(MySQL) S3 Direct Upload / Download ELB CloudSearch Index EC2 (Worker) Get SQS
 (Task Queue) Push Glacier 2 3 1
  10. © ChatWork ScalaΛબఆ ▸ ڠٞͷ݁ՌɺScalaΛ࠾༻͢Δ͜ͱΛܾఆ ▸ େن໛PJ։ൃͰͷ੩తܕ෇͚ͷԸܙΛड͚͍ͨ ▸ ٕज़೉қ౓తʹ΋ͦ͜·Ͱϋʔυϧ͕ߴ͍΋ͷͰ͸ͳ͍ ▸

    ͸͡ΊͯScalaΛ৮ͬͨਓͰ΋ʮΘΓͱ͍͚Δʯͱ͍͏ධՁ ▸ ؔ਺ܕͬΆ͘։ൃ͢Δ͔ɺΦϒδΣΫτࢦ޲ͬΆ͘։ൃ͢Δ͔͸ࣗ༝
  11. © ChatWork ϦϓϨΠεͷൣғ ▸ ݱߦAPIΛScalaʹஔ͖׵͑Δ͜ͱΛ໨ඪͱ͢Δ ▸ νϟοτϫʔΫʹؔΘΔશػೳ͕ϦϓϨΠεର৅ ▸ طଘͷAPIͱฒߦͯ͠ӡ༻͢Δ͜ͱΛ૝ఆ ▸

    ֤ΫϥΠΞϯτ͸޷͖ͳλΠϛϯάͰ৽API΁Ҡߦ͢Δ ▸ APIͷIO΋େ͖͘มΘΔͷͰɺ͜ͷλΠϛϯάͰΫϥΠΞϯτଆ΋େ͖͘ ࡮৽
  12. © ChatWork ϦϓϨΠε vs ϦϑΝΫλϦϯά ▸ ଟ͘ͷ৔߹͸ϦϑΝΫλϦϯάΛଓ͚Δ΄͏͕ྑ͍ ▸ ͦͷϨΨγʔίʔυʹ͸ɺ͍ͭ͘΋ͷվળͷ݁Ռ͕٧Ίࠐ·Ε͍ͯΔ ▸

    ͦͷϨΨγʔίʔυʹ͸ɺ͋ͳͨͷ஌Βͳ͍Α͏ͳػೳ͕Ӆ͞Ε͍ͯΔ ▸ ϦϓϨΠε͢Δʹ͸ɺ͋·Γʹଟ͘ͷ͕͔͔࣌ؒΔ
  13. © ChatWork ϦϓϨΠε vs ϦϑΝΫλϦϯά ▸ ҎԼͷ৔߹͸ϦϓϨΠε͕͍͍͔΋͠Εͳ͍ ▸ ϦϓϨΠεର৅͕খ͍͞ɺ͋Δ͍͸খ͘͞Ͱ͖Δ ▸

    σʔλઃܭ౳ɺࠜຊతͳͱ͜Ζʹ໰୊͕͋Δ ▸ ϦϓϨΠε͢Δ৔߹΋ग़དྷΔݶΓہॴతʹ͢Δ΄͏͕Α͍
  14. © ChatWork ࠓޙͷChatWork͸Ͳ͏͍͔ͯ͘͠ ▸ ෦෼తʹϦϓϨΠε͍ͯ͘͠ ▸ ͨͱ͑͹ɺAPIͷΤϯυϙΠϯτ୯Ґ౳ ▸ ϚΠΫϩαʔϏεԽ΋Ұͭͷखஈ ▸

    σʔλઃܭతʹແཧͳՕॴɺେྔͷσʔλΛѻ͏ՕॴʢAkka/Actor͕ಘ ҙͳ෦෼ʣ ▸ ͨͩ͠ɺશͯΛϦϓϨΠε͠ͳ͍ɺPHPͱ΋௕͍͓෇͖߹͍Λ͍ͯ͘͠ ▸ ݱࡏPHPόʔδϣϯΞοϓΛݕ౼தʢݱঢ়5.6ʣ
  15. © ChatWork εϧʔϓοτൺֱ ▸ abʹΑΔ؆୯ͳϕϯνϚʔΫ ▸ ҎԼ͸ϩάΠϯॲཧͷ଎౓ൺֱ runtime -c 10

    -c 50 -c 100 php 5.6 19.27 req / s 18.78 req / s 19.74 req / s php 7.1 151.44 req / s 161.81 req / s 161.20 req / s hhvm 3.15 143.16 req / s 161.31 req / s 162.61 req / s ▸ େ͖ͳҧ͍͸ͳͦ͞͏
  16. © ChatWork ϝϞϦ࢖༻ྔൺֱ ▸ Լهؔ਺Λ༻͍ͯ࢖༻ྔൺֱ ▸ memory_get_peak_usage — PHP ʹΑׂͬͯΓ౰ͯΒΕͨϝϞϦͷ࠷

    େ஋Λฦ͢ ▸ ୈҰҾ਺ʹtrueΛࢦఆͯ͠ܭଌɻҧ͍͸ҎԼɻ ࢀߟʣhttp://php.net/manual/ja/function.memory-get-peak-usage.php ͜ΕΛ TRUE ʹઃఆ͢ΔͱɺγεςϜׂ͕Γ౰࣮ͯͨࡍͷϝϞϦͷେ͖͞Λऔಘ͠·͢ɻ লུͨ͠Γ FALSEΛઃఆͨ͠Γ͢Δͱɺ emalloc() ͕࢖༻͢ΔϝϞϦͷΈΛใࠂ͠·͢ɻ
  17. © ChatWork runtime API A API B API C php

    5.6 9,961,472 12,582,912 17,039,360 php 7.1 2,097,152 2,097,152 4,194,304 hhvm 3.15 396,328 427,544 889,568 ϝϞϦ࢖༻ྔൺֱ ▸ 3छྨͷAPIͰͦΕͧΕܭଌ ▸ HHVM͕ܶతʹΑ͘ݟ͑Δ͕ɺPHPͱHHVM͸ಈ࡞Ϟσϧ͕ҟͳΔͨΊɺ औಘͰ͖Δ஋͕ҟͳΔ ▸ Ϛϧνϓϩηεͱγϯάϧϓϩηε+ϚϧνεϨου ࢀߟʣhttps://github.com/facebook/hhvm/issues/2257
  18. © ChatWork ݴޠػೳൺֱ ▸ HHVM (Hack) ▸ Generics, Nullable, Collections,

    Lambda, Tuple, … ▸ ϚϧνεϨουʹΑΔඇಉظॲཧ ▸ PHP7 ▸ TypeHinting͕௥Ճ ▸ Hackͷ΋ͷͱൺֱ͢Δͱऑ͍͔
  19. © ChatWork ChatWork with PHP7 ▸ ChatWork͸PHP7Λબ୒ ▸ ੑೳࠩʹ͍ͭͯ͸େ͖ͳҧ͍͸ͳͦ͞͏ ▸

    PHPίϛϡχςΟͷେ͖͞΍ɺࠓޙͷ֤ϥΠϒϥϦͷαϙʔτঢ়گΛצ Ҋ͠PHP7ΛબΜͩ ▸ HHVM͸৽͍͠ϥϯλΠϜͷͨΊɺֶशίετ΍Πϯϑϥͷ੔උ౳ɺଟগ ͷίετ͸͔͔Δ ▸ PHP7ͷTypeHintingͰ΋ɺݱঢ়ͱൺ΂Ε͹े෼ڧྗ