lib/riemann/tools/riemann_client_wrapper.rb in riemann-tools-1.7.1 vs lib/riemann/tools/riemann_client_wrapper.rb in riemann-tools-1.8.0

- old
+ new

@@ -9,10 +9,12 @@ class RiemannClientWrapper include Singleton def initialize @client = nil + @queue = Queue.new + @max_bulk_size = 1000 end def configure(options) return self unless @client.nil? @@ -30,14 +32,27 @@ @client = if options[:tcp] || options[:tls] r.tcp else r end + + @worker = Thread.new do + loop do + events = [] + + events << @queue.pop + events << @queue.pop while !@queue.empty? && events.size < @max_bulk_size + + @client.bulk_send(events) + end + end + @worker.abort_on_exception = true + self end def <<(event) - @client << event + @queue << event end end end end