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
Curious Case of Ruby's memory
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Hemant Kumar
September 30, 2014
Programming
170
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Curious Case of Ruby's memory
A roundup of Ruby memory profiling and GC
Hemant Kumar
September 30, 2014
More Decks by Hemant Kumar
See All by Hemant Kumar
introduction to dtrace
gnufied
3
200
Ruby 2.0 upcoming changes
gnufied
0
130
Building RESTful APIs
gnufied
13
1.2k
Ruby introduction for newbies
gnufied
8
1.1k
Other Decks in Programming
See All in Programming
今さら聞けないCancellationToken
htkym
0
220
Inside Stream API
skrb
1
650
net-httpのHTTP/2対応について
naruse
0
450
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
130
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
500
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.2k
Stage 3 Decorators でできること / できないこと / TSKaigi 2026
susisu
1
1.6k
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
220
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
110
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
17
6.1k
3Dシーンの圧縮
fadis
1
670
Claspは野良GASの夢をみるか
takter00
0
170
Featured
See All Featured
AI: The stuff that nobody shows you
jnunemaker
PRO
8
690
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
360
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.3k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
220
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
Amusing Abliteration
ianozsvald
1
200
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
550
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Testing 201, or: Great Expectations
jmmastey
46
8.2k
The Cult of Friendly URLs
andyhume
79
6.9k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.4k
Typedesign – Prime Four
hannesfritz
42
3.1k
Transcript
Curious case of Ruby’s memory
Garbage Collection
How it used to work
Mark and Sweep
None
Generational GC
Most objects die Young
None
active_users[user.id] = user Old gen object New object
Bug!
None
None
memcpy(RARRAY_PTR(ary)[i], src, array_len(src)) Copy into ruby array Object in old
gen
None
None
Key take aways
Don’t use low level access for Ruby DS in C
extensions, such RARRAY_PTR
If your C-ext holds ref. to a Ruby object you
need Write Barriers for taking adv. of Gen. GC.
GC Tuning via ENV variables
Part 2
Memory Profiling Ruby apps
None
Thanks to Ruby 2.1
RBKit
None
None
None
None
RBkit Team • Emil • Kashyap • Yuva • Hemant
And
http://codemancers.com
C is what Linus Torvalds wrote.
About RBKit • A low overhead Ruby Profiler built for
MRI. • Written almost completely in C.
RBKit • A Desktop application • A Ruby gem
RBKit • Gather and send all profile data via ZeroMQ
to connected client (Desktop app) • Uses msgpack as serialization format.
Advantage RBKit • ZeroMQ manages separate IO threads for sending
and receiving messages. • Msgpack serialisation is fast. • A profiler that can be used in production!
Using it ! require 'rbkit' ! Rbkit.start_profiling
RbkitApp
RbkitApp • Cross platform - Qt/C++ • Webkit/Javascript for rendering
charts. • Sqlite
Why Qt/C++? • All heavy lifting is done client side.
• Parsing and processing heap dump of millions of objects. • We can still render certain pages/data using plain HTML via Qt Webkit bridge.
Tools used • Valgrind • leaks (Try this command on
OSX now!)
RBkit Status Report • Memory Profiling works (Demo) • CPU
Profiling is in works. • Open source
RbkitApp Demo
GC tuning visualizations
RUBY_GC_HEAP_INIT_SLOTS
RUBY_GC_HEAP_GROWTH_FACTOR
Ruby Heap vs C heap • Rvalue size = 40
bytes • If Object can’t fit that size, ruby uses ruby_xmalloc() • which is wrapper around malloc()
RUBY_GC_MALLOC_LIMIT
Thank you! • https://github.com/code-mancers/rbkit • https://github.com/code-mancers/rbkit- client • http://thorstenball.com/blog/2014/03/12/ watching-understanding-ruby-2.1-garbage-
collector/ • http://tmm1.net/ruby21-rgengc/
@gnufied http://www.codemancers.com Hemant Kumar