Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
difference-between-nginx-and-apache
Search
hiroaki
July 25, 2022
94
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
difference-between-nginx-and-apache
hiroaki
July 25, 2022
More Decks by hiroaki
See All by hiroaki
leadership-that-endures-book-lt
hiroaki_u
0
36
プロダクト負債に立ち向かう
hiroaki_u
2
2.1k
pdm_vibe_coding_fail.pdf
hiroaki_u
0
220
Communication with Ubiquitous Language
hiroaki_u
0
120
how to determine architecture
hiroaki_u
1
300
the-concept-of-product-creation-learned-in-startup-science
hiroaki_u
0
190
what-is-container
hiroaki_u
1
120
CI_CD_by_Code_Brothers_by_AWS
hiroaki_u
0
62
think of study
hiroaki_u
1
120
Featured
See All Featured
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
520
SEO for Brand Visibility & Recognition
aleyda
0
4.7k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.6k
Design in an AI World
tapps
1
320
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
500
Six Lessons from altMBA
skipperchong
29
4.5k
What's in a price? How to price your products and services
michaelherold
247
13k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
500
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
350
Transcript
Nginx & Apache 何が違うのか? hiroaki
Who am I ? 名前:hiroaki 技術:PHP/ Laravel, AWS 年齢:27歳 歴 :11ヶ月半
そもそもNginxとApacheって何?
Nginx Apache Webサーバー 例えば、Webページを返してくれる
そもそもなんでNginxとApache?
2021年12月Webサーバシェア Nginx (32.9%) Apache (31.6%) https://news.mynavi.jp/techplus/article/20211203-2211535/ 引用『TECH+ マイナビニュースより』
Nginx & Apache 何が違うのか?
Nginxの方が 同時大量接続に対応できる
ポイントは C10K(Client 10,000)問題 「 ハードウェアの性能上は問題がなくても,あまりにもク ライアントの数が多くなるとサーバがパンクする問題の こと」をC10K問題と定義しています。 https://gihyo.jp/dev/clip/01/orangenews/vol38/0006 『引用:技術評論者ブログより』
そもそものプログラム処理のお話 スレッド1 プロセス1 コア CPU メモリ スレッド2 プロセス2 スレッド1 コア
コア
処理が多くなると。。。 コア CPU メモリ コア コア ・・・ 処理待ち
・そもそもプロセス数に上限がある ・コンテキストスイッチに負荷がかかる プロセスが多くなることは何が問題? https://knowledge.sakura.ad.jp/24148/ 『引用:さくらのナレッジより』 ・ファイルディスクリプタの上限に達する
Apacheの処理の種類は大きく2つ preforkモデル workerモデル ※event駆動モデルは一旦置いてます コントローラープ ロセス 子プロセス 子プロセス 子プロセス コントローラープ
ロセス
accept() read() write() TCP接続をOSから受け取る クライアントから送信されるリクエストを読み込む プロセス2 スレッド1 クライアントにレスポンスを送信する ~~~ HTTPヘッダの解析やコンテンツ作成~~~
~~~ ログを取る等様々な処理 ~~~ HTTPの場合のスレッドをざっくり
コントローラープ ロセス 子プロセス 子プロセス 子プロセス preforkモデル プロセス数 = 接続数(スレッドは1つ) アクセス
preforkモデル スクリプト言語が組み込める メモリの使用効率が悪い 処理速度がworkerに比べて速い CPU負荷が高い コンテキストスイッチのオーバーヘッドが増加
workerモデル コントローラープ ロセス アクセス 1つのスレッドにつき、1つの接続
workerモデル スクリプト言語が組み込めない メモリがpreforkより効率的 コンテキストスイッチのオーバーヘッドが増加
Apacheは接続の分だけ、 スレッドやプロセスが増えてしまう ではNginxは? プロセスの数が限定されている ※大体CPUのコアの数です。
1つのプロセスが複数のアクセスを同時処理 マスタープロセス ワーカープロセス ワーカープロセス ワーカープロセス
ポイントはイベント駆動&I/Oの仕組み accept() read() write() 終わったから次 終わったから次
処理中のブロックがない accept() read() write() 終わったから次 終わったから次 accept() read() 終わるまでこっち ①
② ① ②
Nginxの特徴 処理が速い(軽量) 大量のアクセスを処理することが可能 重たい処理が苦手 (重たい処理の場合プロセスがブロックされてしまうみたいです)
Nginxはロードバランサーや リバースプロキシとしても利用できる
ApacheとNginxを比較 ・軽い処理が得意 ・重たい処理も可能 Nginx Apache ・大量処理が得意 ・大量処理は苦手 ・開発元が営利企業 ・開発元がコミュニティ ・イベント駆動
・マルチスレッド (orプロセス) どちらもオープンソース
References ・C10K問題 https://gihyo.jp/dev/clip/01/orangenews/vol38/0006 Books Web Sites ・Nginx 実践入門 ・HTTP Serverのプロセス構造
http://itdoc.hitachi.co.jp/manuals/link/cosmi_v0950/03Y1830D/EY180028.HTM ・Apache/Nginx https://milestone-of-se.nesuke.com/sv-basic/linux-basic/apache-mpm-prefork-worker-event/ ・プロセス/スレッド https://shinpeim.github.io/process-book/002.md/ https://knowledge.sakura.ad.jp/24148/ https://openstandia.jp/pdf/140228_osc_seminar_ssof8.pdf etc.
ご清聴ありがとうございました。