active_users[user.id] = user
Old gen object New object
Slide 10
Slide 10 text
Bug!
Slide 11
Slide 11 text
No content
Slide 12
Slide 12 text
No content
Slide 13
Slide 13 text
memcpy(RARRAY_PTR(ary)[i], src, array_len(src))
Copy into ruby array
Object in old gen
Slide 14
Slide 14 text
No content
Slide 15
Slide 15 text
No content
Slide 16
Slide 16 text
Key take aways
Slide 17
Slide 17 text
Don’t use low level access for Ruby DS
in C extensions, such RARRAY_PTR
Slide 18
Slide 18 text
If your C-ext holds ref. to a Ruby object
you need Write Barriers for taking adv.
of Gen. GC.
Slide 19
Slide 19 text
GC Tuning via ENV
variables
Slide 20
Slide 20 text
Part 2
Slide 21
Slide 21 text
Memory Profiling Ruby
apps
Slide 22
Slide 22 text
No content
Slide 23
Slide 23 text
Thanks to Ruby 2.1
Slide 24
Slide 24 text
RBKit
Slide 25
Slide 25 text
No content
Slide 26
Slide 26 text
No content
Slide 27
Slide 27 text
No content
Slide 28
Slide 28 text
No content
Slide 29
Slide 29 text
RBkit Team
• Emil
• Kashyap
• Yuva
• Hemant
And
Slide 30
Slide 30 text
http://codemancers.com
Slide 31
Slide 31 text
C is what Linus
Torvalds wrote.
Slide 32
Slide 32 text
About RBKit
• A low overhead Ruby Profiler built for MRI.
• Written almost completely in C.
Slide 33
Slide 33 text
RBKit
• A Desktop application
• A Ruby gem
Slide 34
Slide 34 text
RBKit
• Gather and send all profile data via
ZeroMQ to connected client (Desktop
app)
• Uses msgpack as serialization format.
Slide 35
Slide 35 text
Advantage RBKit
• ZeroMQ manages separate IO threads for
sending and receiving messages.
• Msgpack serialisation is fast.
• A profiler that can be used in production!
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.
Slide 40
Slide 40 text
Tools used
• Valgrind
• leaks (Try this command on OSX now!)
Slide 41
Slide 41 text
RBkit Status Report
• Memory Profiling works (Demo)
• CPU Profiling is in works.
• Open source
Slide 42
Slide 42 text
RbkitApp Demo
Slide 43
Slide 43 text
GC tuning
visualizations
Slide 44
Slide 44 text
RUBY_GC_HEAP_INIT_SLOTS
Slide 45
Slide 45 text
RUBY_GC_HEAP_GROWTH_FACTOR
Slide 46
Slide 46 text
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()