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
Server Memory - Chernivtsi JS 2019
Search
Андрей Листочкин (Andrey Listochkin)
June 22, 2019
Programming
1
130
Server Memory - Chernivtsi JS 2019
Андрей Листочкин (Andrey Listochkin)
June 22, 2019
Tweet
Share
More Decks by Андрей Листочкин (Andrey Listochkin)
See All by Андрей Листочкин (Andrey Listochkin)
Everybody Stand Back! I Know Regular Expressions
listochkin
0
150
Command-line scripting with Rust. Wait, what?!
listochkin
0
320
Server Memory - BuildStuff Ukraine 2019
listochkin
0
30
10 Years Later
listochkin
0
350
Managing Managers - DevTalks iHUB
listochkin
0
42
Time, Numbers, Text
listochkin
1
560
Software Licensing: A Minefield Guide
listochkin
0
130
We Make Bots. For Real
listochkin
0
400
Devops for A Busy Developer - XP Days 2016
listochkin
0
170
Other Decks in Programming
See All in Programming
機能が複雑化しても 頼りになる FactoryBotの話
tamikof
1
260
Datadog Workflow Automation で圧倒的価値提供
showwin
1
330
Boos Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
770
コードを読んで理解するko build
bells17
1
120
コミュニティ駆動 AWS CDK ライブラリ「Open Constructs Library」 / community-cdk-library
gotok365
2
260
Lambdaの監視、できてますか?Datadogを用いてLambdaを見守ろう
nealle
2
840
はじめてのIssueOps - GitHub Actionsで実現するコメント駆動オペレーション
tmknom
5
1.3k
Serverless Rust: Your Low-Risk Entry Point to Rust in Production (and the benefits are huge)
lmammino
1
170
Better Code Design in PHP
afilina
0
190
15分で学ぶDuckDBの可愛い使い方 DuckDBの最近の更新
notrogue
3
870
データベースのオペレーターであるCloudNativePGがStatefulSetを使わない理由に迫る
nnaka2992
0
250
クリーンアーキテクチャから見る依存の向きの大切さ
shimabox
5
1.2k
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.2k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Bash Introduction
62gerente
611
210k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
40
2k
Stop Working from a Prison Cell
hatefulcrawdad
268
20k
How to Ace a Technical Interview
jacobian
276
23k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
Practical Orchestrator
shlominoach
186
10k
A Tale of Four Properties
chriscoyier
158
23k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
Music & Morning Musume
bryan
46
6.4k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
Transcript
None
@listochkin fb.com/tektonna
Not a JavaScript talk
No CSS No frameworks No Node
A bit deeper than most talks on similar subject
None
How programming languages work
Just-in-time compilers Garbage Collection
Memory Management
Server runs our programs
CPU Caches RAM Swap Disk Network
Operating System
None
Pages
4k
Virtual
2 processes [0 … ∞]
Oh, I got a pointer at 4096 What’s at 4095?
Page fault
Allocate page But not really
Once you start writing to it
not 4k?
None
None
malloc
None
malloc me some memory
a pointer
free(pointer)
malloc malloc malloc free malloc free free
Forget to free Free the wrong pointer Read from unallocated
memory
Can we do better?
Reference Counting
None
const players = [ … ] players.forEach(p => makeMove(p))
a = … doX(a) yield a
scope
if ( … ) { let a = … …
}
None
C++: std::shared_ptr
None
Optimizations
Delayed Counting
Don’t count local references
function (user) { let email = user.email; … … }
Delayed deallocation
Cycle Collector
None
None
Compile time ref-counting
Several types of pointers
Ownership
Forbids cycles by forbidding several owning references at the same
time
None
None
None
Perl 1987 - today Python 1991 - 2001 PHP 1994
- 2009
Multiprocess deploys
fork
Copy on Write
Worker Accepts requests As memory use raises: Stop accepting requests
Complete in-flight requests Terminate
Master Keep track on workers Start new workers Signal them
to terminate when memory pressure is high
“Pre-fork”
Load the framework Load app code Run full GC Start
forking process to accept requests
None
None
“Processes”
Tracing GC
1959 60 years ago
Start at Root references Follow all references Build a live
objects tree Delete all objects not part of the tree
Ruby Java JavaScript Lua Go
Roots?
Constants Global variables Local variables Closures Thread-locals ...
Mark & Sweep vs Mark-Compact
None
Can you move objects after mark?
Team Sweep: Go Ruby* Lua Embedded JS engines Erlang
Pros: Pointers don’t change Native extensions Easier to implement
Team Compact: Java JavaScript Ruby* Haskell
Pros: Less memory fragmentation over time Cons: Harder Takes longer
to do a GC
Mark all memory
None
Incremental Marking
3-colored algorithm by Dijkstra™
None
None
None
None
None
What is a barrier? if statement
else branch is very rare CPU branch predictor
Parallel marking
None
None
Lazy Sweep
Generational
Temporary data
Major vs Minor GC
Pointers from Old objects to new objects
Remembered Set
Major GC Scan roots only Bigger object graph
Minor GC Scan roots + RS Small object graph
None
Modern GCs are hybrid
None
None
C-extensions
Can’t move objects if their references are passed to an
extension
Can’t add WB
RGen GC
2 types of objects WB-protected WB-unprotected
WBu are never OldGen
OldGen -> WBu WBu to Remembered Set
Mark WBus on every minor GC
1 stw to mark all WBu in RS
None
None
Adding compaction for WBp
None
V8
Minor GC Parallel
Major Parallel marking Parallel / Concurrent Compact || Sweep
None
When to trigger GC?
Out-of-Bounds GC
request? Minor GCs response is sent? Major GC
Firefox Run GC in background tabs first instead of current
tab
Chrome Animation frame
Walking the memory
Cache locality
GPU
OS Pages pre-forked processes malloc zones GC Pages Remembered Sets
Barriers
None
None