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
Scaling NodeJS beyond the ordinary
Search
Abhinav Rastogi
March 02, 2018
Technology
0
290
Scaling NodeJS beyond the ordinary
These are the slides to accompany the talk I gave at JSConf Iceland 2018.
Abhinav Rastogi
March 02, 2018
Tweet
Share
More Decks by Abhinav Rastogi
See All by Abhinav Rastogi
Next Gen Web: Scaling Progressive Web Apps
abhinavrastogi
57
14k
Other Decks in Technology
See All in Technology
マイクロサービスにおける容易なトランザクション管理に向けて
scalar
0
130
Oracle Cloud Infrastructure:2024年12月度サービス・アップデート
oracle4engineer
PRO
0
190
フロントエンド設計にモブ設計を導入してみた / 20241212_cloudsign_TechFrontMeetup
bengo4com
0
1.9k
AWS re:Invent 2024で発表された コードを書く開発者向け機能について
maruto
0
190
TSKaigi 2024 の登壇から広がったコミュニティ活動について
tsukuha
0
160
How to be an AWS Community Builder | 君もAWS Community Builderになろう!〜2024 冬 CB募集直前対策編?!〜
coosuke
PRO
2
2.8k
10個のフィルタをAXI4-Streamでつなげてみた
marsee101
0
170
20241220_S3 tablesの使い方を検証してみた
handy
4
570
サイバー攻撃を想定したセキュリティガイドライン 策定とASM及びCNAPPの活用方法
syoshie
3
1.3k
終了の危機にあった15年続くWebサービスを全力で存続させる - phpcon2024
yositosi
14
12k
権威ドキュメントで振り返る2024 #年忘れセキュリティ2024
hirotomotaguchi
2
750
社外コミュニティで学び社内に活かす共に学ぶプロジェクトの実践/backlogworld2024
nishiuma
0
260
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
51
7.3k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.3k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Navigating Team Friction
lara
183
15k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Unsuck your backbone
ammeep
669
57k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Rails Girls Zürich Keynote
gr2m
94
13k
It's Worth the Effort
3n
183
28k
Transcript
Scaling NodeJS Beyond the ordinary Abhinav Rastogi Lead UI Engineer
_abhinavrastogi
None
150M Registered Users 500K Phones sold in 15 seconds 200M
Visits over 5 days during annual sale event
– Andre Bondi “Scalability is the capability of a system
to handle a growing amount of work, or its potential to be enlarged to accommodate that growth.”
Why should it concern the JS community?
Why should it concern the JS community? • JS is
running on servers now • Failure is shifting to application code • Failure is better handled by devs
Types of Scalability x y z Add more machines Add
more resources Application layer
Horizontal Scaling
Horizontal Scaling Machine Node API
Horizontal Scaling Machine Node API Machine Node ELB
Vertical Scaling
Vertical Scaling Machine Node API
Vertical Scaling Machine Node API Node ??
Application Layer Optimisations
The Optimisation Cycle Load Test Find Bottleneck Fix Issues
network, cpu, memory, disk
network bandwidth
network bandwidth
1000 kb per page 100 rps per machine 100 machines
= 10gbps
compression
const app = express() app.use(compression)
co-hosted nginx
co-hosted nginx Machine Node Node PM2 nginx API ELB
network profiling
netstat / ss lsof watch
everything is a file in unix!
ulimit
ulimit core file size (blocks, -c) 0 file size (blocks,
-f) unlimited pending signals (-i) 32767 max locked memory (kbytes, -l) 32 max memory size (kbytes, -m) unlimited open files (-n) 1024 max user processes (-u) 50
increase the limits / reduce the usage
keep-alive header
keep-alive header Object.assign(headers, { 'Connection': 'keep-alive', 'Keep-Alive': 'timeout=200' });
connection pooling
connection pooling const http = require('http'); fetch(url, { agent: new
http.Agent({ keepAlive: true, maxSockets: 24 }) });
ephemeral ports
tcp connection states
tcp connection states source: http://cnp3book.info.ucl.ac.be/1st/html/transport/transport.html
tcp connection states
cpu
cpu profiling
node --prof app.js
import crypto from 'crypto'; app.get('/auth', (req, res) => { const
hash = crypto.pbkdf2Sync(password, users[username].salt, 100, 512); if (users[username].hash.toString() === hash.toString()) { res.sendStatus(200); } else { res.sendStatus(401); } });
[Summary]: ticks total nonlib name 79 0.2% 0.2% JavaScript 36703
97.2% 99.2% C++ 7 0.0% 0.0% GC 767 2.0% Shared libraries 215 0.6% Unaccounted
[C++]: ticks total nonlib name 19557 51.8% 52.9% node::crypto::PBKDF2(v8) 4510
11.9% 12.2% _sha1_block_data_order 3165 8.4% 8.6% _malloc_zone_malloc
None
$ npm install -g 0x $ 0x app.js
None
disk
memory
real-time monitoring
load, profile, fix, repeat!
thank you @_abhinavrastogi http://tiny.cc/scalingnodejs