Permalink
Browse files

Speed improvements - 10000 log entries for 0.65sec

  • Loading branch information...
1 parent 740c972 commit 836b0af75ce2193ed24ba841f9b3795d47255783 Martin Rusev committed Apr 27, 2012
Showing with 27 additions and 20 deletions.
  1. +1 −1 Gemfile
  2. +21 −10 benchmarks.rb
  3. +2 −8 lib/ramon/sender.rb
  4. +3 −1 lib/ramon/zeromq.rb
View
@@ -4,5 +4,5 @@ source "http://rubygems.org"
gemspec
gem 'rails', :group => :test
-
+gem 'zmq'
gem 'ramon', :path => '~/ramon'
View
@@ -1,4 +1,5 @@
require "rubygems"
+require "bundler/setup"
require "ramon"
require "logger"
require 'singleton'
@@ -42,6 +43,7 @@ def initialize
@socket = @context.socket(ZMQ::DEALER)
@socket.connect("tcp://#{@@address}")
@socket.setsockopt(ZMQ::LINGER, 0)
+ @socket.setsockopt(ZMQ::SWAP, 25000000) # 25MB disk swap
end
def post(data)
@@ -50,21 +52,30 @@ def post(data)
end
- #Ramon.configure do |config|
- #config.address = '127.0.0.1:5464'
- #config.protocol = 'zeromq'
- #config.logger = Logger.new(STDOUT)
- #end
+ #start_time = Time.now
+ #(1..runs).each {
+ #json_data = {:type => 'log', :content => {:message => 'zeromq test'}}
+ #json_data = json_data.to_json
+ #ZeroMQ.address = '127.0.0.1:5464'
+ #ZeroMQ.instance.post(json_data)
+ #}
+ #end_time = Time.now
+ #puts "ZeroMQ logging #{(end_time - start_time)} seconds"
+ Ramon.configure do |config|
+ config.address = '127.0.0.1:5464'
+ config.protocol = 'zeromq'
+ config.logger = Logger.new(STDOUT)
+ end
+
start_time = Time.now
(1..runs).each {
- json_data = {:type => 'log', :content => {:message => 'zeromq test'}}
- json_data = json_data.to_json
- ZeroMQ.address = '127.0.0.1:5464'
- ZeroMQ.instance.post(json_data)
+ Ramon.log('ramon zeromq test')
}
end_time = Time.now
- puts "ZeroMQ logging #{(end_time - start_time)} seconds"
+ puts "Ramon ZeroMQ logging #{(end_time - start_time)} seconds"
+
+
end
View
@@ -1,10 +1,6 @@
require 'net/http'
require 'json'
require 'zlib'
-begin
- require 'zmq'
-rescue LoadError
-end
module Ramon
class Sender
@@ -65,8 +61,7 @@ def post_http(type, data = {})
def post_zeromq(type, data = {})
if defined?(ZMQ)
- json_data = {:type => type,
- :content => data}
+ json_data = {:type => type, :content => data}
if app_key
json_data['app_key'] = app_key
end
@@ -75,9 +70,8 @@ def post_zeromq(type, data = {})
ZeroMQ.address = address
ZeroMQ.instance.post(json_data)
- true
else
- puts "ZeroMQ is not installed"
+ puts "ZeroMQ is not installed. You can install it with `gem install zmq`"
end
end
View
@@ -8,9 +8,11 @@ def self.address= address
end
def initialize
- context = ZMQ::Context.new()
+ context = ZMQ::Context.new(1)
@socket = context.socket(ZMQ::DEALER)
@socket.connect("tcp://#{@@address}")
+ @socket.setsockopt(ZMQ::LINGER, 0)
+ @socket.setsockopt(ZMQ::SWAP, 25000000) # 25MB disk swap
end
def post(data)

0 comments on commit 836b0af

Please sign in to comment.