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 - BuildStuff Ukraine 2019
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Андрей Листочкин (Andrey Listochkin)
November 18, 2019
Programming
70
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Server Memory - BuildStuff Ukraine 2019
Андрей Листочкин (Andrey Listochkin)
November 18, 2019
More Decks by Андрей Листочкин (Andrey Listochkin)
See All by Андрей Листочкин (Andrey Listochkin)
Everybody Stand Back! I Know Regular Expressions
listochkin
0
220
Command-line scripting with Rust. Wait, what?!
listochkin
0
420
Server Memory - Chernivtsi JS 2019
listochkin
1
160
10 Years Later
listochkin
0
390
Managing Managers - DevTalks iHUB
listochkin
0
82
Time, Numbers, Text
listochkin
1
650
Software Licensing: A Minefield Guide
listochkin
0
180
We Make Bots. For Real
listochkin
0
460
Devops for A Busy Developer - XP Days 2016
listochkin
0
190
Other Decks in Programming
See All in Programming
IBM Bobを活用したレガシーアプリの最新化
oniak3ibm
PRO
1
210
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
280
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
12
5.8k
Webフレームワークの ベンチマークについて
yusukebe
0
180
AIだと陥りがちなJakarta EE最新技術への移行時の落とし穴と解決策
tnagao7
0
120
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
920
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
230
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
5.4k
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
140
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
350k
依存関係から依存物へ―Dependencyという言葉の歴史をひも解く
j_lee
0
130
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
7
1.4k
Featured
See All Featured
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.3k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
330
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
580
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
170
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.1k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
150
Crafting Experiences
bethany
1
190
Deep Space Network (abreviated)
tonyrice
0
210
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
330
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.2k
How to Talk to Developers About Accessibility
jct
2
240
Transcript
None
@listochkin + fb.com/tektonna
Memory Management
A bit deeper than most talks on similar subject
None
CPU Caches RAM Swap Disk Network
Operating System
None
Pages 4k
Virtual
3 processes [0 … ∞] [0 … ∞] [0 …
∞]
Allocate page But not really
None
malloc calloc realloc
None
pointer = malloc(size)
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
if ( … ) { let a = … …
}
C++: std::shared_ptr
None
Optimizations
Delayed Counting
Don’t count local references
function (user) { let email = user.email; … … }
Delayed deallocation
Reference Cycles
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” Supervision Trees
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 Default Choice
Roots?
Constants Global variables Local variables Closures Thread-locals ...
Mark & Sweep vs Mark-Compact
None
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
Incremental Marking
3-colored algorithm by Dijkstra™
None
None
None
None
None
What is a barrier? if statement
CPU branch predictor
Parallel marking
None
Lazy Sweep
Generational
Temporary data data.filter( … ).map( … ) log(`… ${data}`) JSON.stringify(result)
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
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
Firefox Run GC in background tabs first instead of current
tab
Chrome Animation frame
OS Pages pre-forked processes malloc zones GC Regions Remembered Sets
Barriers
None
None
Practical Advice
Memory Leaks Multiprocess Deploys
Throughput ⇔ Latency
Throughput Batch jobs Queues
Latency Requests Messaging
Keep different types of workloads in different processes
More memory Swap with SSDs
Experiment and measure
@listochkin Hire Me!