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
100
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
140
Ruby 2.0 upcoming changes
gnufied
0
99
Building RESTful APIs
gnufied
13
820
Ruby introduction for newbies
gnufied
8
1k
Other Decks in Programming
See All in Programming
What We Can Learn From OSS
inouehi
0
420
educure_カリキュラム生操作マニュアル.pdf
linew_official
0
750
大規模UIKitベースアプリへのTCAの段階的導入/gradual-adoption-of-tca-in-a-large-scale-uikit-based-app
takehilo
1
120
Azure OpenAI Serviceのプロンプトエンジニアリング入門
tomokusaba
3
680
雑に思考を整理する技術と効能
konifar
58
29k
Node.js v22 で変わること
yosuke_furukawa
PRO
9
3.1k
PostmanでAPIの動作確認が楽になった話
h455h1
0
170
GitHub Actionsで泣かないためにやっておきたい設定 / Recommended GHA settings to avoid crying
pinkumohikan
3
530
サイコロで理解する統計的仮説検定の考え方
tatamiya
4
920
GitHub Copilotのススメ
marcy731
1
200
Amazon SQSコンシューマー疎結合への旅 - 出張! #DevelopersIO IT技術ブログの中の人が語る勉強会 #3
quiver
0
260
Anthropic Cookbook のおすすめレシピ
schroneko
7
910
Featured
See All Featured
Six Lessons from altMBA
skipperchong
21
3k
Agile that works and the tools we love
rasmusluckow
325
20k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
227
16k
How to train your dragon (web standard)
notwaldorf
73
5.2k
A Philosophy of Restraint
colly
197
16k
Into the Great Unknown - MozCon
thekraken
10
990
Building a Scalable Design System with Sketch
lauravandoore
456
32k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
352
28k
Building Your Own Lightsaber
phodgson
99
5.7k
Building Better People: How to give real-time feedback that sticks.
wjessup
355
18k
Docker and Python
trallard
34
2.7k
The Language of Interfaces
destraynor
151
23k
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