Slide 1

Slide 1 text

ARRRR ME HEARTY! Sailing the Seas of DRb in a Shoe Davy Stevenson Eric Hodel Rein Henrichs @davystevenson @drbrain @reinh RubyConf 2013

Slide 2

Slide 2 text

Spaceteam? Who has played? Pleiades by Jim Keller

Slide 3

Slide 3 text

Spaceteam trailer

Slide 4

Slide 4 text

Why DRb? Easy Interprocess Communication Send and Get Data Peer to Peer Red Beach by alphadesigner

Slide 5

Slide 5 text

Why Rinda? Flexible Automatic discovery No explicit destination? Throw it in the tuplespace Farmhouse and Roosting Birds at Dusk by Trey Ratcliff

Slide 6

Slide 6 text

Why Shoes? Needs some love and attention Perfect showcase for distributed code Support non-web Ruby development! Freestyle Converse by Daniele Margaroli

Slide 7

Slide 7 text

Why Pirates? Yarrr! Mutiny by Shane Gorski

Slide 8

Slide 8 text

Preparation Install jruby (1.7.4-6 all should work) Install shoes4 $ git clone https://github.com/shoes/shoes4 $ git checkout 7d0a1ee $ gem build shoes.gemspec $ gem install shoes-4.0.0.pre1 $ alias shoes4='/path/to/shoes4/bin/shoes' Install pirate_game $ gem install pirate_game

Slide 9

Slide 9 text

Preparation Also in pirate_game README! https://github.com/davy/pirate_game

Slide 10

Slide 10 text

DRb RMI for Ruby Written by Masatoshi SEKI require ‘drb’ Remote objects act like local objects It’s “Ruby Throated” Tuesday! by MrClean1982

Slide 11

Slide 11 text

Remote Array Server array = [] # share the array DRb::DRbServer.new nil, array # print the URI (we let DRb pick) puts DRb.uri # wait for ^C DRb.thread.join

Slide 12

Slide 12 text

Remote Array Peer # create remote array reference remote_array = DRbObject.new_with_uri ARGV.shift # append to remote array remote_array << "a" remote_array.push "b", "c"

Slide 13

Slide 13 text

Remote Array Peer # create remote array reference remote_array = DRbObject.new_with_uri ARGV.shift puts remote_array.join ", " # => a, b, c

Slide 14

Slide 14 text

Rinda Linda for Ruby Model for distributed programming require ‘rinda/ tuple_space’ Stores tuples with arbitrary data write, take, read Quasicabinet by Aranda\Lasch

Slide 15

Slide 15 text

Tuple Space # blocking operation with template @ts.take [:button, "Keel", (now...now + 30), nil] # writing a matching tuple unblocks @ts.write [:button, "Keel", Time.now.to_i, DRb.uri]

Slide 16

Slide 16 text

Service Discovery Rinda::RingFinger, Rinda::RingServer TupleSpace for registry Broadcast, unicast, multicast (Ruby 2.1) Rinda::RingProvider Wrapper for advertisement

Slide 17

Slide 17 text

Shoes Created by _why Simple cross- platform GUI toolkit for Ruby Shoes4 is an all- Ruby rewrite Still under active development Blue Power! by Éole Wind

Slide 18

Slide 18 text

Shoes Manual Layout Input elements Drawing Animate / Move / Events http://shoesrb.com/manual/Hello.html

Slide 19

Slide 19 text

