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
Hemant Kumar
September 30, 2014
Programming
0
120
Curious Case of Ruby's memory
A roundup of Ruby memory profiling and GC
Hemant Kumar
September 30, 2014
Tweet
Share
More Decks by Hemant Kumar
See All by Hemant Kumar
introduction to dtrace
gnufied
3
160
Ruby 2.0 upcoming changes
gnufied
0
100
Building RESTful APIs
gnufied
13
880
Ruby introduction for newbies
gnufied
8
1k
Other Decks in Programming
See All in Programming
Piniaの現状と今後
waka292
5
1.5k
僕がつくった48個のWebサービス達
yusukebe
18
17k
ECSのサービス間通信 4つの方法を比較する 〜Canary,Blue/Greenも添えて〜
tkikuc
11
2.3k
Android 15 でアクションバー表示時にステータスバーが白くなってしまう問題
tonionagauzzi
0
140
Vaporモードを大規模サービスに最速導入して学びを共有する
kazukishimamoto
4
4.4k
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
9
1k
Kubernetes for Data Engineers: Building Scalable, Reliable Data Pipelines
sucitw
1
200
デプロイを任されたので、教わった通りにデプロイしたら障害になった件 ~俺のやらかしを越えてゆけ~
techouse
52
32k
約9000個の自動テストの 時間を50分->10分に短縮 Flakyテストを1%以下に抑えた話
hatsu38
24
11k
go.mod、DockerfileやCI設定に分散しがちなGoのバージョンをまとめて管理する / Go Connect #3
arthur1
10
2.4k
[PyCon Korea 2024 Keynote] 커뮤니티와 파이썬, 그리고 우리
beomi
0
110
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
0
160
Featured
See All Featured
It's Worth the Effort
3n
183
27k
Adopting Sorbet at Scale
ufuk
73
9k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
167
49k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
3
370
Fontdeck: Realign not Redesign
paulrobertlloyd
81
5.2k
Intergalactic Javascript Robots from Outer Space
tanoku
268
27k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
355
29k
Building Better People: How to give real-time feedback that sticks.
wjessup
363
19k
4 Signs Your Business is Dying
shpigford
180
21k
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