Rayman asked:

State servers

Hello,

0.40 release notes mention that the new nitro console command can start a cluster with a single parameter AND a shared stateserver on the go.

How does it work? It fails on windows due to fork().

Can the state server be configured to use a specific backend?

is there any kind of locking done on the database?

(1 attempts)

gmosx answered:

The state server is useful to store distributed sessions and distributed global variables. First of all you need to define your state server using the special file state.rb in your main directory. Here is an example:

#!/usr/bin/env ruby

$LOAD_PATH.unshift 'lib'

require 'nitro/server/drb'
require 'nitro/session/drb'
require 'nitro/global'

Nitro::Session.cache_port = 9050
Global.cache_port = 9051

# DrbServer 

class AppDrbServer < Nitro::DrbServer
  def setup_drb_objects
    super
     
    @global_cache = SyncHash.new 
    DRb.start_service("druby://#{Global.cache_address}:#{Global.cache_port}", @global_cac
he)    
    puts "Drb global cache at druby://#{Global.cache_address}:#{Global.cache_port}."  
  end
end    

AppDrbServer.start

The nitro command automatically starts the state server if needed. Here is an example invocation:

nitro --live --mongrel --cluster 3

This commands starts 3 application server as a mongrel cluster listening on ports baseport, baseport 1, baseport 2 and one state server.

nitro stop

stops the application servers but not the state server, useful for restarts that the users don't notice.

nitro kill

stops the application servers and the state server.

Rating: 5