Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
PHPでWebサーバーを作って高速化に挑戦する!/php-web-server
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Ryo Tomidokoro
April 11, 2022
Technology
1.2k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
PHPでWebサーバーを作って高速化に挑戦する!/php-web-server
PHPerKaigi 2022 Day2 の LTです。
Ryo Tomidokoro
April 11, 2022
More Decks by Ryo Tomidokoro
See All by Ryo Tomidokoro
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
2.6k
あるアーキテクチャ決定と その結果/architecture-decision-and-its-result
hanhan1978
2
1.9k
開発者が知っておきたい複雑さの正体/where-the-complexity-comes-from
hanhan1978
8
4k
Spec Driven Development入門/spec_driven_development_for_learners
hanhan1978
2
2k
フロントエンドがTypeScriptなら、バックエンドはPHPでもいいじゃない/php-is-not-bad
hanhan1978
8
14k
どうすると生き残れないのか/how-not-to-survive
hanhan1978
17
15k
100分で本番デプロイ!Laravelで作るWebアプリケーション作成/100min_web_app_cicd
hanhan1978
1
310
PHPerのための計算量入門/Complexity101 for PHPer
hanhan1978
8
4k
集中して作業する技術/how_to_work_deeply
hanhan1978
69
62k
Other Decks in Technology
See All in Technology
「私が一番顧客に詳しい」を捨てる~ 全員が一次情報に精通する開発チームをつくり、PMが次のボトルネックへ染み出すまで
kaminashi
3
1.5k
Conditional PED-ANOVA: Hyperparameter Importance in Hierarchical & Dynamic Search Spaces
pfn
PRO
0
150
「Learning Outcome」を書きたくない私が、Learning Outcomeと折り合いをつけるまで
mhlyc
0
130
Refining Active Record
shugo
0
190
古い指輪から広がった JAVA コミュニティ とのつながり
yamad
0
140
トークン化預金DCJPYの取り組みと活用ユースケース
finengine
0
230
PHPカンファレンス関西の招待状 / Invitation to PHP Conference Kansai
ykanoh
0
230
Codex を使った障害対応机上演習の実際
orgachem
PRO
0
310
macOS Golden Gate 時代のMac管理
tategami
0
130
Metadata - Section 2: Simple Metadata & Meta Tags
mohab1
0
120
AIをリアル世界に解き放つ 〜M5Stack×AIであなたのアイディアを手の平に〜
hamadakoji
1
360
Claude Code on Bedrock で統制をかける小ネタ集/claude-code-bedrock-governance-tips
emiki
1
420
Featured
See All Featured
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.2k
BBQ
matthewcrist
90
10k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.3k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.4k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
590
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
2
960
Game over? The fight for quality and originality in the time of robots
wayneb77
1
310
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
370
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.9k
How to build a perfect <img>
jonoalderson
1
6.2k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
840
Paper Plane
katiecoart
PRO
5
54k
Transcript
@hanhan1978 PHPでWebサーバーを作って高速化に挑 戦する! PHPerKaigi 2022 LT
@hanhan1978 • 富所 亮 • 所属 株式会社カオナビ💎 Expert • 職業
Webアプリケーションエンジニア • ブログ https://blog.hanhans.net • Yokohama North AM https://anchor.fm/yokohama-north-am 2
本日のテーマ 3
PHP 8.1 でウェブサーバーを作って 世界一を目指す! 4
ルール説明 5
各言語、実装、ミドルウェアのウェブサーバーは / へのアクセスに対して {status : “OK”} というレスポンスを返す 6
各言語、実装、ミドルウェアのウェブサーバーは / へのアクセスに対して {status : “OK”} というレスポンスを返す 7
ベンチマーカーには wrk を使う。 ベンチマークコマンドは下記 wrk -t3 -c100 -d30s –latency http://127.0.0.1:8080/
8
9 実測
まずは対戦相手から 10
11 Go
Nginx 12 docker run -v default.conf:/etc/nginx/conf.d/default.conf -p 8080:80 --rm nginx
Node.js 13
14
top 1 で簡易に負荷状況を見る 15
top 1 で簡易に負荷状況を見る 16 特定のCPUコアに負荷が偏る
top 1 で簡易に負荷状況を見る 17
top 1 で簡易に負荷状況を見る 18 満遍なく負荷をかけられている こちらが理想的な形
19 PHP実装
Webサーバーとは? ようするに HTTP の仕様にそった 文字列を Socket 通信で返却すればOK 20
まずは、シングルプロセス 21
まずは、シングルプロセス 22 実に単純明快
23 結果
無念の敗退 24
次は、IO多重化 25
次は、IO多重化 26 複数コネクションを同時に扱 えるようになった
27 結果
むしろ遅くなる 28
シンプルすぎる返却値なので socket_select 分遅くなったと推測 29
よし!ノンブロックだ! 30
よし!ノンブロックだ! 31 時代はノンブロッキング
32 結果
ブロッキングとほぼ変わらない 33
この辺で、PHPのコア側にブロックしてい る箇所があるという想像が働く 34
実際の負荷状況 35
実際の負荷状況 36 全てのコアが遊びまくっている
ノンブロッキングの場合は無限ループのコードにな るので、若干1コアの負荷が上がるが、ほぼ負荷を かけられない 37
諦めずにpreforkしてみる 38
諦めずにpreforkしてみる 39 ノンブロッキングサーバーを 複数プロセスで利用
40 結果
ちょっと改善したが... 41
そろそろ勝てる気がしなくなってきたので 手当たりしだいに試した 42
手当たり次第の結果 43 実装 Req/Seq Amp 11933 RoadRunner 19618 Revolt 20297
mod-php 30389
なんとか Node.js をかわした 44
しかし、それでいいのか? 45
mod-php での実装 46
mod-php での実装 47 これでいいのか?
助けて Open Swoole ….. 48
Open Swoole での実装 49
50 結果
勝てば官軍 51
52 優勝だ!
ちょっとだけ、まじめなラップアップ 53
Open Swoole は、PHPコアのブロッキングする関 数を独自実装で置き換えている。 結局のところ、ボトルネックを自前で差し替えるよう な豪腕を発揮しない限りPHP単体では勝てないの かもしれない。 54
この件については、まじめな追加調査をします! 影PHP勉強会でお会いしましょう! 55