Permalink
Browse files

better forking.rb

  • Loading branch information...
1 parent 5114c5e commit 30239b4c83e25c7e66cce90bcbc02ca8c1cb2cfc @jmettraux committed Apr 13, 2011
Showing with 24 additions and 4 deletions.
  1. +10 −1 lib/cassandra_lock.rb
  2. +14 −3 test/forking.rb
View
@@ -10,7 +10,8 @@ class CassandraLock
CF = "_cassandra_locks"
CHOOSING = "_choosing"
NUMBERS = "_numbers"
- SLEEP_DURATION = 0.1
+ #SLEEP_DURATION = 0.1
+ SLEEP_DURATION = 0.0
class << self
attr_writer :keyspace, :host
@@ -83,7 +84,13 @@ class Handle
attr_reader :client
+ attr_reader :gcounts, :scounts
+
def initialize(lock_id, my_worker_id, host, keyspace=nil)
+
+ @gcounts = 0
+ @scounts = 0
+
@keyspace = keyspace || CassandraLock.keyspace
@lock_id = lock_id
@my_worker_id = my_worker_id
@@ -211,10 +218,12 @@ def am_i_waiting_behind_worker?(numbers, his_worker_id, my_number, my_worker_id)
end
def get(key)
+ @gcounts += 1
@client.get(CF, key, :consistency => Cassandra::Consistency::QUORUM)
end
def set(key, value)
+ @scounts += 1
@client.insert(CF, key, value, :consistency => Cassandra::Consistency::QUORUM)
end
View
@@ -6,7 +6,6 @@
WORKER_COUNT = 10
-#WORKER_COUNT = 1
#cl = Cassandra.new('CassandraLock')
@@ -21,10 +20,21 @@
worker_pids << Process.fork do
+ start = Time.now
+ locks = 0
+
handle = CassandraLock::Handle.new(
'work', i + 1, "127.0.0.#{ (i % 5) + 1 }:9160")
- #p handle.client
+ Signal.trap('INT') do
+ duration = Time.now - start
+ puts "#{i} : #{duration}s"
+ puts "#{i} : #{locks} locks"
+ puts "#{i} : #{locks/duration} locks/s"
+ puts "#{i} : #{handle.gcounts} reads"
+ puts "#{i} : #{handle.scounts} writes"
+ exit(0)
+ end
loop do
@@ -35,11 +45,12 @@
#STDERR.puts "#{i} ^^^"
handle.unlock
+ locks += 1
end
end
end
-sleep 3 * 60
+sleep 60
at_exit do
worker_pids.each { |pid| Process.kill('INT', pid) }

0 comments on commit 30239b4

Please sign in to comment.