Distributed Ruby and Rails
Distributed Ruby
- DRb
- Rinda
- Starfish
- MapReduce
- MagLev VM
DRb
- Ruby's RMI (remote method invocation) system
- An object in one Ruby process can invoke methods on an object in another Ruby process on the same or a different machine.
- No defined interface, faster development time
- Tightly couple applications, because no defined API, but rather method on objects
- Unreliable under large-scale, heavy loads production environments
Server Example 1
Client Example 1
Example 2
Server example 2
Client Example 2
Err
Why DRbUndumped ?
- Default DRb operation
- Pass by value
- Must share code
- With DRbUndumped
- Pass by reference
- No need to share code
Example 2 Fixed
Why use DRbUndumped?
- Big objects
- Singleton objects
- Lightweight clients
- Rapidly changing software
ID conversion
- Converts reference into DRb object on server
- DRbIdConv (Default)
- TimerIdConv
- NamedIdConv
- GWIdConv
DRb security
$SAFE=1
- Access Control Lists (ACLs)
- via IP address array
- still can run denial-of-service attack
- DRb over SSL
Rinda
- Rinda is a Ruby port of Linda distributed computing paradigm.
- Linda is a model of coordination and communication among several parallel processes operating upon objects stored in and retrieved from shared, virtual, associative memory. This model is implemented as a "coordination language" in which several primitives operating on ordered sequence of typed data objects, "tuples," are added to a sequential language, such as C, and a logically global associative memory, called a tuplespace, in which processes store and retrieve tuples
- Rinda consists of:
- A TupleSpace implementation
- A RingServer that allows DRb services to
- automatically discover each other.
RingServer
- We hardcoded IP addresses in DRb program, it’s tight coupling of applications and make fault tolerance difficult.
- RingServer can detect and interact with other services on the network without knowing IP addresses.
Learn Ruby on Rails - Ruby on Rails tutorial - Ring Server - Ruby on Rails examples - Ruby On Rails programs
Ring Server Example
Service Example
Client Example
TupleSpaces
- Shared object space
- Atomic access
- Just like bulletin board
- Tuple template is
- [:name, :Class, object, ‘description’ ]
5 Basic Operations
- write
- read
- take (Atomic Read+Delete)
- read_all
- notify (Callback for write/take/delete)
Starfish
- Starfish is a utility to make distributed programming ridiculously easy
- It runs both the server and the client in infinite loops
- MapReduce with ActiveRecode or Files
starfish foo.rb
foo.rb
Starfish server example
starfish client example
starfish client example (another way)
MapReduce
- Introduced by Google to support distributed computing on large data sets on clusters of computers.
- Inspired by map and reduce functions commonly used in functional programming.
Starfish Server Example
starfish client example
Other implementations
- Skynet
- Use TupleSpace or MySQL as message queue
- Include an extension for ActiveRecord
- MRToolkit based on Hadoop
MagLev VM
- A fast, stable, Ruby implementation with integrated object persistence and distributed shared cache.