Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
php-fpm をちょっとチューニングしてみよう #phpblt
Search
Yuichiro SAITO
PRO
February 22, 2017
Technology
5
7.5k
php-fpm をちょっとチューニングしてみよう #phpblt
PHP BLT #6
2017-02-22 @ メルカリ 東京 (六本木ヒルズ)
Yuichiro SAITO
PRO
February 22, 2017
Tweet
Share
More Decks by Yuichiro SAITO
See All by Yuichiro SAITO
FinTech スタートアップのセキュリティチェックシートとの向き合い方 / AWS FinTech Bootcamp! Compliance
koemu
PRO
0
520
クラウドを積極活用したサービスの開発のために / AWS FinTech Bootcamp! Basic
koemu
PRO
0
220
ワークショップFinTech アーキテクチャ / AWS FinTech Bootcamp! Workshop
koemu
PRO
0
210
正しい理解で作る安心安全な FinTech の IT インフラ / tech play aws 2022 2
koemu
PRO
1
260
AWSの「今」 -PHPのコードを素早く動かすためのサービスのご紹介 / PHPCon2022 AWS Japan Session
koemu
PRO
2
1.9k
PdMとエンジニアのより良いコミュニケーションに向けて / Improve communication between Product Manager and Software Engineer
koemu
PRO
1
490
フェイズ別・スタートアップ企業への技術選定 シード編 #AWS #AWSStartup / Startup Tech 101 for Seed
koemu
PRO
0
480
AWSを使って送金機能を実装してみよう - 「sunabar-GMOあおぞらネット銀行API実験場-」コミュニティイベント第6弾
koemu
PRO
0
1k
Hardening II SU Softening Day - Team カムイ Presentation
koemu
PRO
0
3.7k
Other Decks in Technology
See All in Technology
DevOps視点でAWS re:invent2024の新サービス・アプデを振り返ってみた
oshanqq
0
180
C++26 エラー性動作
faithandbrave
2
680
WACATE2024冬セッション資料(ユーザビリティ)
scarletplover
0
190
オプトインカメラ:UWB測位を応用したオプトイン型のカメラ計測
matthewlujp
0
170
OpenShift Virtualizationのネットワーク構成を真剣に考えてみた/OpenShift Virtualization's Network Configuration
tnk4on
0
130
2024年にチャレンジしたことを振り返るぞ
mitchan
0
130
OpenAIの蒸留機能(Model Distillation)を使用して運用中のLLMのコストを削減する取り組み
pharma_x_tech
4
540
KnowledgeBaseDocuments APIでベクトルインデックス管理を自動化する
iidaxs
1
250
日本版とグローバル版のモバイルアプリ統合の開発の裏側と今後の展望
miichan
1
120
LINE Developersプロダクト(LIFF/LINE Login)におけるフロントエンド開発
lycorptech_jp
PRO
0
120
PHPからGoへのマイグレーション for DMMアフィリエイト
yabakokobayashi
1
160
複雑性の高いオブジェクト編集に向き合う: プラガブルなReactフォーム設計
righttouch
PRO
0
110
Featured
See All Featured
The Language of Interfaces
destraynor
154
24k
Designing on Purpose - Digital PM Summit 2013
jponch
116
7k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
Code Review Best Practice
trishagee
65
17k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Into the Great Unknown - MozCon
thekraken
33
1.5k
Unsuck your backbone
ammeep
669
57k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Transcript
php-fpm Λͪΐͬͱνϡʔχϯάͯ͠ ΈΑ͏ • Yuichiro Saito (@koemu) • 2017-02-22 @
ϝϧΧϦ ౦ژΦϑΟε © Yuichiro Saito (koemu), 2017 1
ࠓͷ͓ • php-fpm ͷࢠϓϩηεΛվળͯ͠ΈΑ͏ • ͍ͬͯΔΠϯελϯεͷੑೳΛҾ͖ग़ͦ͏ • (νϡʔχϯάೖͷ͓Ͱ͢) © Yuichiro
Saito (koemu), 2017 2
લఏ݅ ڥ koemu$ cat /etc/debian_version # Ubuntu 16.04 LTS stretch/sid
koemu$ php -v PHP 7.0.13-0ubuntu0.16.04.1 (cli) ( NTS ) koemu$ nginx -v nginx version: nginx/1.10.0 (Ubuntu) Ubuntu 16.04 LTS্ͷnginx + php-fpmͰಈ͘ߏஙͨ͠લఏͰ͓͠·͢ɻ αʔόΠϯελϯεɺಛه͕ͳ͍ݶΓAWS౦ژϦʔδϣϯ m4.large (2vCPU) ͱ͠·͢ɻ © Yuichiro Saito (koemu), 2017 3
Լ४උ $ sudo apt-get install apache2-utils htop ҙ: ຊ ab
Λ࣮ߦ͢Δαʔό͚ͨ΄͏͕͍͍Ͱ͢ɻࠓ ճ؆қతͳܗͰհ͠·͢ɻ © Yuichiro Saito (koemu), 2017 4
σϑΥϧτͰͬͯ·ͤΜ͔ʁ Ubuntu 16.04 LTSͷ߹ pm = dynamic pm.max_children = 5
pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 3 ;pm.process_idle_timeout = 10s; ;pm.max_requests = 500 © Yuichiro Saito (koemu), 2017 5
σϑΥϧτͷ··ͩͱ • ىಈϓϩηε2ɻ • ࠷େϓϩηε͕5ɻ ͦͯ͠ • ϓϩηεಈతʹ૿ݮ͢Δɻ ͋ͳͨͷ࡞ͬͨΞϓϦɺ͜ΕͰੑೳग़·͔͢Ͷʁ ©
Yuichiro Saito (koemu), 2017 6
͍ͬͨͳ͍ʂʂʂʂ © Yuichiro Saito (koemu), 2017 7
ϓϩηεΛௐͯ͠ΈΔ © Yuichiro Saito (koemu), 2017 8
ࢼ͠ʹܭଌͯ͠ΈΔ ୯७ͳ phpinfo() Λฦ͚ͩ͢ͷΞϓϦέʔγϣϯɻ $ ab -l -n 10000 -c
1 http://localhost/index.php Requests per second: 1509.23 [#/sec] (mean) $ ab -l -n 10000 -c 3 http://localhost/index.php Requests per second: 1734.29 [#/sec] (mean) $ ab -l -n 10000 -c 5 http://localhost/index.php Requests per second: 1852.83 [#/sec] (mean) $ ab -l -n 10000 -c 10 http://localhost/index.php Requests per second: 1817.48 [#/sec] (mean) $ ab -l -n 10000 -c 20 http://localhost/index.php Requests per second: 1767.25 [#/sec] (mean) © Yuichiro Saito (koemu), 2017 9
5Ͱݶʁ pm.max_children = 5 Ͱઃఆͨ͠Ͱ಄ଧͪͰ͢Ͷɻ © Yuichiro Saito (koemu), 2017
10
͜͜Ͱฤू diff --git a/php/7.0/fpm/pool.d/www.conf b/php/7.0/fpm/pool.d/www.conf index 635f192..7808cde 100644 --- a/php/7.0/fpm/pool.d/www.conf
+++ b/php/7.0/fpm/pool.d/www.conf @@ -93,7 +93,7 @@ listen.group = www-data ; pm.process_idle_timeout - The number of seconds after which ; an idle process will be killed. ; Note: This value is mandatory. -pm = dynamic +pm = static ; The number of child processes to be created when pm is set to 'static' and the ; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'. @@ -104,7 +104,7 @@ pm = dynamic ; forget to tweak pm.* to fit your needs. ; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand' ; Note: This value is mandatory. -pm.max_children = 5 +pm.max_children = 10 © Yuichiro Saito (koemu), 2017 11
มߋՕॴʹ͍ͭͯ pm = static • ࢠϓϩηεΛಈతʹ૿ݮ͢ΔͷͰͳ͘ɺݻఆʹ͠·͢ɻ • ಈ͘ΞϓϦέʔγϣϯܾͬͯ·ͬͯ·͢ΑͶʁ • ܾ·͍ͬͯΔͷͳΒɺ࠷ॳ͔Βݻఆͨ͠΄͏͕૿ݮͷΦʔόʔϔουݮΒͤ·͢ΑͶɻ
pm.max_children = 10 • ࢠϓϩηε • 10ʹઃఆ • ͜ͷ͕Ռͨͯ͠ ద ͔͕ࠓճͷϙΠϯτʂ © Yuichiro Saito (koemu), 2017 12
10ϓϩηεͰͲ͏ͩ $ ab -l -n 10000 -c 1 http://localhost/index.php Requests
per second: 1499.22 [#/sec] (mean) $ ab -l -n 10000 -c 3 http://localhost/index.php Requests per second: 1704.51 [#/sec] (mean) $ ab -l -n 10000 -c 5 http://localhost/index.php Requests per second: 1802.32 [#/sec] (mean) $ ab -l -n 10000 -c 10 http://localhost/index.php Requests per second: 1774.85 [#/sec] (mean) $ ab -l -n 10000 -c 20 http://localhost/index.php Requests per second: 1774.27 [#/sec] (mean) © Yuichiro Saito (koemu), 2017 13
…ɺ͋Μ·มΘΒͳ͍Ͱ͢Ͷɻ © Yuichiro Saito (koemu), 2017 14
࣮…ฒྻ3࣌: CPUΛ΄΅͍͍ͬͯΔ © Yuichiro Saito (koemu), 2017 15
͍ɻ © Yuichiro Saito (koemu), 2017 16
ͰCPUίΞΛ૿͢ͱͲ͏͔ c4.4xlarge (16vCPU) ʹͯ͠Έ·͢ɻ $ ab -l -n 10000 -c
1 http://localhost/index.php Requests per second: 1918.79 [#/sec] (mean) $ ab -l -n 10000 -c 3 http://localhost/index.php Requests per second: 4845.39 [#/sec] (mean) $ ab -l -n 10000 -c 5 http://localhost/index.php Requests per second: 7109.63 [#/sec] (mean) $ ab -l -n 10000 -c 10 http://localhost/index.php Requests per second: 7400.49 [#/sec] (mean) $ ab -l -n 10000 -c 20 http://localhost/index.php Requests per second: 7771.68 [#/sec] (mean) © Yuichiro Saito (koemu), 2017 17
ͳͥॲཧͰ͖ΔΑ͏ʹͳͬͨͷ͔ʁ • ࠓ·Ͱ: ϓϩηε > ίΞ • ͋Δϓϩηε͕CPUΛѲ͍ͬͯΔͱɺ΄͔ͷϓϩηεॲཧ͕Ͱ͖ͳ͍ɻ • ࠷ॳ2vCPU→2ϓϩηεʴαఔ͕ॲཧͷݶɻ
• c4.4xlarge ʹมߋ: ϓϩηε < ίΞ • Ͳ͔͜ͷCPUίΞ͕ۭ͍͍ͯΔɻ • 10ϓϩηε·ͰىಈͰ͖ΔΑ͏ʹ͍ͯ͠ΔͷͰɺ16ίΞͷͲΕ͔Λࣗ༝ʹಠ͠ ͯ͑Δঢ়ଶͰ͋ΓɺଞͷϓϩηεͷऴྃΛͭඞཁ͕ͳ͘ͳΔɻ • 1ϓϩηε͋ͨΓͷੑೳΛҾ͖ग़ͤΔΑ͏ʹͳͬͨɻ © Yuichiro Saito (koemu), 2017 18
ͰࠓͷઃఆͰͲ͜·Ͱߦ͚Δ͔ʁ $ ab -n 10000 -c 30 http://localhost/index.php Requests per
second: 8418.15 [#/sec] (mean) $ ab -n 10000 -c 50 http://localhost/index.php Requests per second: 7250.75 [#/sec] (mean) Ͳ͏Βಉ࣌20ʙ30ଓ͕͍͍ͱ͜ΖͷΑ͏Ͱ͢ɻ © Yuichiro Saito (koemu), 2017 19
CPU༨༟͋Γͦ͏ © Yuichiro Saito (koemu), 2017 20
Ͱ pm.max_children = 16 ʹ͠·͢ɻ $ ab -l -n 10000
-c 10 http://localhost/index.php Requests per second: 9959.54 [#/sec] (mean) $ ab -l -n 10000 -c 20 http://localhost/index.php Requests per second: 14348.17 [#/sec] (mean) $ ab -l -n 10000 -c 30 http://localhost/index.php Requests per second: 14814.62 [#/sec] (mean) $ ab -l -n 10000 -c 40 http://localhost/index.php Requests per second: 14224.85 [#/sec] (mean) $ ab -l -n 10000 -c 50 http://localhost/index.php Requests per second: 14220.10 [#/sec] (mean) ಉ࣌20ʙ30ଓ·Ͱͳͷ͔ΘΓ·ͤΜ͕ɺrps͕͋Γ·ͨ͠ɻ © Yuichiro Saito (koemu), 2017 21
͔͠͠CPU ·ͩ༨༟͕͋ΔΜͰ͢ © Yuichiro Saito (koemu), 2017 22
Ͱ pm.max_children = 32 ʹ͠·͢ɻ ฏۉ70%ఔͰਪҠ͍ͯ͠·͢ͷͰɺϓϩηεΛ୯७ʹഒʹͯ͠Έ·͠ΐ͏ɻ $ ab -l -n
10000 -c 10 http://localhost/index.php Requests per second: 10123.11 [#/sec] (mean) $ ab -l -n 10000 -c 20 http://localhost/index.php Requests per second: 12894.17 [#/sec] (mean) $ ab -l -n 10000 -c 30 http://localhost/index.php Requests per second: 14858.04 [#/sec] (mean) $ ab -l -n 10000 -c 40 http://localhost/index.php Requests per second: 16056.80 [#/sec] (mean) $ ab -l -n 10000 -c 50 http://localhost/index.php Requests per second: 16279.67 [#/sec] (mean) ಉ࣌30ʙ40ଓ͘Β͍·Ͱ͍͚ͦ͏Ͱ͢Ͷɻͨͩɺ͜ΕҎ্ͷ্ݟࠐΊͳͦ͞͏Ͱ͢ɻ © Yuichiro Saito (koemu), 2017 23
php-fpm ͷεςʔλεϖʔδΛݟΔͱ pool: www process manager: static start since: 225
accepted conn: 700001 listen queue: 0 max listen queue: 0 listen queue len: 0 idle processes: 31 active processes: 1 total processes: 32 max active processes: 32 max children reached: 0 slow requests: 0 max active processes: 32ɻҰഋଓΛ͍͑ͯΔΑ͏Ͱ͢ɻ © Yuichiro Saito (koemu), 2017 24
CPU͋Δఔ͍͑ͯ·͢Ͷ © Yuichiro Saito (koemu), 2017 25
࣮ࡍӡ༻͍ͯͯ͠ؾʹ͍ͯ͠Δ͜ͱ • զ͕ՈͷWordpressͷࣄྫ © Yuichiro Saito (koemu), 2017 26
࣮ࡍͷϝϞϦ༻ྔͱCPU༻ྔ © Yuichiro Saito (koemu), 2017 27
PHP 5.4→PHP 7.0ʹΞοϓσʔτͨ࣌͠ ϝϞϦ༻ྔ͕͙ͬͱݮΔ © Yuichiro Saito (koemu), 2017 28
ҙͨ͜͠ͱ • CPUεΧεΧͳͷ͕ͩɺϝϞϦΛΑ͘৯͍ͬͯΔɻ • ϓϩηεΛ૿͗͢͠ΔͱɺCPUΑΓϝϞϦͷྔ͕Γͳ͘ͳͬͨɻ • ϝϞϦͷྔΛݟͳ͕ΒϓϩηεΛ૿͢ඞཁ͕͋ͬͨɻ • ಛʹϝϞϦࡌྔ͕গͳ͍VPSཁҙɻ •
࣮ࡍɺଌఆ݁ՌΛجʹͨ͠ઃఆͰ͍͍͔ܧଓతͳϞχλϦϯά͕ඞཁɻ • ಛʹɺϝϞϦͷಈ࣌ؒಈ͔͞ͳ͍ͱΘ͔Βͳ͍͜ͱ͋Δɻ • Wordpressɺཧը໘Λ্ཱͪ͛ΔͱΑΓϝϞϦΛফඅ͢Δɻ • ͨͩ୯ʹӡ༻͍ͯͯͩ͠Ίɻ͍Ζ͍ΖͳγφϦΦΛࢼ͢ɻ © Yuichiro Saito (koemu), 2017 29
·ͱΊ • php-fpmΛσϑΥϧτͰ͏͜ͱ͔Β٫ͯ͠ΈΑ͏ • php-fpmͷϓϩηεCPUίΞ*2͘Β͍͕·ͣ҆ • ଌΔͱ͖topΛΈͳ͕ΒΔ͜ͱ • ͪͳΈʹApache+mod_phpͰಉ͡ख๏͕͑·͢ ©
Yuichiro Saito (koemu), 2017 30