SimpleRPC
About
SimpleRPC is a very simple (and rather fast) RPC library for ruby. It works by wrapping an object on the server side, and exposing those methods to clients. In the interests of simplicity and speed it notably doesn’t handle exposure over many interfaces, eventmachine integration, versioning, service naming/description or anything beyond basic security. If you want those things, go elsewhere.
SimpleRPC works either with ruby’s built in Marshal serialisation system or MessagePack, both of which offer good performance for most tasks. Using Marshal it is capable of making several thousand requests per second, something slightly improved upon by MessagePack.
Features currently run to:
- Connect-on-demand functionality, or multiple persistent connections supported (or a mix of the two)
- Timeouts on all operations using
select() - Speed—objects are serialised and loaded directly from the socket with no data copying or caching
- Password authentication (sent over an AES-256 encrypted link)
- Transparency—Proxy objects are almost indistinguishable from the remote object itself, and support blocks and coroutines.
- Thread safety—Clients and servers both optionally support multiple simultaneous calls and connections
Download
The best way of acquiring the tool is to pull it from rubygems.org using the gem tool:
gem install -r simplerpc
The source is available over on its git summary page..
Use
To use the library, simply include the gem:
require 'simplerpc/server' # server only
require 'simplerpc/client' # client only
require 'simplerpc' # both server and client
Full documentation is included in the gem, or listed on the summary page at rubygems.org.
Sample Code
A simple enough server is as below:
require 'simplerpc/server'
object = ['Test', 'Array'] # Wrap this object
s = SimpleRPC::Server.new( object, :port => 4545 ) # Serve object on port 4545
s.listen # Listen for clients
An accompanying test client would be:
require 'simplerpc/client'
c = SimpleRPC::Client.new( :hostname => '127.0.0.1', :port => 4545 ) # Connect on port 4545
puts "Remote length: #{c.length}" # call '.length', outputs '2'
puts "Remote data: #{c.call(:dup)}" # method would normally be clobbered by client, outputs '["Test", "Array"]'