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
560
実例で学ぶ画像最適化集 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.1k
メルカリのデータ分析基盤 / mercari data analysis infrastructure
cubicdaiya
11
11k
On-call Engineering
cubicdaiya
8
6.5k
Other Decks in Technology
See All in Technology
「視座」の上げ方が成人発達理論にわかりやすくまとまってた / think_ perspective_hidden_dimensions
shuzon
2
4.1k
小規模に始めるデータメッシュとデータガバナンスの実践
kimujun
3
590
[JAWS-UG金沢支部×コンテナ支部合同企画]コンテナとは何か
furuton
3
260
生成AIと知識グラフの相互利用に基づく文書解析
koujikozaki
1
140
ガチ勢によるPipeCD運用大全〜滑らかなCI/CDを添えて〜 / ai-pipecd-encyclopedia
cyberagentdevelopers
PRO
3
210
MAMを軸とした動画ハンドリングにおけるAI活用前提の整備と次世代ビジョン / abema-ai-mam
cyberagentdevelopers
PRO
1
110
ガバメントクラウド先行事業中間報告を読み解く
sugiim
1
1.4k
【技術書典17】OpenFOAM(自宅で極める流体解析)2次元円柱まわりの流れ
kamakiri1225
0
210
とあるユーザー企業におけるリスクベースで考えるセキュリティ業務のお話し
4su_para
3
320
新R25、乃木坂46 Mobileなどのファンビジネスを支えるマルチテナンシーなプラットフォームの全体像 / cam-multi-cloud
cyberagentdevelopers
PRO
1
130
新卒1年目が挑む!生成AI × マルチエージェントで実現する次世代オンボーディング / operation-ai-onboarding
cyberagentdevelopers
PRO
1
170
Amazon FSx for NetApp ONTAPを利用するにあたっての要件整理と設計のポイント
non97
1
160
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Designing for humans not robots
tammielis
249
25k
The Cult of Friendly URLs
andyhume
78
6k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Code Review Best Practice
trishagee
64
17k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
A Tale of Four Properties
chriscoyier
156
23k
A designer walks into a library…
pauljervisheath
202
24k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
107
49k
Happy Clients
brianwarren
97
6.7k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
43
6.6k
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)Φϓγϣϯͷ༗ޮԽ w -JOVYͩͱ5$1@$03,Φϓγϣϯ w TFOEpMF༗ޮ࣌ͷΈར༻Մೳ UDQ@OPQVTIPO
TCP_NODELAYͱTCP_NOPUSH w ͜ͷೋͭຊདྷ૬͢Δಈ࡞Λ͢Δ w 5$1@/0%&-": w ύέοτΛͰ͖Δ͚ͩଈ࠲ʹૹ৴͢Δ w 5$1@/0164) w
ύέοτΛͰ͖Δ͚ͩ·ͱΊͯૹ৴͢Δ w OHJOY྆ํΈ߹ΘͤՄೳ ཁTFOEpMF w ·ͣɺύέοτૹ৴Λ5$1@/0164)ͰԆͤ͞Δ 5$1@/0164)ΛPGG5$1@/0%&-":Ͱϑϥογϡ
listen ύϥϝʔλଟ͗͢
ύϑΥʔϚϯεʹӨڹ͢Δ ओͳlistenύϥϝʔλ w TQEZ41%:Λ༗ޮʹ͢Δ w CBDLMPH/MJTUFOͷόοΫϩά w OFUDPSFTPNBYDPOOΕͣʹ w GBTUPQFO/5$1'BTU0QFO
w SFVTFQPSU40@3&64&1035Λ༗ޮʹ͢Δ
nginxͱh2oͷϕϯνϚʔΫ w DYMBSHFPO&$ w IPBMQIB w OHJOY w XSLͰϕϯνϚʔΫ w
XSLDUEIUUQ
h2o.conf(࠷దԽલ) MJTUFO IPTUT QBUIT pMFEJSVTSMPDBMOHJOYIUNM
h2o.conf(࠷దԽޙ) OVNUISFBET OVNOBNFSFTPMVUJPOUISFBET NBYDPOOFDUJPOT MJTUFO IPTUT QBUIT pMFEJSVTSMPDBMOHJOYIUNM
nginx.conf(࠷దԽલ) XPSLFS@QSPDFTTFT FWFOUT\ XPSLFS@DPOOFDUJPOT ^ IUUQ\ JODMVEFNJNFUZQFT EFGB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ΫϥΠΞϯτ͕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 σϑΥϧτઃఆׂͱอकత ແޮͳͷ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