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
nginxのパフォーマンスチューニング
Search
Tatsuhiko Kubo
June 02, 2015
Technology
70
19k
nginxのパフォーマンスチューニング
@shibuya.pm#17
Tatsuhiko Kubo
June 02, 2015
Tweet
Share
More Decks by Tatsuhiko Kubo
See All by Tatsuhiko Kubo
Handling a tremendous amount of images with Fastly / Yamagoya Traverse 2020
cubicdaiya
2
1.4k
System Integration with Fastly
cubicdaiya
0
570
実例で学ぶ画像最適化集 with ImageFlux / ImageFlux meetup#2
cubicdaiya
4
19k
Software Engineer, Infrastructure
cubicdaiya
4
3.1k
High Performance Count Up!
cubicdaiya
0
330
ImageFluxを利用した画像配信の最適化 / ImageFlux meetup 201801
cubicdaiya
0
2.9k
Building high performance push notification server in Go
cubicdaiya
5
3.2k
メルカリのデータ分析基盤 / mercari data analysis infrastructure
cubicdaiya
11
12k
On-call Engineering
cubicdaiya
8
6.5k
Other Decks in Technology
See All in Technology
.NET 9 のパフォーマンス改善
nenonaninu
0
560
アップデート紹介:AWS Data Transfer Terminal
stknohg
PRO
0
170
プロダクト開発を加速させるためのQA文化の築き方 / How to build QA culture to accelerate product development
mii3king
1
260
サーバレスアプリ開発者向けアップデートをキャッチアップしてきた #AWSreInvent #regrowth_fuk
drumnistnakano
0
190
サイバー攻撃を想定したセキュリティガイドライン 策定とASM及びCNAPPの活用方法
syoshie
3
1.2k
サイボウズフロントエンドエキスパートチームについて / FrontendExpert Team
cybozuinsideout
PRO
5
38k
How to be an AWS Community Builder | 君もAWS Community Builderになろう!〜2024 冬 CB募集直前対策編?!〜
coosuke
PRO
2
2.8k
OpenShift Virtualizationのネットワーク構成を真剣に考えてみた/OpenShift Virtualization's Network Configuration
tnk4on
0
130
kargoの魅力について伝える
magisystem0408
0
200
AI時代のデータセンターネットワーク
lycorptech_jp
PRO
1
280
Fanstaの1年を大解剖! 一人SREはどこまでできるのか!?
syossan27
2
160
KubeCon NA 2024 Recap: How to Move from Ingress to Gateway API with Minimal Hassle
ysakotch
0
200
Featured
See All Featured
Testing 201, or: Great Expectations
jmmastey
40
7.1k
A Tale of Four Properties
chriscoyier
157
23k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
510
Building Adaptive Systems
keathley
38
2.3k
Facilitating Awesome Meetings
lara
50
6.1k
Adopting Sorbet at Scale
ufuk
73
9.1k
Typedesign – Prime Four
hannesfritz
40
2.4k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Embracing the Ebb and Flow
colly
84
4.5k
How GitHub (no longer) Works
holman
311
140k
It's Worth the Effort
3n
183
28k
Done Done
chrislema
181
16k
Transcript
nginxͷύϑΥʔϚϯενϡʔχϯά Tatsuhiko Kubo@cubicdaiya Shibuya.pm#17@2015/06/02
@cubicdaiya / Tatsuhiko Kubo w 4PGUXBSF&OHJOFFSJO*OGSBTUSVDUVSF &OHJOFFSJOH!.FSDBSJ *OD w "VUIPSPGOHJOYCVJME
w OHJOYSEQBSUZNPEVMFEFWFMPQFS w OHY@TNBMM@MJHIU OHY@EZOBNJD@VQTUSFBN FUDʜ w 'BWPSJUFT(P $ -VB OHJOY OHY@MVB
ੲnginxͷಛूهࣄΛॻ͖·ͨ͠
mozaic.fm#18ʹήετग़ԋ͠·ͨ͠ IUUQNP[BJDGN
Agenda w OHJOYͷجຊతͳνϡʔχϯά w OHJOYͱIPͷϕϯνϚʔΫ w ߲ผνϡʔχϯά w H[JQѹॖ w
όοϑΝϦϯά w )5514
nginx.conf w σϑΥϧτͩͱอकతͳઃఆ͕ଟ͍ w ͋ΒΏΔڥͰಈ࡞͢ΔΑ͏ʹߟྀ͞ΕͯΔ w σΟϨΫςΟϒͨ͘͞Μ w OHY@DPSF@NPEVMF͚ͩͰݸҎ্
core functionality w XPSLFS@QSPDFTTFT w ϫʔΧϓϩηε w XPSLFS@DPOOFDUJPOT w ϫʔΧຖͷ࠷େଓ
w XPSLFS@SMJNJU@OPpMF w ϫʔΧϓϩηε͕PQFOͰ͖ΔGEͷ࠷େ
σϑΥϧτ XPSLFS@QSPDFTTFT FWFOUT\ XPSLFS@DPOOFDUJPOT ^ XPSLFS@SMJNJU@OPpMFͷσϑΥϧτ04ґଘ
worker_processes w $16ͷίΞΛ҆ʹ w BVUPʹ͢Δͱࣗಈతʹ$16ίΞͷϫʔΧʔϓ ϩηε͕ىಈ͢Δ w ଓʹԠͯ͡େ͖͘͢Δ w $16όϯυʹͳΓͦ͏ͳΒ͞Βʹେ͖Ίʹ͢Δ
w FHOHY@TNBMM@MJHIU OHY@MVB
worker_connections w ௨ৗઍ ʙ Ͱे w ສ୯ҐͰ͍͚ͦ͏͚ͩͲͬͨ͜ͱͳ͍ w XPSLFS@QSPDFTTFTͱηοτͰߟ͑Δ w
ϓϩΩγઌͷଓؚ·ΕΔʹҙ
worker_rlimit_nofile w ϫʔΧϓϩηε͕ΦʔϓϯͰ͖ΔGEͷ࠷େ w XPSLFS@DPOOFDUJPOTΑΓ༏ઌ͞ΕΔͷͰҙ XPSLFS@SMJNJU@OPpMF
νϡʔχϯάܥσΟϨΫςΟϒ(Ұ෦) w TFOEpMF w LFFQBMJWF@UJNFPVU w PQFO@pMF@DBDIF w UDQ@OPEFMBZ w
UDQ@OPQVTI w MJTUFO
sendfile w TFOpMFγεςϜίʔϧͷ༗ޮԽ w σϑΥϧτͩͱແޮ TFOEpMFPO
keepalive_timeout w ΫϥΠΞϯτͱͷΩʔϓΞϥΠϒଓͷ λΠϜΞτ LFFQBMJWF@UJNFPVUT
open_file_cache w Ұ։͍ͨϑΝΠϧใΛΩϟογϡ w ϑΝΠϧͷGEɺαΠζɺߋ৽࣌ PQFO@pMF@DBDIFNBYJOBDUJWFT
tcp_nodelay w 5$1@/0%&-":Φϓγϣϯͷ༗ޮԽ w σϑΥϧτͰ༗ޮ w /BHMFΞϧΰϦζϜΛېࢭ UDQ@OPEFMBZPO
tcp_nopush w 5$1@/0164)Φϓγϣϯͷ༗ޮԽ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దԽޙ) XPSLFS@QSPDFTTFT FWFOUT\ XPSLFS@DPOOFDUJPOT BDDFQU@NVUFY@EFMBZNT ^ IUUQ\ JODMVEFNJNFUZQFT EFGBVMU@UZQFBQQMJDBUJPOPDUFUTUSFBN BDDFTT@MPHPGG
TFOEpMFPO PQFO@pMF@DBDIFNBYJOBDUJWFT UDQ@OPQVTIPO LFFQBMJWF@UJNFPVU TFSWFS\ MJTUFO TFSWFS@OBNFMPDBMIPTU MPDBUJPO\ SPPUIUNM JOEFYJOEFYIUNMJOEFYIUN ^ ^ ^
nginxͱh2oͷϕϯνϚʔΫ SFRT SFRTFD XSLDUEIUUQ
nginxͱgzipѹॖ w H[JQH[JQѹॖΛ༗ޮʹ͢Δ w H[JQ@UZQFTH[JQѹॖରͷ$POUFOU5ZQF w H[JQ@DPNQ@MFWFMH[JQͷѹॖϨϕϧ w H[JQ@TUBUJDH[JQѹॖࡁΈϑΝΠϧͷ৴ w
HVO[JQH[JQղౚ
gzipѹॖͷઃఆྫ H[JQPO H[JQ@DPNQ@MFWFM H[JQ@UZQFTUFYUDTT UFYUKBWBTDSJQU BQQMJDBUJPOKBWBTDSJQU BQQMJDBUJPOKTPO
nginxͱgzipѹॖ w ੩తίϯςϯπͷH[JQѹॖੵۃతʹ͖͢ w $16ͷΦʔόʔϔουΑΓωοτϫʔΫͷ ϨΠςϯγͷํ͕Δ͔ʹେ͖͍ w $16Ϧιʔεͷফඅྔ͕ແࢹͰ͖ͳ͍߹ w H[JQ@TUBUJDͰH[JQѹॖࡁΈϑΝΠϧΛ৴
gzip_staticͷઃఆྫ YYY DTTcKT H[͕ଘࡏͨ͠ΒͦΕΛͦͷ··৴ ΫϥΠΞϯτ͕H[JQѹॖΛαϙʔτ͍ͯ͠ͳ͍߹H[ϑΝΠϧΛల։ͯ͠৴ MPDBUJPOd = DTTcKT \ H[JQ@TUBUJDBMXBZT
HVO[JQPO ^
zopfliͰ͞Βʹѹॖ w EFqBUFޓͷѹॖΞϧΰϦζϜπʔϧ w IUUQTHJUIVCDPNHPPHMF[PQqJ w [PQqJͰѹॖͨ͠ͷHVO[JQՄೳ w ѹॖ͕ߴ͍ɺѹॖʹ͔͔Δ͕͍࣌ؒ w
ࣄલʹѹॖ͢ΔͷͰʹͳΒͳ͍
nginxͱόοϑΝϦϯά w DMJFOU@CPEZ@CVGGFS@TJ[F w QSPYZ@CVGGFS@TJ[F w QSPYZ@CVGGFST w QSPYZ@CVGGFSJOH w
QSPYZ@SFRVFTU@CVGGFSJOH w FUDʜ
όοϑΝϦϯάͷOn/Off w QSPYZ@CVGGFSJOH EFGBVMUPO w FHετϦʔϛϯά૬ͷॲཧΛ͢Δࡍʹ PGGʹ͢Δ͔ݕ౼ w QSPYZ@SFRVFTU@CVGGFSJOH
EFGBVMUPO w FHେ͖ͳϑΝΠϧͷΞοϓϩʔυ͕ൃੜ͢Δࡍ ʹPGGʹ͢Δ͔ݕ౼ ಛʹཧ༝͕ͳ͍ݶΓσϑΥϧτͰ0,
όοϑΝϦϯάͱI/O w OHJOYͷ֤όοϑΝͷαΠζൺֱతখ͞Ί w େମ,#ఔ w όοϑΝ͕Γͳ͘ͳΔͱσΟεΫʹॻ͖ग़͢ w όοϑΝαΠζΛௐPSUNQGTΛར༻
όοϑΝϦϯάͱtmpfs ϦΫΤετϘσΟͷॻ͖ग़͠ઌ DMJFOU@CPEZ@UFNQ@QBUIEFWTINDCU ϓϩΩγઌϨεϙϯεϘσΟͷॻ͖ग़͠ઌ QSPYZ@UFNQ@QBUIEFWTINQU ɾ ɾ ɾ
HTTPSؔ࿈ͷνϡʔχϯά w 5-44FTTJPO$BDIF w 5-44FTTJPO5JDLFUT w 0$414UBQMJOH w 41%: w
0QUJNJ[JOHUIF5-4SFDPSETJ[F
TLS Session Cache w 5-4ϋϯυγΣΠΫͷηογϣϯΛαʔόʹ Ωϟογϡ w OHJOYͰڞ༗ϝϞϦ্ͷอଘ͞ΕΔ w ࣍ճͷ5-4ϋϯυγΣΠΫΛলུ
TLS Session Cache with nginx TTM@TFTTJPO@DBDIFTIBSFE44-N TTM@TFTTJPO@UJNFPVUN
TLS Session Tickets w ҉߸Խͨ͠ηογϣϯ νέοτ ΛΫϥΠΞϯτ ʹ͢ w νέοτΛݩʹ5-4ηογϣϯΛ࠶։
w )5514αʔόෳͰηογϣϯΛڞ༗
TLS Session Tickets with nginx TTM@TFTTJPO@UJDLFUTPO TTM@TFTTJPO@UJDLFU@LFZFUDOHJOYTTMUJDLFULFZ
OCSP Stapling w 0$41ʹΑΔ44-ূ໌ॻͷࣦޮ֬ೝΛαʔόଆ ͰߦͬͯΩϟογϡ w ΫϥΠΞϯτଆͰΔͱ5-4ϋϯυγΣΠΫ࣌ ʹϨΠςϯγൃੜ
OCSP Stapling with nginx TTM@TUBQMJOHPO TTM@TUBQMJOH@WFSJGZPO TTM@USVTUFE@DFSUJpDBUFFUDOHJOYTTMDFSUDSU SFTPMWFSYYYYYYYYYYYYWBMJET SFTPMWFS@UJNFPVUT
SPDY with nginx MJTUFOTTMTQEZ
Optimizing the TLS-record size w 5-4ͰҰఆαΠζຖʹ௨৴༰Λ҉߸Խ͢Δ ௨শ 5-4SFDPSE w
TTM@CVGGFS@TJ[F EFGBVMUL w ,#ͩͱେ͖͗ͯ͢৽ن5$1ଓ࣌ͷ355͕૿Ճ w Ұൠతͳ8FCαΠτͳΒখ͍͞΄͏͕͍͍ w 55'# 5JNF5P'JSTU#ZUF վળʹޮՌ͋Γ TTM@CVGGFS@TJ[FL
·ͱΊ w OHJOYύϑΥʔϚϯεʹӨڹ͢ΔσΟϨΫςΟϒ ͕ͨ͘͞Μ͋Δ w σϑΥϧτઃఆׂͱอकత ແޮͳͷଟ͍ w H[JQѹॖੵۃతʹ
w όοϑΝͷαΠζͱϑΝΠϧ*0ͷؔʹҙ w )5514͍Ζ͍Ζͱ࠷దԽ߲͋Δ
ࢀߟจݙ / URL w OHJOYEPDVNFOUBUJPO w IUUQOHJOYPSHFOEPDT w 4FDVSJUZ4FSWFS4J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