Share
Embed
drbdump
drbdump is a tcpdump-like tool for the dRuby protocol. It allows you to inspect the message and analyze the messages sent between your DRb-using processes.
This presentation was given at dRuby Hiroba 2013
Eric Hodel
June 02, 2013
Transcript
53 slides
-
drbdump • Like tcpdump • Understands messages • Tracks Marshal
allocations • Tracks latency Sunday, June 2, 13 -
Problems • Out-of-order TCP • mDNS • resolv.rb, partial patch
• No filtering • IPv6 (bug) Sunday, June 2, 13 -
Running • Basic drbdump • Summary of 10,000 messages drbdump
-q -n -c 10000 • Listen only on loopback drbdump -i lo0 Sunday, June 2, 13 -
Demo $ cd $(dirname $(gem which drbdump))/.. $ ruby example/...
Sunday, June 2, 13 -
dRuby Protocol • Peer to Peer • Message → Result
• 1 to ∞ messages per connection • TCP, UNIX, SSL, etc. • drbdump is TCP-only Sunday, June 2, 13 -
Message Chunk • Chunk size • 32-bit little-endian integer •
Marshal stream "\x00\x00\x00\x03\x04\x08T" Sunday, June 2, 13 -
Message Send • Receiver • nil or object id •
Method name • Argument count • Arguments • Block or nil Sunday, June 2, 13 -
Message Result • Message status • true → success •
false → exception • Result or Exception Sunday, June 2, 13 -
drbdump loop Get packet Add to stream Find first chunk
Load Error Ignore stream Determine type Update statistics Display packet Sunday, June 2, 13 -
Debug with irb …⋯ ⇒ ("druby://10.101.28.77:60913", 70180390657240). respond_to?(:update, false) ^C
$ irb -r drb >> DRb.start_service >> DRb::DRbObject.new_with( "druby://10.101.28.77:60913", 70180390657240) Sunday, June 2, 13 -
Exception Result 17:34:49.563440 "druby://10.101.28.77:60929" ⤂ "druby://10.101.28.77:60920" exception: #<LocalJumpError: break from
proc-closure> Sunday, June 2, 13 -
Exception Object 17:34:49.563440 "druby://10.101.28.77:60929" ⤂ "druby://10.101.28.77:60920" exception: #<LocalJumpError: break from
proc-closure> Sunday, June 2, 13 -
Easy to Match "druby://10.101.28.77:60919" ⇒ ("druby://10.101.28.77:60913" "druby://10.101.28.77:60919" ⾨ "druby://10.101.28.77:60913" "druby://10.101.28.77:60929"
⇒ ("druby://10.101.28.77:60920" "druby://10.101.28.77:60929" ⤂ "druby://10.101.28.77:60920" Sunday, June 2, 13 -
Statistics Output • Basic statistics • Packets, messages, results •
Message statistics • Allocations, latency • Peer statistics • Latency Sunday, June 2, 13 -
Basic Statistics 1508 total packets captured 0 Rinda packets captured
56 DRb packets captured 30 messages sent 26 results received 2 exceptions raised Sunday, June 2, 13 -
Message Statistics Messages sent min, avg, max, stddev: call (1
args) 10 sent; 3.0, 6.2, 19.0, 6.7 allocations; 0.285, 1.479, 7.258, 2.171 ms Sunday, June 2, 13 -
Peer Statistics Peers min, avg, max, stddev: 6 messages: "druby://10.101.28.77:60928"
to "druby://10.101.28.77:60910"; 0.623, 1.632, 4.877, 1.618 ms Sunday, June 2, 13 -
Peer Statistics Peers min, avg, max, stddev: [...] 4 single-message
peers 0.307, 0.791, 1.568, 0.547 ms Sunday, June 2, 13 -
capp • libpcap wrapper • GVL-friendly • MIT license •
Simple interface Sunday, June 2, 13 -
capp capp = Capp.live capp.filter = '...' Thread.new do capp.loop
do |packet| @queue.enq packet end @queue << nil # no more packets end Sunday, June 2, 13 -
capp Thread.new do while packet = @queue.deq do process packet
end end Sunday, June 2, 13 -
capp Thread process packet Queue packet = queue.deq Thread capp_loop()
acquire GVL queue.enq packet Sunday, June 2, 13 -
capp Thread Thread process packet Queue Queue acquire GVL capp_loop()
queue.enq packet packet = queue.deq Thread capp_loop() acquire GVL queue.enq packet Sunday, June 2, 13 -
capp Capp.open 'lo0' Capp.open 'capture.pcap' Capp.devices # devices and addresses
Capp.drop_privileges # for safety capp.stop # end capture Sunday, June 2, 13 -
marshal-structure s = Marshal::Structure.new \ Marshal.dump %w[a b] s.count_allocations #=>
4 s.load #=> ["a", "b"] Sunday, June 2, 13 -
marshal-structure s = Marshal::Structure.new \ Marshal.dump %w[a b] s.count_allocations #=>
4 s.load #=> ["a", "b"] Hidden Encoding instance variable Sunday, June 2, 13 -
token_stream s.token_stream.to_a #=> [ :array, 2, :instance_variables, :string, "a", 1,
:symbol, "E", :true, :instance_variables, :string, "b", 1, :symbol_link, 0, :true] Sunday, June 2, 13 -
structure s.structure #=> [ :array, 0, 2, [:instance_variables, [:string, 1,
"a"], 1, [:symbol, 0, "E"], :true], [:instance_variables, [:string, 2, "b"], 1, [:symbol_link, 0], :true]] Sunday, June 2, 13 -
structure s.structure #=> [ :array, 0, 2, [:instance_variables, [:string, 1,
"a"], 1, [:symbol, 0, "E"], :true], [:instance_variables, [:string, 2, "b"], 1, [:symbol_link, 0], :true]] Reference ID Sunday, June 2, 13 -
structure s.structure #=> [ :array, 0, 2, [:instance_variables, [:string, 1,
"a"], 1, [:symbol, 0, "E"], :true], [:instance_variables, [:string, 2, "b"], 1, [:symbol_link, 0], :true]] Reference ID Sunday, June 2, 13 -
structure s.structure #=> [ :array, 0, 2, [:instance_variables, [:string, 1,
"a"], 1, [:symbol, 0, "E"], :true], [:instance_variables, [:string, 2, "b"], 1, [:symbol_link, 0], :true]] Reference ID Sunday, June 2, 13 -
structure s.structure #=> [ :array, 0, 2, [:instance_variables, [:string, 1,
"a"], 1, [:symbol, 0, "E"], :true], [:instance_variables, [:string, 2, "b"], 1, [:symbol_link, 0], :true]] Reference ID Reference Use Sunday, June 2, 13 -
token_stream s.token_stream.to_a #=> [ :array, 2, :instance_variables, :string, "a", 1,
:symbol, "E", :true, :instance_variables, :string, "b", 1, :symbol_link, 0, :true] Sunday, June 2, 13 -
structure s.structure #=> [ :array, 0, 2, [:instance_variables, [:string, 1,
"a"], 1, [:symbol, 0, "E"], :true], [:instance_variables, [:string, 2, "b"], 1, [:symbol_link, 0], :true]] Sunday, June 2, 13