Riak with Rails
Upcoming SlideShare
Loading in...5
×
 

Riak with Rails

on

  • 10,844 views

Ruby on Rails is a powerful web framework that focuses on developer productivity. Riak is a friendly key-value store that is simple, flexible and scalable. Put them together and you have lots of ...

Ruby on Rails is a powerful web framework that focuses on developer productivity. Riak is a friendly key-value store that is simple, flexible and scalable. Put them together and you have lots of exciting possibilities!

Statistics

Views

Total Views
10,844
Slideshare-icon Views on SlideShare
9,216
Embed Views
1,628

Actions

Likes
14
Downloads
101
Comments
0

4 Embeds 1,628

http://nosql.mypopescu.com 1591
http://coderwall.com 32
http://translate.googleusercontent.com 3
http://webcache.googleusercontent.com 2

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Riak with Rails Riak with Rails Presentation Transcript

  • Riak with Rails Sean Cribbs Developer Advocate basho
  • Why Riak with Rails? Simple to understand and use Share-nothing, homogeneous Web-friendly Grows with your app (“scales”) Lots of use-cases basho
  • Use Cases Document database File / upload storage (DFS) Cache / object store Session store basho
  • Getting Started # Gemfile gem 'curb' # Faster HTTP gem 'yajl-ruby' # Faster JSON gem 'riak-client', :require => 'riak' gem 'ripple' $ gem install curb yajl-ruby ripple basho
  • Rails 3 Setup # config/ripple.yml development: host: 127.0.0.1 port: 8098 # config/application.rb require 'ripple/railtie' basho
  • Basic Client Operations basho
  • require ‘riak’ Make a client object client = Riak::Client.new # or Ripple.client Get a bucket bucket = client.bucket(‘foo’) # Riak::Bucket Get an object from the bucket obj = bucket.get(‘bar’) # Riak::RObject Initialize a new object obj = bucket.new(‘baz’) basho
  • Riak::RObject Get/set object key obj.key = “bar” Get/set content-type obj.content_type = ‘application/json’ Get/set the object body data (JSON auto enc/dec) obj.data = {“name” => “Sean”} Store the object obj.store basho
  • Using Links Create a link Riak::Link.new(“/riak/bucket/key”, “tag”) Read an object’s links obj.links # Set<Riak::Link> Convert an object to a link obj.links << obj2.to_link(“next”) obj.store basho
  • Link-Walking obj = client[‘demo’][‘test1’] obj.walk(:keep => true) # Get all linked one-level obj.walk(:bucket => “demo”, :keep => true) # Get all linked in “demo” bucket obj.walk(:tag => ‘friend’, :keep => true) # Get all linked with tag “friend” obj.walk({},{:keep => true}) # Get all linked at second level basho
  • MapReduce mr = Riak::MapReduce.new(Ripple.client) mr.add(“people”,”sean”) mr.link(:tag => “friend”) mr.map(“Riak.mapValuesJson”,:keep => true) mr.run Riak::MapReduce.new(Ripple.client). add(“people”,”sean”). link(:tag => “friend”). map(“Riak.mapValuesJson”,:keep => true).run basho
  • Load RObjects from M/R Javascript Identity Map Function function(v){ return [v]; } Load output Riak::RObject.load_from_mapreduce(c, mr.run) # Returns Array<Riak::RObject> basho
  • Use-Case: Document DB basho
  • Riak as Document DB Store semi-structured data as “documents” (JSON) Alternative to CouchDB or MongoDB Links and Link-walking for easy relationships MapReduce for more involved queries basho
  • Ripple - Document OM Build rich, multi-level nested document models ActiveModel goodies: validations, callbacks, etc Associations -- embedded, linked Requires Rails 3.0.0.rc basho
  • Caveats No indexes for efficient lookups (other than key) Still pretty new Currently hard to clean up after tests basho
  • Ripple Demo basho
  • Use Case: File storage basho
  • Riak as a File Server Web-shaped storage - plays well with ops Authenticated downloads Serve files directly from Riak basho
  • File Upload / Serve Demo basho
  • Use-Case: Cache store basho
  • Riak as a Cache Store It’s a K/V store - similar to memcached, redis Flexible serialization options: JSON, YAML, Marshal, text, binary Tune for performance over consistency Low quorums and replication Last-write-wins? In-memory backend basho
  • Using Riak::CacheStore Implements ActiveSupport::Cache::Store Sets quorum/n_val defaults for you (tweakable) R=W=RW=1, DW=0, N=2 Doesn’t set backend or last_write_wins (tweakable) config.cache_store = :riak_store basho
  • Caveats Not as fast as memcached or redis No per-object expiry (could be done client-side) basho
  • Riak::CacheStore Demo basho
  • Use-Case: Session store basho
  • Riak as a Session store Substitute for ActiveRecord or memcached sessions Use when you need larger or longer-lived sessions Tune for modest durability and performance Low quorums, modest N (2 or 3) Fast disk backend (bitcask) or memory (ets) basho
  • Ripple::SessionStore (WIP) Sets quorum/n_val defaults for you Implements ActionDispatch::Session::AbstractStore config.session_store = ::Riak::SessionStore Coming in next release of Ripple (0.8.0) basho
  • Wrap-up basho
  • Riak with Rails Useful in many contexts Semi-structured data/documents Web-friendly storage Distributed cache / session storage Flexible K/V storage Grows with your app basho
  • Ripple Roadmap Testing assistance/automation Protocol buffers interface, HTTP enhancements More association types Get involved: http://github.com/seancribbs/ripple basho
  • Plug Interested in learning about support, consulting, or Enterprise features? Email info@basho.com or go to http://www.basho.com/contact.html to talk with us. www.basho.com basho
  • Plug Interested in learning about support, consulting, or Enterprise features? Email info@basho.com or go to http://www.basho.com/contact.html to talk with us. www.basho.com sean@basho.com @seancribbs basho