Skip to content

Commit

Permalink
Add concurrent-ruby gem
Browse files Browse the repository at this point in the history
The reason we need this gem is to be able to provide a good concurrency
story in our "Data Stores".

We want the data stores to be thread-safe to make it easy for metrics to
use them, and to shield away the complexity so that the store can do what's
most efficient, and metrics don't need to make assumptions on how it
works.

However, we also need metrics to be able to update multiple values at once
so in some cases (most notably, histograms), the store does need to provide
a synchronization method.

Since the normal `set` / `increment` methods call a Mutex already, having
a Mutex block around them means we end up calling `Mutex.synchronize` twice,
which *should* work, but Ruby Mutexes are not reentrant.

`concurrent-ruby` provides a Reentrant lock. It's a Read-Write Lock, not
a Mutex, but by always grabbing Write locks, it's functionally the same

Signed-off-by: Daniel Magliola <[email protected]>
  • Loading branch information
Daniel Magliola committed Mar 4, 2019
1 parent ce6d44d commit b787e37
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions prometheus-client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ Gem::Specification.new do |s|

s.files = %w(README.md) + Dir.glob('{lib/**/*}')
s.require_paths = ['lib']

s.add_dependency 'concurrent-ruby'
end

0 comments on commit b787e37

Please sign in to comment.