Poor man's web application with StrokeDB and Merb

Posted by yrashk

Yesterday I’ve finally got to playing with StrokeDB as a database “server” for a web application (currently using Merb, but basically the following scenario should work for any Ruby-based framework)

So, while we’re going to create a nice realtime replication subsystem that will allow to build really largely scalable applications with StrokeDB, there is definitely a need to play with StrokeDB-powered web applications right away, even if it will not be that scalable and fast as we want it to be. That’s why I’ve tried to create something like simplistic way to use StrokeDB from few Merb application instances.

The basic idea is that all processes that want to access StrokeDB database need to access the only one “server” store over network connection. That’s why I’ve created RemoteStore concept that allows to access stores over DRb (more protocols could be added later). Since stores (SkiplistStore to be specific) aren’t really thread-safe, RemoteStore server is actually serving one client at a time. Unless you’re going to invoke long-running operations, it should be fast enough to play with this stuff.

So, here we go. Lets assume you have a Merb skeleton application (I am using merb-0.5.3 at the moment). All you need to do is:

  • Update your config/merb_init.rb to contain something like
 
puts "Loading StrokeDB..." 
$:.unshift File.dirname(__FILE__) + '/../../strokedb-ruby/' # replace with your StrokeDB path
require 'strokedb'

StrokeDB.use_global_default_config!

print "Configuring StrokeDB..." 
if ARGV.include?('--strokedb-server')
  print 'configuring server store...'
  StrokeDB::Config.build :base_path => File.dirname(__FILE__) + "/../db", :default => true
  STROKEDB_THREAD = StrokeDB.default_store.remote_server('druby://localhost:9999').start
else
  StrokeDB.default_store = StrokeDB::RemoteStore::DRb::Client.new('druby://localhost:9999')
end
puts "done." 
 
  • define some metas in app/models, like app/models/user.rb:

User = Meta.new

  • run StrokeDB server:

$ merb -r "STROKEDB_THREAD.join" --strokedb-server

  • enjoy StrokeDB-powered application!

For example, you can use it in your controllers, or simply play within merb console (merb -i)

Of course, this method is definitely poor man’s one and we’re working on a better ways to build StrokeDB-powered applications, but something is more than nothing :)

If you’ll have any problems with the above scenario, let me know.

Comments

Leave a response