Skip to content

Instantly share code, notes, and snippets.

@Winslett
Created July 17, 2012 17:13
Show Gist options
  • Save Winslett/3130646 to your computer and use it in GitHub Desktop.
Save Winslett/3130646 to your computer and use it in GitHub Desktop.
Ruby - MongoDB Forked Connection Pattern
require 'rubygems'
require 'mongo'
@conn = Mongo::Connection.new("localhost", 27017, :pool_size => 10, :pool_timeout => 5)
@db = @conn['mongomapper_resque_development']
@coll = @db['users']
puts @db.command({getLastError: 1})
1.upto(10) do
client = fork do
puts @db.command({getLastError: 1})
end
Process.wait(client)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment