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

Like this? Share it with your network

Share

Riak with Rails

  • 11,141 views
Uploaded on

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!

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
11,141
On Slideshare
9,506
From Embeds
1,635
Number of Embeds
4

Actions

Shares
Downloads
101
Comments
0
Likes
14

Embeds 1,635

http://nosql.mypopescu.com 1,598
http://coderwall.com 32
http://translate.googleusercontent.com 3
http://webcache.googleusercontent.com 2

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
































Transcript

  • 1. Riak with Rails Sean Cribbs Developer Advocate basho
  • 2. Why Riak with Rails? Simple to understand and use Share-nothing, homogeneous Web-friendly Grows with your app (“scales”) Lots of use-cases basho
  • 3. Use Cases Document database File / upload storage (DFS) Cache / object store Session store basho
  • 4. 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
  • 5. Rails 3 Setup # config/ripple.yml development: host: 127.0.0.1 port: 8098 # config/application.rb require 'ripple/railtie' basho
  • 6. Basic Client Operations basho
  • 7. 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
  • 8. 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
  • 9. 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
  • 10. 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
  • 11. 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
  • 12. 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
  • 13. Use-Case: Document DB basho
  • 14. 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
  • 15. 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
  • 16. Caveats No indexes for efficient lookups (other than key) Still pretty new Currently hard to clean up after tests basho
  • 17. Ripple Demo basho
  • 18. Use Case: File storage basho
  • 19. Riak as a File Server Web-shaped storage - plays well with ops Authenticated downloads Serve files directly from Riak basho
  • 20. File Upload / Serve Demo basho
  • 21. Use-Case: Cache store basho
  • 22. 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
  • 23. 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
  • 24. Caveats Not as fast as memcached or redis No per-object expiry (could be done client-side) basho
  • 25. Riak::CacheStore Demo basho
  • 26. Use-Case: Session store basho
  • 27. 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
  • 28. 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
  • 29. Wrap-up basho
  • 30. 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
  • 31. Ripple Roadmap Testing assistance/automation Protocol buffers interface, HTTP enhancements More association types Get involved: http://github.com/seancribbs/ripple basho
  • 32. 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
  • 33. 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