Swooleのフレームワークをくらべてみた

 Swooleのフレームワークをくらべてみた

PHPerKaig2019の発表資料です

uzullaさんのPHPerKaigi2018「大統一PHP」
https://speakerdeck.com/uzulla/da-tong-php
で紹介されているSwooleという非同期かつ、Coroutineの仕組みをもったPHPのextensionがあります。
Swooleを用いたフレームワークはいくつかあります。
今回、EasySwoole(v2,v3)、Swoft、Laravel-Swooleの3つの比べてみた結果をお話しします。
それぞれのフレームワークのISUCON8予選のベンチマークの結果をお伝えします(恒例)
No.1 Swooleフレームワークはどれだ!

Ec2fcdc4ea7905b289967a2c4c43e154?s=128

CyberAgent SGE Engineer

March 31, 2019
Tweet

Transcript

  1. 4XPPMFͷϑϨʔϜϫʔΫΛ ͘Β΂ͯΈͨ !HPPEPP  QIQFSLBJHJ

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

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

  4. 4XPPMFͱ͸

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

  6. 1)1FS,JBHJͷV[VMMB͞ΜͷൃදͰ஌Γ·ͨ͠ https://speakerdeck.com/uzulla/da-tong-php

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

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

  9. 4XPPMFͷ(JU)VCͰ঺հ͞Ε͍ͯΔ ϑϨʔϜϫʔΫɹ̏ͭ https://github.com/swoole/swoole-src

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

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

  12. 4BCFS 'BUF޷͖͕ͭͬͨͬ͘Ά͍

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

  14. ࠓճ͓࿩͢Δ ϑϨʔϜϫʔΫ

  15. w&BTZ4XPPMF W W  w4XPGU w-BSBWFM4XPPMF

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

  17. ಛ௃  &BTZ4XPPMF •Built-in HTTP, TCP, WebSocket,Udp Coroutine Server •Global

    dependency injection container •PSR-7 based HTTP message implementation •RESTful supported •HTTP,TCP, WebSocket, Udp middleware support •Mysql, Redis, RPC, HTTP Coroutine Clients •High performance router •Universal connection pools •Remote Console W
  18. W͔Βͷվળ఺ ࣗ෼͕ؾ͍ͮͨ఺  &BTZ4XPPMF

  19. %#ͷτϥϯβΫγϣϯ ·ΘΓ͕੔උ͞Εͨ W͸ͳ͔ͬͨɾɾ  &BTZ4XPPMF

  20.  &BTZ4XPPMF

  21. $POpH͕EFWͱ QSPEVDUJPOͱΛ෼͚ͯ ؅ཧͰ͖ΔΑ͏ʹͳͬͨ W͸ͳ͔ͬͨɾɾɾ  &BTZ4XPPMF

  22.  &BTZ4XPPMF ىಈ࣌ʹ؀ڥ໊Λࢦఆ ແࢦఆͩͱEFWͷDPOpH͕ద༻͞ΕΔʣ $ php easyswoole start produce

  23. &BTZ4XPPMFͷϑΥϧμߏ੒ ࠷খݶ Project ├ App         │ ├ HttpController │ │ ├ BooksController.php │ │ └

    Router.php │ ├ Model │ │ └ BookModel.php │ └ Utility │   └ Pool │     ├ MysqlObject.php │     └ MysqlPool.php ├ Views │ └ index.twig ├ Log ├ Temp ├ vendor ├ Static │ ├ css │ └ js ├ easyswoole ├ production.php └ dev.php  &BTZ4XPPMF
  24. &BTZ4XPPMFͷϑΥϧμߏ੒ ࠷খݶ Project ├ App         │ ├ HttpController │ │ ├ BooksController.php │ │ └

    Router.php │ ├ Model │ │ └ BookModel.php │ └ Utility │   └ Pool │     ├ MysqlObject.php │     └ MysqlPool.php ├ Views │ └ index.twig ├ Log ├ Temp ├ vendor ├ Static │ ├ css │ └ js ├ easyswoole ├ production.php └ dev.php  &BTZ4XPPMF ίϯτϩʔϥʔ
  25. &BTZ4XPPMFͷϑΥϧμߏ੒ ࠷খݶ Project ├ App         │ ├ HttpController │ │ ├ BooksController.php │ │ └

    Router.php │ ├ Model │ │ └ BookModel.php │ └ Utility │   └ Pool │     ├ MysqlObject.php │     └ MysqlPool.php ├ Views │ └ index.twig ├ Log ├ Temp ├ vendor ├ Static │ ├ css │ └ js ├ easyswoole ├ production.php └ dev.php  &BTZ4XPPMF ϧʔλʔ
  26. &BTZ4XPPMFͷϑΥϧμߏ੒ ࠷খݶ Project ├ App         │ ├ HttpController │ │ ├ BooksController.php │ │ └

    Router.php │ ├ Model │ │ └ BookModel.php │ └ Utility │   └ Pool │     ├ MysqlObject.php │     └ MysqlPool.php ├ Views │ └ index.twig ├ Log ├ Temp ├ vendor ├ Static │ ├ css │ └ js ├ easyswoole ├ production.php └ dev.php  &BTZ4XPPMF Ϟσϧ
  27. &BTZ4XPPMFͷϑΥϧμߏ੒ ࠷খݶ Project ├ App         │ ├ HttpController │ │ ├ BooksController.php │ │ └

    Router.php │ ├ Model │ │ └ BookModel.php │ └ Utility │   └ Pool │     ├ MysqlObject.php │     └ MysqlPool.php ├ Views │ └ index.twig ├ Log ├ Temp ├ vendor ├ Static │ ├ css │ └ js ├ easyswoole ├ production.php └ dev.php  &BTZ4XPPMF %#ͷίωΫγϣ ϯϓʔϧ
  28. &BTZ4XPPMFͷϑΥϧμߏ੒ ࠷খݶ Project ├ App         │ ├ HttpController │ │ ├ BooksController.php │ │ └

    Router.php │ ├ Model │ │ └ BookModel.php │ └ Utility │   └ Pool │     ├ MysqlObject.php │     └ MysqlPool.php ├ Views │ └ index.twig ├ Log ├ Temp ├ vendor ├ Static │ ├ css │ └ js ├ easyswoole ├ production.php └ dev.php  &BTZ4XPPMF ςϯϓϨʔτϑΝΠϧ
  29. &BTZ4XPPMFͷϑΥϧμߏ੒ ࠷খݶ Project ├ App         │ ├ HttpController │ │ ├ BooksController.php │ │ └

    Router.php │ ├ Model │ │ └ BookModel.php │ └ Utility │   └ Pool │     ├ MysqlObject.php │     └ MysqlPool.php ├ Views │ └ index.twig ├ Log ├ Temp ├ vendor ├ Static │ ├ css │ └ js ├ easyswoole ├ production.php └ dev.php  &BTZ4XPPMF ੩తϑΝΠϧ
  30. &BTZ4XPPMFͷϑΥϧμߏ੒ ࠷খݶ Project ├ App         │ ├ HttpController │ │ ├ BooksController.php │ │ └

    Router.php │ ├ Model │ │ └ BookModel.php │ └ Utility │   └ Pool │     ├ MysqlObject.php │     └ MysqlPool.php ├ Views │ └ index.twig ├ Log ├ Temp ├ vendor ├ Static │ ├ css │ └ js ├ easyswoole ├ production.php └ dev.php  &BTZ4XPPMF ىಈ༻ϑΝΠϧ
  31. &BTZ4XPPMFͷϑΥϧμߏ੒ ࠷খݶ Project ├ App         │ ├ HttpController │ │ ├ BooksController.php │ │ └

    Router.php │ ├ Model │ │ └ BookModel.php │ └ Utility │   └ Pool │     ├ MysqlObject.php │     └ MysqlPool.php ├ Views │ └ index.twig ├ Log ├ Temp ├ vendor ├ Static │ ├ css │ └ js ├ easyswoole ├ production.php └ dev.php  &BTZ4XPPMF $POpHϑΝΠϧ ؀ڥ͝ͱ
  32. ίωΫγϣϯϓʔϧ  &BTZ4XPPMF

  33. ίωΫγϣϯϓʔϧ  &BTZ4XPPMF ίϯτϩʔϥʔͰɺϦΫΤετ։࢝͝ͱ ʹݺͼग़͞ΕΔϝιου

  34. ίωΫγϣϯϓʔϧ  &BTZ4XPPMF ϓʔϧ͔Β%#ͷΠϯελϯεΛऔΓग़͢

  35. ίωΫγϣϯϓʔϧ  &BTZ4XPPMF ίϯτϩʔϥʔͰɺϦΫΤετऴྃ͝ͱ ʹݺͼग़͞ΕΔϝιου

  36. ίωΫγϣϯϓʔϧ  &BTZ4XPPMF ϦιʔεΛϓʔϧʹฦ٫

  37. ϧʔλʔ  &BTZ4XPPMF

  38. ϧʔλʔ  &BTZ4XPPMF ؆୯ͳॲཧͳΒͦͷ··͔͚Δ

  39. ϧʔλʔ  &BTZ4XPPMF (&5ɺ1045ɺ165ɺ%&-&5&Λࢦఆ ͯ͠ɺϧʔςΟϯά

  40. ίϯϑΟά  &BTZ4XPPMF

  41. ίϯϑΟά  &BTZ4XPPMF 4XPPMFपΓͷઃఆ͸͜͜

  42. ίϯϑΟά  &BTZ4XPPMF .Z42-ͷઃఆ͸ίί

  43. ΘΓͱૉ௚ʹѻ͑Δ ϑϨʔϜϫʔΫ  &BTZ4XPPMF

  44.  4XPGU  4XPGU https://www.swoft.org/

  45. •Base on Swoole extension •Built-in HTTP, TCP, WebSocket Coroutine Server

    •Powerful AOP (Aspect Oriented Programming) •Flexible and comprehensive annotations framework •Global dependency injection container •PSR-7 based HTTP message implementation •PSR-14 based event manager •PSR-15 based middleware •PSR-16 based cache design •Scalable high performance RPC •Holistic service governance, fallback, load balance, service registration and discovery •Database ORM •Universal connection pools •Mysql, Redis, RPC, HTTP Coroutine Clients •Coroutine driver client and blocking driver client seamlessly switch automatically •Coroutine and asynchronous task delivery •Custom user processes •RESTful supported •Internationalization (i18n) supported •High performance router •Fast and flexible parameter validator •Alias mechanism •Powerful log component •Cross-platform application auto- reload mechanism https://github.com/swoft-cloud/swoft ͷREADMEͷӳ༁ Ҿ༻ɿ  4XPGU
  46. •Built-in HTTP, TCP, WebSocket Coroutine Server •Powerful AOP (Aspect Oriented

    Programming) •Database ORM •Universal connection pools •Flexible and comprehensive annotations framework •Global dependency injection container •PSR-7 based HTTP message implementation ಛ௃  4XPGU
  47. 3FRVFTUMJGFDZDMF https://doc.swoft.org/master/zh-CN/core/framework.html  4XPGU

  48. 4XPGUͷϑΥϧμߏ੒ ࠷খݶ Project ├ app         │ ├ Controllers │ │ └ BooksController.php │ └

    Models │   └ Entity │    └ Books.php ├ config │ ├ beans │ │ └ base.php │ └ properties │   ├ app.php │   └ db.php ├ public ├ runtime │ ├ logs │ ├ uploadfiles │ └ sessions ├ resources │ └ views │   └ books │     └ view.php └ bin   ├ bootstrap.php   └ swoft  4XPGU
  49. 4XPGUͷϑΥϧμߏ੒ ࠷খݶ Project ├ app         │ ├ Controllers │ │ └ BooksController.php │ └

    Models │   └ Entity │    └ Books.php ├ config │ ├ beans │ │ └ base.php │ └ properties │   ├ app.php │   └ db.php ├ public ├ runtime │ ├ logs │ ├ uploadfiles │ └ sessions ├ resources │ └ views │   └ books │     └ view.php └ bin   ├ bootstrap.php   └ swoft ίϯτϩʔϥʔ Ϟσϧ  4XPGU
  50. 4XPGUͷϑΥϧμߏ੒ ࠷খݶ Project ├ app         │ ├ Controllers │ │ └ BooksController.php │ └

    Models │   └ Entity │    └ Books.php ├ config │ ├ beans │ │ └ base.php │ └ properties │   ├ app.php │   └ db.php ├ public ├ runtime │ ├ logs │ ├ uploadfiles │ └ sessions ├ resources │ └ views │   └ books │     └ view.php └ bin   ├ bootstrap.php   └ swoft ౎౓ಡΈࠐ·ΕΔ ઃఆϑΝΠϧ ˞FOW͕༏ઌ CFBOੜ੒࣌ʹಡΈࠐ·ΕΔ ϑΝΠϧ  4XPGU
  51. 4XPGUͷϑΥϧμߏ੒ ࠷খݶ Project ├ app         │ ├ Controllers │ │ └ BooksController.php │ └

    Models │   └ Entity │    └ Books.php ├ config │ ├ beans │ │ └ base.php │ └ properties │   ├ app.php │   └ db.php ├ public ├ runtime │ ├ logs │ ├ uploadfiles │ └ sessions ├ resources │ └ views │   └ books │     └ view.php └ bin   ├ bootstrap.php   └ swoft ੩తϑΝΠϧஔ͖৔ DTTɺKT  4XPGU
  52. 4XPGUͷϑΥϧμߏ੒ ࠷খݶ Project ├ app         │ ├ Controllers │ │ └ BooksController.php │ └

    Models │   └ Entity │    └ Books.php ├ config │ ├ beans │ │ └ base.php │ └ properties │   ├ app.php │   └ db.php ├ public ├ runtime │ ├ logs │ ├ uploadfiles │ └ sessions ├ resources │ └ views │   └ books │     └ view.php └ bin   ├ bootstrap.php   └ swoft Ұ࣌ϑΝΠϧஔ͖৔  4XPGU
  53. 4XPGUͷϑΥϧμߏ੒ ࠷খݶ Project ├ app         │ ├ Controllers │ │ └ BooksController.php │ └

    Models │   └ Entity │    └ Books.php ├ config │ ├ beans │ │ └ base.php │ └ properties │   ├ app.php │   └ db.php ├ public ├ runtime │ ├ logs │ ├ uploadfiles │ └ sessions ├ resources │ └ views │   └ books │     └ view.php └ bin   ├ bootstrap.php   └ swoft UFNQMBUFϑΝΠϧ  4XPGU
  54. 4XPGUͷϑΥϧμߏ੒ ࠷খݶ Project ├ app         │ ├ Controllers │ │ └ BooksController.php │ └

    Models │   └ Entity │    └ Books.php ├ config │ ├ beans │ │ └ base.php │ └ properties │   ├ app.php │   └ db.php ├ public ├ runtime │ ├ logs │ ├ uploadfiles │ └ sessions ├ resources │ └ views │   └ books │     └ view.php └ bin   ├ bootstrap.php   └ swoft ىಈ༻ϑΝΠϧ  4XPGU
  55. ίϯτϩʔϥʔ  4XPGU

  56. ίϯτϩʔϥʔ w 63-ͷϚοϐϯάΛBOOPUBUJPOͰ ઃఆ w ςϯϓϨʔτɺϨΠΞ΢τϑΝΠϧΛ BOOPUBUJPOͰઃఆ  4XPGU

  57. ίϯτϩʔϥʔ 143४ڌ  4XPGU

  58. ίϯτϩʔϥʔ ʙதུʙ %FQFOEFODZ *OKFDUJPO  4XPGU

  59. Ϟσϧ &OUJUZ  4XPGU

  60. Ϟσϧ &OUJUZ $ php bin/swoft entity:create -d bookshelf ࣍ͷίϚϯυͰ%#͔Βࣗಈੜ੒ ϦόʔεΤϯδχΞϦϯά

     4XPGU
  61. Ϟσϧ03.  4XPGU

  62. Ϟσϧ03. 03. #PPLTςʔϒϧσʔλΛऔಘ  4XPGU

  63. $POpH%#  4XPGU

  64. $POpH%# DPOOFDUJPOQPPMͷઃఆ  4XPGU

  65. Ұ௨Γἧ͍ͬͯΔ ϑϧελοΫ ϑϨʔϜϫʔΫ  4XPGU

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

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

  68. -BSBWFMͰΞϓϦέʔγϣ ϯΛͭ͘Δ  -BSBWFM4XPPMF ඇಉظฒྻॲཧ͕΄͘͠ͳΔ -BSBWFM4XPPMFͰղܾ

  69. -BSBWFM UP -BSBWFM4XPPMF  -BSBWFM4XPPMF

  70.  DPNQPTFSʹ௥Ճ  -BSBWFM4XPPMF  DPOpHͷ1SPWJEFS௥Ճ

  71.  4XPPMF༻ͷDPOpHੜ੒  -BSBWFM4XPPMF $ php artisan vendor:publish --tag=laravel-swoole 

    DPOpHTXPPMF@IUUQQIQΛઃఆ
  72.  ىಈ  -BSBWFM4XPPMF $ php artisan swoole:http start ॳظઃఆͩͱ൪ϙʔτͰ଴ͪड͚·͢

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

  74. DPSPVUJOFͷॻ͖ํ

  75. ͲͷϑϨʔϜϫʔΫ΋ 4XPPMFͷؔ਺͕ݺ΂Δ ͷͰ࣍ͷΑ͏ʹ͔͚Δ

  76. None
  77. HPؔ਺ͰDPSPVUJOFͱͯ͠ಈ࡞

  78. $IBOOFMΛ࡞੒ $IBOOFMʹ σʔλΛ֨ೲ औΓग़͢ ˞औΓग़ͨ͠σʔλ ͷॱং͸ෆఆ

  79. ϕϯνϚʔΫ ݁Ռ

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

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

  82. νέοτ༧໿αΠτ

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

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

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

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

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

    Swoole MySQL ୆ ୆
  88. ൺֱ݁Ռ

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

    ճ໨       ̎ճ໨       ճ໨       ճ໨       ̑ճ໨       ฏۉ       ˞ϩδοΫมߋͳ͠ͷঢ়ଶ 1)1 4XPPMF
  90. %FGBVMU 4MJN &BTZ4XPPMF W &BTZ4XPPMF W 4XPGU -BSBWFM -BSBWFM 4XPPMF

    ճ໨       ̎ճ໨       ճ໨       ճ໨       ̑ճ໨       ฏۉ       ˞ϩδοΫมߋͳ͠ͷঢ়ଶ 1)1 4XPPMF ϑϨʔϜϫʔΫͷ ҧ͍͸ޡࠩͰ͢ʂ &BTZ4XPPMF W ͷ࣮૷ɿ 4XPGUͷ࣮૷ɿ https://github.com/shirai-suguru/isucon8-swoft https://github.com/shirai-suguru/isucon8-easyswoole &BTZ4XPPMF W ͷ࣮૷ɿ https://github.com/shirai-suguru/isucon8-easyswoole-v3 -BSBWFMͷ࣮૷ɿ https://github.com/shirai-suguru/isucon8-laravel -BSBWFM4XPPMFͷ࣮૷ɿ https://github.com/shirai-suguru/isucon8-laravel-swoole
  91. &BTZ4XPPMF͸एׯ҆ఆ౓ ʹ͚ܽΔ͔΋ ࣗ෼͕ॻ͍ͨ෦෼ͰϝϞϦ͕ϦʔΫͯ͠ΔՄ ೳੑ΋͋Δ͕  ߴෛՙ࣌Τϥʔ͕ͰΔͱ͖͕͋ͬͨ ϕϯνϚʔΫॴײ

  92. ·ͱΊ

  93. ͓͢͢Ί͸ʁ

  94. ݸਓతʹ4XPGU ͋͘·Ͱݸਓͷײ૝Ͱ͢

  95. ͨͩ͠ɺ4XPGU͸ ߋ৽ස౓͕Լ͕ͬͯ WΛ࡞͍ͬͯΔؾ഑

  96. কདྷੑ͸ -BSBWFM4XPPMF ͋͘·Ͱݸਓͷײ૝Ͱ͢

  97. ಋೖͷෑډ͕௿͍ ˍ ਓؾͷϑϨʔϜϫʔΫ ͕΄΅ͦͷ··ಈ͘

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

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