This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def thread_write | |
pool = ThreadPool.new(80) | |
doc_size = 10000 | |
doc_size.times do |i| | |
pool.process do | |
write_doc(i) | |
read_doc(i) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def connection(options = { pool: true }) | |
if options[:pool] | |
Mongo::Connection.new("localhost", 27017, pool_size: 15, pool_timeout: 5) | |
else | |
Mongo::Connection.new("localhost", 27017) | |
end | |
end | |
def do_write(counter = nil) | |
if counter |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"errors": [ | |
{ | |
"code": 63, | |
"message": "User has been suspended" | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'redis', '3.0.2', require: ['redis', 'redis/connection/hiredis'] | |
gem 'hiredis' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extend ActiveSupport::Benchmarkable | |
def logger; Rails.logger; end; | |
def redis_connection(hire = true) | |
hire ? Redis.new(logger: nil, driver: 'hiredis') : Redis.new(logger: nil) | |
end | |
def test_redis_hash(size = 10_000, hire = true) | |
key = Digest::MD5.hexdigest(Time.now.to_i.to_s)[0, 24] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extend ActiveSupport::Benchmarkable | |
def logger; Rails.logger; end; | |
def redis_connection(hire = true) | |
hire ? Redis.new(logger: nil, driver: 'hiredis') : Redis.new(logger: nil) | |
end | |
def test_redis(size = 10_000, hire = true) | |
key = Digest::MD5.hexdigest(Time.now.to_i.to_s)[0, 24] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"connections/paths": [ | |
{ | |
"user_ids": ["4e4b1547a876e66e41000033", "4e4b1547a876e66e41000011"], | |
"connectors": [ | |
{ | |
"via": "facebook", | |
"type": "friend", | |
OR | |
"in": true, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rails console | |
Loading development environment (Rails 3.0.6) | |
ruby-1.8.7-p334 :001 > r = Rails.application.routes | |
Gives you a handle of all the routes (config/routes.rb) | |
#Inspect a named route: | |
ruby-1.8.7-p334 :005 > r.recognize_path(app.destroy_user_session_path) | |
=> {:action=>"destroy", :controller=>"sessions"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car | |
def start(speed) | |
speed = 60 | |
puts "running @ #{speed}" | |
end | |
end | |
speed = 40 | |
puts speed | |
Car.new.start speed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car | |
def start(options) | |
options[:speed] = 60 | |
puts "running @ #{options[:speed]}" | |
end | |
end | |
op = { speed: 50 } | |
puts op.inspect | |
Car.new.start op |