34. TokenWorker Notes
M processes, 1 becomes leader for the given
time period and performs the work
Fault tolerant, not scalable
As reliable as memcached
The trick is the memcached::add API
35. 4 module Aggregator
5 class Engine
6 include Politics::TokenWorker
7
8 def initialize
9 register_worker 'dash-aggregator', :iteration_length =>
60.seconds, :servers => memcached_servers
10 end
11
12 def start
13 process do
14 MetricAggregator.new.aggregate
15 end
16 end
39. StaticQueueWorker Notes
Work is divided into N buckets
M-1 processes can be working on those N
buckets concurrently
Scalable and fault tolerant
Peers discover via Bonjour and communicate via
DRb
40. 16 module Politics
17 class QueueWorkerExample
18 include Politics::StaticQueueWorker
19 TOTAL_BUCKETS = 20
20
21 def initialize
22 register_worker ‘queue-example', TOTAL_BUCKETS, :iteration_length =>
60, :servers => memcached_servers
23 end
24
25 def start
26 process_bucket do |bucket|
27 puts "PID #{$$} processing bucket #{bucket}/#{TOTAL_BUCKETS} at
#{Time.now}..."
28 sleep 1.5
29 end
30 end
Asynchrony - processes run at different speeds and it would be very difficult and cost-prohibitive to make them work in a synchronous fashion\nLocality - each process has its own memory and view of the network, with no shared state.\nFailure - processes can fail at any time, just like real life.\n
How do processes learn about each other? How do they determine their proper set of peers, in light of failure?\n