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
320
ImageFluxを利用した画像配信の最適化 / ImageFlux meetup 201801
cubicdaiya
0
2.8k
Building high performance push notification server in Go
cubicdaiya
5
3.2k
メルカリのデータ分析基盤 / mercari data analysis infrastructure
cubicdaiya
11
11k
On-call Engineering
cubicdaiya
8
6.5k
Other Decks in Technology
See All in Technology
iOSチームとAndroidチームでブランチ運用が違ったので整理してます
sansantech
PRO
0
150
オープンソースAIとは何か? --「オープンソースAIの定義 v1.0」詳細解説
shujisado
9
1.1k
SRE×AIOpsを始めよう!GuardDutyによるお手軽脅威検出
amixedcolor
0
170
TypeScript、上達の瞬間
sadnessojisan
46
13k
Why App Signing Matters for Your Android Apps - Android Bangkok Conference 2024
akexorcist
0
130
ノーコードデータ分析ツールで体験する時系列データ分析超入門
negi111111
0
420
開発生産性を上げながらビジネスも30倍成長させてきたチームの姿
kamina_zzz
2
1.7k
TanStack Routerに移行するのかい しないのかい、どっちなんだい! / Are you going to migrate to TanStack Router or not? Which one is it?
kaminashi
0
600
Lambdaと地方とコミュニティ
miu_crescent
2
370
OCI Security サービス 概要
oracle4engineer
PRO
0
6.5k
Flutterによる 効率的なAndroid・iOS・Webアプリケーション開発の事例
recruitengineers
PRO
0
120
心が動くエンジニアリング ── 私が夢中になる理由
16bitidol
0
100
Featured
See All Featured
The World Runs on Bad Software
bkeepers
PRO
65
11k
A designer walks into a library…
pauljervisheath
204
24k
Documentation Writing (for coders)
carmenintech
65
4.4k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Facilitating Awesome Meetings
lara
50
6.1k
Raft: Consensus for Rubyists
vanstee
136
6.6k
How to Ace a Technical Interview
jacobian
276
23k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
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@OPEF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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 OHJOYEPDVNFOU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