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. 2.

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

    • גࣜձࣾαϜβοϓ • നҪɹӳ • ΤϯδχΞ • #MPH IUUQBNFCMPKQHPPEPP ͓લɺ୭Α • 5XJUUFS !HPPEPP • %2 ͙ͪ͢Ή '# 
 ϓΫϦϙ ཱྀܳਓ
  2. 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
  3. 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
  4. 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 ίϯτϩʔϥʔ
  5. 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 ϧʔλʔ
  6. 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 Ϟσϧ
  7. 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 %#ͷίωΫγϣ ϯϓʔϧ
  8. 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 ςϯϓϨʔτϑΝΠϧ
  9. 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 ੩తϑΝΠϧ
  10. 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 ىಈ༻ϑΝΠϧ
  11. 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ϑΝΠϧ ؀ڥ͝ͱ
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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
  22. 76.
  23. 88.
  24. 89.

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

    ճ໨       ̎ճ໨       ճ໨       ճ໨       ̑ճ໨       ฏۉ       ˞ϩδοΫมߋͳ͠ͷঢ়ଶ 1)1 4XPPMF
  25. 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
  26. 92.