Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Curious Case of Ruby's memory
Search
Hemant Kumar
September 30, 2014
Programming
180
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
140
Building RESTful APIs
gnufied
13
1.2k
Ruby introduction for newbies
gnufied
8
1.1k
Other Decks in Programming
See All in Programming
数年滞っていたダークモード対応をおよそ2週間で完了させる
chigichan24
0
700
ALB ログから Trace を気合で繋げる技術
fohte
7
880
GKE アップグレード前に知っておきたい Blue/Green と PDB の関係
stkk
0
160
20260828_品質と開発生産性を両立させる、AI時代のE2Eテストの考え方
magicpod
0
180
Foundry Localでエージェント開発
seosoft
0
160
WebMCP Challenge に星空観察アプリで参加した話
okajun35
0
120
市販E-Readerを乗っ取れ 〜Embedded Swiftで電子ペーパーガジェットを制御する〜
trickart
0
160
AWS Step Functions 大規模並列の壁を越える / jaws-sonic-2026-niigata-step-functions
kasacchiful
PRO
1
430
新卒PdEのリアル
ryu1013
1
480
tsc.rip を支える技術 / Kyoto.なんか #8
susisu
0
4.4k
コンパウンドプロダクト開発のためのローカルプロセスマネージャー再発明 #layerxgo
izumin5210
0
660
思考垂れ流し開発 ~音声入力 × AIエージェント × 開発ハーネスによる試行錯誤~
npostring
0
1.1k
Featured
See All Featured
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
320
How Software Deployment tools have changed in the past 20 years
geshan
1
34k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
270
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
930
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
450
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
270
My Coaching Mixtape
mlcsv
0
310
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.8k
Visualization
eitanlees
152
17k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
590
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