Display Issues Not all movement methods have been implemented on all types of objects Can move, but not displace Width/height =( Show/hide/toggle missing =(

Slide 20

Slide 20 text

Animations Animations run in parallel Need to manually manage them start, stop, remove PROTIP™: Separate drawing from animation

Slide 21

Slide 21 text

Give Back Complicated Shoes app highlights regressions Use game to detect & fix issues

Slide 22

Slide 22 text

Open Source Three Gems! github.com/davy/ pirate_command github.com/davy/ shuttlecraft github.com/davy/ pirate_game Coast Guard by Mike Baird

Slide 23

Slide 23 text

pirate_command PirateCommand.generate => "Swab the Poop Deck" PirateCommand.action => "Batten" PirateCommand.thing => "Main Sail" PirateCommand.exclaim => "Ahoy" PirateCommand.exclaim! => "Shiver me Timbers!"

Slide 24

Slide 24 text

pirate_command github.com/davy/pirate_command

Slide 25

Slide 25 text

shuttlecraft Create distributed systems with Rinda Simplifies registration Keeps track of registered clients Easily send messages

Slide 26

Slide 26 text

shuttlecraft github.com/davy/shuttlecraft

Slide 27

Slide 27 text

pirate_game Play the game!

Slide 28

Slide 28 text

pirate_game github.com/davy/pirate_game

Slide 29

Slide 29 text

Game Architecture? Does exactly what the GM instructs Game Master Game Handles all logic Issue cmds to game, game sends response

Slide 30

Slide 30 text

That’s no fun! Distributed services FTW Lightning by Fadzly Mubin

Slide 31

Slide 31 text

Game Architecture Registration Layout generation Issuing actions & gathering responses

Slide 32

Slide 32 text

Yay Diagrams! Game Game Master Rinda Tuplespace

Slide 33

Slide 33 text

Registration

Slide 34

Slide 34 text

Registration write [:name, ‘Foo’, uri’]

Slide 35

Slide 35 text

Registration write write [:name, ‘Foo’, uri’] [:name, ‘Bar’, uri’]

Slide 36

Slide 36 text

Registration write write write [:name, ‘Foo’, uri’] [:name, ‘Bar’, uri’] [:name, ‘Baz’, uri’]

Slide 37

Slide 37 text

Registration write write write [:name, ‘Foo’, uri’] [:name, ‘Bar’, uri’] [:name, ‘Baz’, uri’] read_all

Slide 38

Slide 38 text

Layout Generation GM sends each game their bridge and list of all bridge items my_items all_items my_items all_items direct DRb

Slide 39

Slide 39 text

Action & Response

Slide 40

Slide 40 text

Action & Response watch for actions take (blocks)

Slide 41

Slide 41 text

Action & Response ‘Haul the Keel’ watch for actions take (blocks)

Slide 42

Slide 42 text

Action & Response watch for button click take (blocks) watch for actions take (blocks)

Slide 43

Slide 43 text

Action & Response watch for button click on button click [:button, ‘Keel’, timestamp, from] write take (blocks) watch for actions take (blocks)

Slide 44

Slide 44 text

Action & Response watch for button click [:button, ‘Keel’, timestamp, from] take (blocks) watch for actions take (blocks)

Slide 45

Slide 45 text

Action & Response watch for button click watch for actions take (blocks) write [:action, ‘Keel’, timestamp, from]

Slide 46

Slide 46 text

Action & Response watch for button click watch for actions take (blocks) [:action, ‘Keel’, timestamp, from]

Slide 47

Slide 47 text

Action & Response watch for button click watch for actions

Slide 48

Slide 48 text

Architecture Diagram mothership game_master client client_app master_app shuttlecraft

Slide 49

Slide 49 text

Enough Jibber Jabber Let’s get to the important parts GAME TIME Shut up you fool! by Andre Vandal

Slide 50

Slide 50 text

Preparation (again) Install jruby (1.7.4-6 all should work) Install shoes4 $ git clone https://github.com/shoes/shoes4 $ git checkout 7d0a1ee $ gem build shoes.gemspec $ gem install shoes-4.0.0.pre1 $ alias shoes4='/path/to/shoes4/bin/shoes'

Slide 51

Slide 51 text

Install Install pirate_game $ gem install pirate_game

Slide 52

Slide 52 text

Networking Theoretically this should work on conference wifi *But* for best results use a personal access point

Slide 53

Slide 53 text

RingServer Someone needs to run a ringserver $ ring_server But not too many Try not to screw it up We are working on it

Slide 54

Slide 54 text

Game Master Only one needed per game Pick a good name If GM crashes, game is stranded =(

Slide 55

Slide 55 text

Pirate Game! 1* to 4 players *Totally a ‘feature’ not a bug

Slide 56

Slide 56 text

Find Your Game GMs are found by Rinda service discovery

Slide 57

Slide 57 text

Find Your Game ISSUE: If join fails you will not receive an error message and will enter empty disconnected pub =(

Slide 58

Slide 58 text

Pirate Pub Chat with your friends in the Pirate Pub* *Yes, you have to click the ‘Send’ button. No keybindings?!? =(

Slide 59

Slide 59 text

Pirate Pub ISSUE: At the moment the GM needs to trigger each stage. Future development should switch over to Spaceteam-like mechanism where each player indicates that they are ready to proceed

Slide 60

Slide 60 text

Sail the High Seas Keep the ship afloat! Work together to man the ship Beware of bad weather!

Slide 61

Slide 61 text

Security DRb Priorities: Transparency Easy of use … Security Pirates by Adrien Sifre

Slide 62

Slide 62 text

Full Access Clients can do anything Get remote nil instance_eval github.com/drbrain/drb-worm

Slide 63

Slide 63 text

Message-level Security DRb::DRbServer::INSECURE_METHOD Opt-out $SAFE Relies on tainting

Slide 64

Slide 64 text

DRb over UNIX Socket Restricted to one host Filesystem permissions control access No network access

Slide 65

Slide 65 text

Access Control List Deny or allow by IP address and range Difficult to manage No privacy

Slide 66

Slide 66 text

DRb over SSL X509 certificate Full privacy Difficult to manage

Slide 67

Slide 67 text

chroot Filesystem sandbox Can’t write outside Can still consume CPU, create processes

Slide 68

Slide 68 text

Best Practices Verify your peers Limit accessibility Use a private network

Slide 69

Slide 69 text

drbdump tcpdump for DRb Message sends Message latency Message allocations Colorful toy trucks parked together in rows by Horia Varlan

Slide 70

Slide 70 text

Problems Out-of-order TCP mDNS Ruby 2.1 No filtering IPv6 (bug)

Slide 71

Slide 71 text

Running Basic drbdump Summary of 10,000 messages drbdump -q -n -c 10000 Listen only on loopback drbdump -i lo0

Slide 72

Slide 72 text

Timestamp 17:34:49.546074 "druby://192.0.2.1:60919" 㱺 ("druby://192.0.2.1:60913", 70180390657240). respond_to?(:update, false)

Slide 73

Slide 73 text

Source 17:34:49.546074 "druby://192.0.2.1:60919" 㱺 ("druby://192.0.2.1:60913", 70180390657240). respond_to?(:update, false)

Slide 74

Slide 74 text

Message-send 17:34:49.546074 "druby://192.0.2.1:60919" 㱺 ("druby://192.0.2.1:60913", 70180390657240). respond_to?(:update, false)

Slide 75

Slide 75 text

Receiver 17:34:49.546074 "druby://192.0.2.1:60919" 㱺 ("druby://192.0.2.1:60913", 70180390657240). respond_to?(:update, false)

Slide 76

Slide 76 text

Message Name 17:34:49.546074 "druby://192.0.2.1:60919" 㱺 ("druby://192.0.2.1:60913", 70180390657240). respond_to?(:update, false)

Slide 77

Slide 77 text

Arguments 17:34:49.546074 "druby://192.0.2.1:60919" 㱺 ("druby://192.0.2.1:60913", 70180390657240). respond_to?(:update, false)

Slide 78

Slide 78 text

Timestamp 17:34:49.546531 "druby://192.0.2.1:60919" ⾨ "druby://192.0.2.1:60913" success: true

Slide 79

Slide 79 text

Destination 17:34:49.546531 "druby://192.0.2.1:60919" ⾨ "druby://192.0.2.1:60913" success: true

Slide 80

Slide 80 text

Message-result 17:34:49.546531 "druby://192.0.2.1:60919" ⾨ "druby://192.0.2.1:60913" success: true

Slide 81

Slide 81 text

Source 17:34:49.546531 "druby://192.0.2.1:60919" ⾨ "druby://192.0.2.1:60913" success: true

Slide 82

Slide 82 text

Status 17:34:49.546531 "druby://192.0.2.1:60919" ⾨ "druby://192.0.2.1:60913" success: true

Slide 83

Slide 83 text

Result Object 17:34:49.546531 "druby://192.0.2.1:60919" ⾨ "druby://192.0.2.1:60913" success: true

Slide 84

Slide 84 text

Exception 17:34:49.563440 "druby://192.0.2.1:60929" ⤂ "druby://192.0.2.1:60920" exception: #

Slide 85

Slide 85 text

Exception Object 17:34:49.563440 "druby://192.0.2.1:60929" ⤂ "druby://192.0.2.1:60920" exception: #

Slide 86

Slide 86 text

Easy to Match "druby://192.0.2.1:60919" 㱺 ("druby://192.0.2.1:60913" "druby://192.0.2.1:60919" ⾨ "druby://192.0.2.1:60913" "druby://192.0.2.1:60929" 㱺 ("druby://192.0.2.1:60920" "druby://192.0.2.1:60929" ⤂ "druby://192.0.2.1:60920"

Slide 87

Slide 87 text

Statistics Output Basic statistics Packets, messages, results Message statistics Allocations, latency Peer statistics Latency

Slide 88

Slide 88 text

Basic Statistics 1508 total packets captured 0 Rinda packets captured 56 DRb packets captured 30 messages sent 26 results received 2 exceptions raised

Slide 89

Slide 89 text

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

Slide 90

Slide 90 text

drbdump Diagnostics Find message spam Find hanging calls Verify expected behavior

Slide 91

Slide 91 text

Future Want to pitch in? Wilma was here by zanzibar

Slide 92

Slide 92 text

Group Activities Raid a ship? Survive a hurricane? Steer ship with the wheel

Slide 93

Slide 93 text

Character Generation Build a pirate? Select: Beard Parrot Eyepatch Hair

Slide 94

Slide 94 text

Infrastructure Improvement Automatic Integrated Game Master Better Error Handling Easy Game Restart

Slide 95

Slide 95 text

Play! Contribute! Thanks! =D The Flying Dutchman by Scott Smith