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
サイバー攻撃を想定したセキュリティガイドライン 策定とASM及びCNAPPの活用方法
syoshie
3
1.3k
podman_update_2024-12
orimanabu
1
280
第3回Snowflake女子会_LT登壇資料(合成データ)_Taro_CCCMK
tarotaro0129
0
200
10個のフィルタをAXI4-Streamでつなげてみた
marsee101
0
170
Oracle Cloud Infrastructure:2024年12月度サービス・アップデート
oracle4engineer
PRO
0
210
多領域インシデントマネジメントへの挑戦:ハードウェアとソフトウェアの融合が生む課題/Challenge to multidisciplinary incident management: Issues created by the fusion of hardware and software
bitkey
PRO
2
110
小学3年生夏休みの自由研究「夏休みに Copilot で遊んでみた」
taichinakamura
0
170
re:Invent 2024 Innovation Talks(NET201)で語られた大切なこと
shotashiratori
0
320
MLOps の現場から
asei
7
650
NW-JAWS #14 re:Invent 2024(予選落ち含)で 発表された推しアップデートについて
nagisa53
0
270
継続的にアウトカムを生み出し ビジネスにつなげる、 戦略と運営に対するタイミーのQUEST(探求)
zigorou
0
600
【re:Invent 2024 アプデ】 Prompt Routing の紹介
champ
0
150
Featured
See All Featured
Testing 201, or: Great Expectations
jmmastey
40
7.1k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Designing for humans not robots
tammielis
250
25k
Typedesign – Prime Four
hannesfritz
40
2.4k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Documentation Writing (for coders)
carmenintech
66
4.5k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
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 EFGBVMU@UZQFBQQMJDBUJPOPDUFUTUSFBN BDDFTT@MPHPGG TFOEpMFPO
LFFQBMJWF@UJNFPVU TFSWFS\ MJT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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͍Ζ͍Ζͱ࠷ద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