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

PHP8版!Swooleのフレームワークを比べてみた

 PHP8版!Swooleのフレームワークを比べてみた

PHPerKaigi2021の発表資料です

PHPerKaigi2019でお話しした内容( https://fortee.jp/phperkaigi-2019/proposal/61b5c154-7b53-4d78-820a-cf328f6d3360 )を
PHP8の環境で、再度検証してみた話をお伝えします
さらに、Swooleを用いたフレームワークでもっともGitHubの更新頻度が高い
Hyperfを加えて、4種類のフレームワークをくらべてみます
そもそも、PHP8のJITはどれだけSwooleに有利に働くのでしょうか?
PHP8の環境における、No.1 Swooleフレームワークはどれだ!

Ec2fcdc4ea7905b289967a2c4c43e154?s=128

CyberAgent SGE Engineer

March 27, 2021
Tweet

Transcript

  1. 1)1൛ʂ 4XPPMFͷϑϨʔϜϫʔΫΛ ൺ΂ͯΈͨ גࣜձࣾαΠόʔΤʔδΣϯτ നҪӳ  QIQFSLBJHJ !HPPEPP

  2. • גࣜձࣾαΠόʔΤʔδΣϯτ • 4(&౷ׅຊ෦ٕज़౷ׅࣨࣨ௕ • ࢠձࣾࣾ$50 • גࣜձࣾ$SBGU&HH • גࣜձࣾαϜβοϓ

    • നҪɹӳ • ΤϯδχΞ • #MPH IUUQBNFCMPKQHPPEPP ͓લɺ୭Α • 5XJUUFS !HPPEPP • %2 ͙ͪ͢Ή '#  
 ϓΫϦϙ ཱྀܳਓ
  3. "HFOEB w4XPPMFͱ͸ w4XPPMFΛ༻͍ͨϑϨʔϜϫʔΫ wࠓճ͓࿩͢ΔϑϨʔϜϫʔΫΛ 
 ਂ۷Γ wϕϯνϚʔΫ݁Ռ w·ͱΊ

  4. 4XPPMFͱ͸

  5. 1)1ͰΠϕϯτۦಈͷඇಉظ ˍίϧʔνϯϕʔεͷฒߦॲཧ

  6. 1)1ͷFYUFOTJPOͱͯ͠ ಋೖ͠·͢ # pecl install swoole

  7. 4XPPMFΛ༻͍ͨ ϑϨʔϜϫʔΫ

  8. 4XPPMFΛ༻͍ͨ ϑϨʔϜϫʔΫ͸ ͍͔ͭ͋͘Γ·͢ ެࣜαΠτΛݟͯΈ·͠ΐ͏

  9. 4XPPMFͷ(JU)VCͷ3&"%.&Ͱ঺հ͞Εͯ ͍ΔϑϨʔϜϫʔΫͷIJTUPSZΛΈͯΈ·͢ https://github.com/swoole/swoole-src ࣌఺

  10. 4XPPMFͷ(JU)VCͷ3&"%.&Ͱ঺հ͞Εͯ ͍ΔϑϨʔϜϫʔΫ https://github.com/swoole/swoole-src ʢ̍ʣ࠷ॳظߋ৽ 4XPGUͷ௥Ճ

  11. 4XPPMFͷ(JU)VCͷ3&"%.&Ͱ঺հ͞Εͯ ͍ΔϑϨʔϜϫʔΫ https://github.com/swoole/swoole-src ʢ̎ʣͦͷ̎ߋ৽ &BTZ4XPPMFͷ௥Ճ

  12. 4XPPMFͷ(JU)VCͷ3&"%.&Ͱ঺հ͞Εͯ ͍ΔϑϨʔϜϫʔΫ https://github.com/swoole/swoole-src ʢ̏ʣͦͷ̏ߋ৽ 4BCFSͷ௥Ճ

  13. 4XPPMFͷ(JU)VCͷ3&"%.&Ͱ঺հ͞Εͯ ͍ΔϑϨʔϜϫʔΫ https://github.com/swoole/swoole-src ʢ̐ʣͦͷ̐ߋ৽ )ZQFSGͷ௥ՃʢҰ൪্ʹʣ

  14. 4XPPMFͷ(JU)VCͷ3&"%.&Ͱ঺հ͞Εͯ ͍ΔϑϨʔϜϫʔΫ https://github.com/swoole/swoole-src ʢ̑ʣͦͷ̑ߋ৽ .JY1)1ͷ௥Ճ

  15. 4XPPMFͷ(JU)VCͷ3&"%.&Ͱ঺հ͞Εͯ ͍ΔϑϨʔϜϫʔΫ https://github.com/swoole/swoole-src ʢ̒ʣͦͷ̒ߋ৽ JNJͷ௥Ճ

  16. 4XPPMFͷ(JU)VCͷ3&"%.&Ͱ঺հ͞Εͯ ͍ΔϑϨʔϜϫʔΫ https://github.com/swoole/swoole-src ʢ̓ʣݱࡏߋ৽ 0OFͷ௥Ճ

  17. 4XPPMFͷ(JU)VCͷ3&"%.&Ͱ঺հ͞Εͯ ͍ΔϑϨʔϜϫʔΫ https://github.com/swoole/swoole-src ʢ̓ʣݱࡏߋ৽

  18. ࠓճऔΓ্͛Δ ϑϨʔϜϫʔΫΛ ؆୯ʹ͝঺հ

  19. )ZQFS )ZQFSTQFFE 'MFYJCJMJUZ)ZQFSG ໊͕લͷ༝དྷ ϚΠΫϩαʔϏεΛҙࣝͨ͠ϑϨʔϜϫʔΫ εϐʔυͱॊೈੑΛ௥ٻʂ 4XPPMFͷ(JU)VCͰ͸ɺϑϨʔϜϫʔΫͷ঺հͷதͰ Ұ൪্ʹ঺հ͞Ε͓ͯΓɺίϛοτ਺΋࠷΋ଟ͍

  20. 4XPGU ϞμϯͰɺߴੑೳͰ "01ͱ$PSPVUJOFΛ උ͑ͨϑϨʔϜϫʔΫ 1)1$PO4FOEBJͷ-5Ͱ ࿩͠·ͨ͠ https://speakerdeck.com/sgeengineer/swoolewotukatutahuremuwakuswoftwotafalsesimu ϞμϯͳϑϨʔϜϫʔΫͳΒɺͪ͜Β

  21. &BTZTXPPMF ؆୯ʹ4XPPMFΛࢼ͢ͷͳΒɺͪ͜Β https://speakerdeck.com/sgeengineer/isucon8deyu-xuan-luo-tisitafalsede-swoole-easyswoole-deshu-kihuan-ete-gan-xiang-zhan-debentizou-rasetemitahua 1)1$POGFSFODFͷ -5Ͱ࿩͠·ͨ͠ɾɾɾ

  22. 4XPPMFͷ(JU)VCͰ঺հ͞Ε͸͞Ε͍ͯͳ͍ Ͱ͕͢ɺݸਓతʹ஫໨͍ͯ͠ΔϑϨʔϜϫʔΫ

  23. ͜ͷηογϣϯΛࢹௌ͞Ε͍ͯΔօ͞ΜͳΒ Ί΋Γʔ͞Μͷൃද΋ฉ͍ͯΔͱࢥ͏ͷͰ ৄ͘͠͸ͦͪΒͰʂ ʢࣗ෼΋ΊͬͪΌڵຯ͋Δʣ

  24. ࠓճ͓࿩͢Δ ϑϨʔϜϫʔΫ Λগ͠ਂ۷Γ

  25. w)ZQFSG W  w&BTZ4XPPMF W  w4XPGU W  w-BSBWFM4XPPMF

    W
  26. ؓ࿩ٳ୊

  27. 4XPPMFͷ 1)1ͱ+*5ͷରԠঢ়گ͸ Ͳ͏ͳͷ͔ʁ

  28. 4XPPMFͷهड़ 1)1Ҏ্Ͱ ίϯύΠϧՄೳ

  29. 4XPPMF͸ 1)1ͷ؀ڥͰQFDMͰ ΠϯετʔϧͰ͖ͨ

  30. શવ໰୊ͳ͍͚͘Δ͡ΌΜ ͱࢥͬͨࣗ෼͕͍·ͨ͠

  31. +*5͕ɾɾɾɾɾɾ https://github.com/swoole/swoole-src/issues/3986

  32. +*5͕ɾɾɾɾɾɾ

  33. ࠓճͷ؀ڥΛ࡞Δͱ͖ʹ 1)1 4XPPMF ͷ૊Έ߹ΘͤΛ બΜͰ͠·ͬͨͨΊ ΊͬͪΌযΓ·ͨ͠

  34. ࠓ͸ղܾ͞Ε͍ͯ·͢ 1)1YܥͰ͸ 4XPPMFҎ্Λ ͓࢖͍͍ͩ͘͞

  35. ؓ࿩ٳ୊ऴΘΓ

  36. w)ZQFSG W  w&BTZ4XPPMF W  w4XPGU W  w-BSBWFM4XPPMF

    W
  37.  )ZQFSG  )ZQFSG https://github.com/hyperf/hyperf

  38. ϕʔεͷΞʔΩςΫνϟ  )ZQFSG •Coroutin e •Dependency injectio n •Event s

    •Annotatio n •AOP(asset-oriented programming
  39. ϦϦʔεܭը͕͔ͬ͠Γͯ͠Δʂ  )ZQFSG https://hyperf.wiki/2.1/#/en/release-planning

  40. )ZQFSGͷϑΥϧμߏ੒ ࠷খݶ Projec t ! appɹɹɹɹɹɹɹɹ "ɹ! Controller s "ɹ"ɹ!

    AbstractController.ph p "ɹ"ɹ# BooksController.ph p "ɹ! Model s "ɹ"ɹ# Books.ph p "ɹ! Exceptio n "ɹ# Listene r ! confi g "ɹ! config.ph p "ɹ# routes.ph p ! publi c ! runtim e "ɹ! log s "ɹ! containe r "ɹ# sessio n ! storag e "ɹ# view s "ɹɹɹ# index.twi g # bi n ɹɹ# hyperf.ph p  )ZQFSG
  41. ίϯτϩʔϥʔ  )ZQFSG

  42. ίϯτϩʔϥʔ  )ZQFSG w 63-ͷϚοϐϯάɺϝιουࢦఆΛ BOOPUBUJPOͰઃఆ w .JEEMFXBSFͷݺͼग़͠Λ BOOPUBUJPOͰઃఆ

  43.  )ZQFSG 7JFX DPO fi H

  44.  )ZQFSG 7JFX DPO fi H w 5FNQMBUFΤϯδϯͷࢦఆ 
 #MBEF

    4NBSUZͳͲʹ΋ରԠ
  45.  )ZQFSG 7JFX DPO fi H w 7JFXͷϨϯμϦϯάΛ 5BTL8PSLFSʹͤ͞Δ 


    ผϓϩηεͱͳΔ
  46. ਵॴʹ)ZQFS4QFFE Λҙࣝͨ͠࡞ΓࠐΈʂ  )ZQFSG

  47.  4XPGU  4XPGU http://swoft.io/

  48. • Built-in high performance network server(Http/Websocket/RPC/TCP ) • Flexible componentizatio

    n • Flexible annotation functio n • Diversi fi ed command terminal(Console ) • Powerful Aspect Oriented ProgrammingʢAOPʣ • Perfect Container management, Dependency Injection (DI ) • Flexible event mechanis m • Implementation of HTTP message based on PSR- 7 • Event Manager Based on PSR-1 4 • Middleware based on PSR-1 5 • Internationalization(i18n) suppor t • Simple and ef fi cient parameter validato r •High performance connection pool(Mysql/Redis/RPC)ɼAutomatic reconnectio n •Database is highly compatible Larave l •Cache Redis highly compatible Larave l •Ef fi cient task processin g •Ef fi cient seconds cronta b •Process poo l •Flexible exception handlin g •Powerful log syste m •Service registration & discover y •Service breake r •Service restriction s •Service fallbac k •Con fi guration Cente r •Apoll o •Consul https://github.com/swoft-cloud/swoft ͷREADME Ҿ༻ɿ  4XPGU
  49. •Built-in high performance network serve r •Flexible annotation functio n

    •Powerful Aspect Oriented ProgrammingʢAOPʣ •Perfect Container management, Dependency Injection (DI ) •Implementation of HTTP message based on PSR- 7 •Middleware based on PSR-1 5 •High performance connection pool(Mysql/Redis/RPC)ɼ Automatic reconnectio n •Database is highly compatible Larave l •Cache Redis highly compatible Larave l ಛ௃  4XPGU
  50. 4XPGUͷϑΥϧμߏ੒ ࠷খݶ Projec t ! appɹɹɹɹɹɹɹɹ "ɹ! Controller s "ɹ"ɹ#

    BooksController.ph p "ɹ! Model s "ɹ"ɹ# Entit y "ɹ"ɹ # Books.php "ɹ# bean.ph p ! publi c ! runtim e "ɹ! log s "ɹ! cache s "ɹ# session s ! resource s "ɹ# view s "ɹɹɹ# book s "ɹɹɹɹɹ# view.ph p # bi n ɹɹ! bootstrap.ph p ɹɹ# swoft  4XPGU
  51. w "OOPUBUJPOͷॻ͕ࣜҰ෦มΘͬͨ 
 3FRVFTU.BQQJOHͷNFUIPEͷࢦఆ  w %#Ϋϥεͷվળ 
 4XPGUa%Ca%# 

    w 4FTTJPOΫϥεͷվળ 
 4XPGUa)UUQa4FTTJPOa)UUQ4FTTJPO  4XPGU Wͷؾ͍ͮͨมߋ఺
  52. Ұ௨Γἧ͍ͬͯΔ ϑϧελοΫ ϑϨʔϜϫʔΫ  4XPGU

  53.  &BTZ4XPPMF  &BTZ4XPPMF https://github.com/easy-swoole/easyswoole

  54. ಛ௃  &BTZ4XPPMF •Built-in HTTP, TCP, WebSocket,Udp Coroutine Serve r

    •Global dependency injection containe r •PSR-7 based HTTP message implementatio n •RESTful supporte d •HTTP,TCP, WebSocket, Udp middleware suppor t •Mysql, Redis, RPC, HTTP Coroutine Client s •High performance route r •Universal connection pool s •Remote Console support W
  55. &BTZ4XPPMFͷϑΥϧμߏ੒ ࠷খݶ Projec t ! Appɹɹɹɹɹɹɹɹ "ɹ! HttpControlle r "ɹ"ɹ!

    BooksController.ph p "ɹ"ɹ# Router.ph p "ɹ! Mode l "ɹ"ɹ# BookModel.ph p "ɹ# Utilit y "ɹɹɹ# Poo l "ɹɹɹɹɹ# MysqlObject.ph p ! EasySwooleEvent.ph p ! View s "ɹ# index.twi g ! Lo g ! Tem p ! vendo r ! Stati c "ɹ! cs s "ɹ# j s ! easyswool e ! produce.ph p # dev.php  &BTZ4XPPMF
  56. w ίωΫγϣϯϓʔϧͷ࢓૊Έ͕গ͠վળ͞Εͨ 
 ઐ༻ͷΫϥε͕ඪ४ʹ &BTZ4XPPMFa1PPMa.BOBHFS  w 4FTTJPOΛѻ͏Ϋϥεͷվળ 
 &BTZ4XPPMFa4FTTJPOa4FTTJPO

     w $PO fi Hͷॻࣜ΋গ͠มߋ 
 5BTL8PSLFSͷ߲໨͕ಠཱ  &BTZ4XPPMF Wͷؾ͍ͮͨվળ఺
  57. ΘΓͱૉ௚ʹѻ͑Δ ϑϨʔϜϫʔΫ  &BTZ4XPPMF

  58.  -BSBWFM4XPPMF  -BSBWFM4XPPMF https://github.com/swooletw/laravel-swoole

  59. ಛ௃ -BSBWFMͷ ΞϓϦέʔγϣϯ͕ 4XPPMFͰಈ͘  -BSBWFM4XPPMF

  60. -BSBWFM UP -BSBWFM4XPPMF  -BSBWFM4XPPMF

  61.  DPNQPTFSʹ௥Ճ  -BSBWFM4XPPMF  DPO fi Hͷ1SPWJEFS௥Ճ

  62.  4XPPMF༻ͷDPO fi Hੜ੒  -BSBWFM4XPPMF $ php artisan vendor:publish

    --tag=laravel-swoole  DPO fi HTXPPMF@IUUQQIQΛઃఆ
  63.  ىಈ  -BSBWFM4XPPMF $ php artisan swoole:http start ॳظઃఆͩͱ൪ϙʔτͰ଴ͪड͚·͢

     OHJOYͷઃఆ proxy_pass http://127.0.0.1:1215 QSPYZ@QBTTͰઃఆ͠·͢ https://github.com/swooletw/laravel-swoole/wiki
  64. -BSBWFMͰॻ͍ͨ ΞϓϦέʔγϣϯ͕ ΄Μͱ͏ʹͦͷ·· 4XPPMFͰಈ͘ʂ  -BSBWFM4XPPMF

  65. ϕϯνϚʔΫ ݁Ռ

  66. *46$0/ ϕϯνϚʔΫ݁Ռ ൺֱ

  67. *46$0/ͷ͓୊ 8FCαΠτͷ࢓༷

  68. νέοτ༧໿αΠτ

  69. ϩάΠϯ͕͋Γɺηογϣϯ؅ཧඞཁ

  70. ੮༧໿ͷτϥϯβΫγϣϯ੍ޚ͋Γ

  71. ؅ཧը໘Ͱ$47μ΢ϯϩʔυ΋͋Δ

  72. ຊ൪ͱಉ͡؀ڥ͸ ༻ҙͰ͖ͳ͔ͬͨͷͰ ($1্Ͱଌͬͨ ݁ՌͰ͢ n2-highcpu-2ʢvCPU x 2ɺϝϞϦ 2 GBʣ

  73. ߏ੒ 4MJNɺ-BSBWFM ߏ੒ )ZCFSG &BTZ4XPPMF 4XPGU -BSBWFM4XPPMF h2o php-fpm MySQL

    h2o Swoole MySQL ୆ ୆
  74. ࠓճ͸࣍ͷͭͷ؀ڥΛൺֱ w 1)1 01DBDIF w 1)1 01DBDIF w 1)1 01DBDIF

    +*5
  75. ಥવͷؓ࿩ٳ୊ ճ໨ʣ

  76. ͦΕͧΕͷϑϨʔϜ ϫʔΫͬͯ1)1ʹ ରԠ͍ͯ͠Δͷʁ

  77. )ZQFSGͷDPNQPTFSKTPO

  78. ͍͚ΔΜ͡ΌͶ

  79. ൵͍͠ݱ࣮

  80. ൵͍͠ݱ࣮ %*͕ґଘ͍ͯ͠ΔϞδϡʔϧ ͕1)1ʹରԠ͍ͯ͠ͳ͍

  81. ࢑ఆରԠ 1)1Ͱಈ͍ͨιʔεΛ ͦͷ··ίϐʔͯ͠ DPNQPTFSJOTUBMMΛར༻͠ͳ͍  ແཧ໼ཧ࣮ߦ ʢҰԠಈ͍ͨ

  82. MBSBWFMTXPPMFͷDPNQPTFSKTPO

  83. ͩΊ͡ΌΜ

  84. ࢑ఆରԠ ࠶ͼ 1)1Ͱಈ͍ͨιʔεΛ ͦͷ··ίϐʔͯ͠ DPNQPTFSJOTUBMMΛར༻͠ͳ͍  ແཧ໼ཧ࣮ߦ ʢҰԠಈ͍ͨ

  85. &BTZ4XPPMF W ͱ 4XPGU W  ͸0,Ͱͨ͠

  86. ؓ࿩ٳ୊ऴΘΓ

  87. ͓଴͔ͪͶͷ ൺֱ݁Ռ

  88. ͦΕͧἘճܭଌͯ͠ ࠷େ஋ɺ࠷খ஋Λআ͍ ͨ̑ճͷฏۉ஋Ͱൺֱ ϩδοΫมߋͳ͠

  89. %FGBVMU 4MJN )ZQFSG W 4XPGU W &BTZ4XPPMF W -BSBWFM W

    -BSBWFM 4XPPMF ճ໨       ̎ճ໨       ճ໨       ճ໨       ̑ճ໨       ճ໨       ճ໨       ճͷฏۉ        1)14XPPMF
  90. %FGBVMU 4MJN )ZQFSG W 4XPGU W &BTZ4XPPMF W -BSBWFM W

    -BSBWFM 4XPPMF ճ໨       ̎ճ໨       ճ໨       ճ໨       ̑ճ໨       ճ໨       ճ໨       ճͷฏۉ        1)1 +*5PGG 4XPPMF
  91. %FGBVMU 4MJN )ZQFSG W 4XPGU W &BTZ4XPPMF W -BSBWFM W

    -BSBWFM 4XPPMF ճ໨       ̎ճ໨       ճ໨       ճ໨       ̑ճ໨       ճ໨       ճ໨       ճͷฏۉ        1)1 +*5PO 4XPPMF
  92. %FGBVMU 4MJN )ZQFSG W 4XPGU W &BTZ4XPPMF W -BSBWFM W

    -BSBWFM 4XPPMF 1)1       1)1 +*5PGG       1)1 +*5PO       ؀ڥ͝ͱͷൺֱ
  93. %FGBVMU 4MJN )ZQFSG W 4XPGU W &BTZ4XPPMF W -BSBWFM W

    -BSBWFM 4XPPMF 1)1       1)1 +*5PGG       1)1 +*5PO       ؀ڥ͝ͱͷൺֱ ≒ ≒ ≒ ≒ ≒ ≒ ≒ ≒ 61 61
  94. )ZQFSG͕ϕϯνϚʔΫGBJM ͢Δ͜ͱ΋͋ͬͨ TFTTJPO·ΘΓ  ࢲͷιʔε͕ѱ͍Մೳੑ΋େ͍ʹ͋Γʣ 
 ϕϯνϚʔΫॴײ

  95. %#ʹෛՙ͕͔͔ΔϕϯνϚʔ ΫͷͨΊɺ࿈ଓͰ͔͚Δͱ ίωΫγϣϯϓʔϦϯάͯ͠ ͍ΔϑϨʔϜϫʔΫ͸ Τϥʔ͕ग़Δ͜ͱ΋͋ͬͨ ϕϯνϚʔΫॴײ

  96. ·ͱΊ

  97. 4XPPMFͷϑϨʔϜ ϫʔΫͷ1)1΁ͷ ຊ֨తͳରԠ͸ ͜Ε͔ΒͱࢥΘΕΔ

  98. ࠓޙ΋ಈ޲Λ ௥͍ͬͯ͘

  99. ݱ࣌఺ͷ͓͢͢Ί͸ʁ

  100. ࠓޙͷظ଴΋ࠐΊͯ )ZQFSG ͋͘·Ͱݸਓͷײ૝Ͱ͢

  101. -BSBWFM4XPPMF ΋Ҿ͖ଓ͖XBUDI ͋͘·Ͱݸਓͷײ૝Ͱ͢

  102. Έͳ͞Μ΋ 4XPPMFΛ͔ͭͬͨ ϑϨʔϜϫʔΫʹ νϟϨϯδ͠·͠ΐ͏

  103. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