Aggregate + POSIX message queues support for Ruby 1.9+ and Linux
This class is duck-type compatible with Aggregate and allows us to aggregate and share statistics from multiple processes/threads aided POSIX message queues. This is designed to be used with the Raindrops::LastDataRecv
Rack application, but can be used independently on compatible Runtimes.
Unlike the core of raindrops, this is only supported on Ruby 1.9+ and Linux 2.6+. Using this class requires the following additional RubyGems or libraries:
aggregate (tested with 0.2.2)
posix_mq (tested with 1.0.0)
There is one master thread which aggregates statistics. Individual worker processes or threads will write to a shared POSIX message queue (default: "/raindrops") that the master reads from. At a predefined interval, the master thread will write out to a shared, anonymous temporary file that workers may read from
Setting :worker_interval
and :master_interval
to 1
will result in perfect accuracy but at the cost of a high synchronization overhead. Larger intervals mean less frequent messaging for higher performance but lower accuracy.
returns the number of dropped messages sent to a POSIX message queue if non-blocking operation was desired with :lossy
new (params = {}) source
Creates a new Raindrops::Aggregate::PMQ
object
Raindrops::Aggregate::PMQ.new(options = {}) -> aggregate
options
is a hash that accepts the following keys:
:queue - name of the POSIX message queue (default: "/raindrops")
:worker_interval - interval to send to the master (default: 10)
:master_interval - interval to for the master to write out (default: 5)
:lossy - workers drop packets if master cannot keep up (default: false)
:aggregate - Aggregate object (default: Aggregate.new)
:mq_umask - umask for creatingthe POSIX message queue (default: 0666)
<< (val) source
adds a sample to the underlying Aggregate object
aggregate () source
Loads the last shared Aggregate from the master thread/process
count () source
proxy for Aggregate#count
each () { |*args| ... } source
proxy for Aggregate#each
each_nonzero () { |*args| ... } source
proxy for Aggregate#each_nonzero
flush () source
flushes the local queue of the worker process, sending all pending data to the master. There is no need to call this explicitly as :worker_interval
defines how frequently your queue will be flushed
flush_master () source
Flushes the currently aggregate statistics to a temporary file. There is no need to call this explicitly as :worker_interval
defines how frequently your data will be flushed for workers to read.
master_loop () source
Starts running a master loop, usually in a dedicated thread or process:
Thread.new { agg.master_loop }
Any worker can call agg.stop_master_loop
to stop the master loop (possibly causing the thread or process to exit)
max () source
proxy for Aggregate#max
mean () source
proxy for Aggregate#mean
min () source
proxy for Aggregate#min
outliers_high () source
proxy for Aggregate#outliers_high
outliers_low () source
proxy for Aggregate#outliers_low
std_dev () source
proxy for Aggregate#std_dev
stop_master_loop () source
stops the currently running master loop, may be called from any worker thread or process
sum () source
proxy for Aggregate#sum
to_s (*args) source
proxy for Aggregate#to_s
mail archives: https://yhbt.net/raindrops-public/ http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/raindrops-public nntps://news.public-inbox.org/inbox.comp.lang.ruby.raindrops nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.lang.ruby.raindrops imaps://yhbt.net/inbox.comp.lang.ruby.raindrops.0 imap://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.lang.ruby.raindrops.0 public: raindrops-public@yhbt.net source code: git clone https://yhbt.net/raindrops.git torsocks git clone http://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/raindrops.git