Module: Lockistics
- Defined in:
- lib/lockistics.rb,
lib/lockistics/lock.rb,
lib/lockistics/meter.rb,
lib/lockistics/version.rb,
lib/lockistics/meterable.rb,
lib/lockistics/statistics.rb,
lib/lockistics/configuration.rb
Overview
Lockistics is basically a distributed mutex on Redis.
In addition to locking it also collects statistics data of the locking events.
You can use each part separately if you just want to collect statistics or to do simple locking.
Total, daily and hourly metrics you get for each key are:
- Number of locks
- Number of times having to wait for lock
- Number of failed locking attempts
- Minimum and maximum duration
- Minimum and maximum memory growth (using OS gem, only when :meter_rss => true)
- Arbitary metrics you add during execution
Theres also an experimental module you can use to wrap any instance
methods inside a meter block.
@example
class SomeClass
include Lockistics::Meterable
meter :instance_method_name
def instance_method_name
do_something
end
end
Defined Under Namespace
Modules: Meterable Classes: Configuration, DummyMeter, Lock, LockTimeout, Meter, Statistics
Constant Summary collapse
- VERSION =
"0.1.6"
Class Method Summary collapse
-
.configuration ⇒ Object
Returns an instance of Lockistics::Configuration.
-
.configure {|configuration| ... } ⇒ Object
Configure the gem.
-
.known_keys(key = nil) ⇒ Object
Get a list of known keys or add a key to known keys list.
-
.lock(key, options = {}, &block) ⇒ Object
Get a hold of a lock or wait for it to be released.
-
.meter(key, options = {}, &block) ⇒ Object
Don’t perform locking, just collect metrics.
-
.meterlock(key, options = {}, &block) ⇒ Object
Perform locking and statistics collection.
-
.redis ⇒ Object
Accessor to the redis configured via Lockistics::Configuration.
-
.release(key, options = {}) ⇒ Object
Manually release a lock.
-
.statistics(key) ⇒ Object
Returns an instance of Lockistics::Statistics for the key.
Class Method Details
.configuration ⇒ Object
Returns an instance of Lockistics::Configuration
56 57 58 |
# File 'lib/lockistics.rb', line 56 def self.configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
Configure the gem
51 52 53 |
# File 'lib/lockistics.rb', line 51 def self.configure(&block) yield configuration end |
.known_keys(key = nil) ⇒ Object
Get a list of known keys or add a key to known keys list.
145 146 147 148 149 150 151 |
# File 'lib/lockistics.rb', line 145 def self.known_keys(key=nil) if key.nil? redis.smembers "#{Lockistics.configuration.namespace}.known_keys" else redis.sadd "#{Lockistics.configuration.namespace}.known_keys", key end end |
.lock(key, options = {}, &block) ⇒ Object
Get a hold of a lock or wait for it to be released
Given a block, will release the lock after block exection
83 84 85 86 87 88 89 |
# File 'lib/lockistics.rb', line 83 def self.lock(key, ={}, &block) if block_given? Meter.new(key, .merge(:no_metrics => true)).perform(&block) else Lock.new(key, ).acquire_lock end end |
.meter(key, options = {}, &block) ⇒ Object
Don’t perform locking, just collect metrics.
98 99 100 |
# File 'lib/lockistics.rb', line 98 def self.meter(key, ={}, &block) Meter.new(key, .merge(:lock => nil)).perform(&block) end |
.meterlock(key, options = {}, &block) ⇒ Object
Perform locking and statistics collection
113 114 115 |
# File 'lib/lockistics.rb', line 113 def self.meterlock(key, ={}, &block) Meter.new(key, .merge(:lock => Lock.new(key, ))).perform(&block) end |
.redis ⇒ Object
Accessor to the redis configured via Lockistics::Configuration
61 62 63 |
# File 'lib/lockistics.rb', line 61 def self.redis configuration.redis end |
.release(key, options = {}) ⇒ Object
Manually release a lock
127 128 129 |
# File 'lib/lockistics.rb', line 127 def self.release(key, ={}) Lock.new(key).release_lock end |
.statistics(key) ⇒ Object
Returns an instance of Lockistics::Statistics for the key.
139 140 141 |
# File 'lib/lockistics.rb', line 139 def self.statistics(key) Statistics.new(key) end |