pulse-meter 0.4.4 → 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,29 @@
1
+ $:.unshift File.expand_path('../../lib/', __FILE__)
2
+
3
+ require "pulse-meter"
4
+
5
+ PulseMeter.redis = Redis.new
6
+ PulseMeter.redis.flushdb
7
+ PulseMeter.command_aggregator = PulseMeter::CommandAggregator::UDP.new([['127.0.0.1', 33333], ['127.0.0.1', 33334], ['127.0.0.1', 33335],])
8
+
9
+ ss = PulseMeter::Sensor::Configuration.new(
10
+ cnt: {sensor_type: 'counter'}
11
+ )
12
+
13
+ start = Time.now.to_f
14
+
15
+ i = 0
16
+ loop do
17
+ i += 1
18
+ ss.cnt(1)
19
+ sleep 0.000005
20
+ if i % 1000 == 0
21
+ t = Time.now.to_f
22
+ passed = t - start
23
+ required_rps = i.to_f / passed
24
+ val = ss.sensor(:cnt){|s| s.value}
25
+ actual_rps = val.to_f / passed
26
+ p [i, required_rps, val, actual_rps]
27
+ end
28
+ end
29
+
@@ -5,9 +5,13 @@ module PulseMeter
5
5
  module CommandAggregator
6
6
  class UDP
7
7
 
8
- def initialize(servers = [])
9
- raise ArgumentError, "No servers specified" if servers.empty?
10
- @servers = servers
8
+ def initialize(host, port = nil)
9
+ @servers = if host.is_a?(Array)
10
+ host
11
+ else
12
+ [[host, port]]
13
+ end
14
+ raise ArgumentError, "No servers specified" if @servers.empty?
11
15
  @buffer = []
12
16
  @in_multi = false
13
17
  @sock = UDPSocket.new
@@ -26,8 +26,10 @@ module PulseMeter
26
26
  def process_packet
27
27
  raw_data, _ = @socket.recvfrom(MAX_PACKET)
28
28
  data = parse_data(raw_data)
29
- data.each do |command|
30
- PulseMeter.redis.send(*command)
29
+ PulseMeter.redis.multi do
30
+ data.each do |command|
31
+ PulseMeter.redis.send(*command)
32
+ end
31
33
  end
32
34
  rescue StandardError => e
33
35
  PulseMeter.error "Error processing packet: #{e}"
@@ -1,3 +1,3 @@
1
1
  module PulseMeter
2
- VERSION = "0.4.4"
2
+ VERSION = "0.4.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pulse-meter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-02-08 00:00:00.000000000 Z
13
+ date: 2013-02-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: gon-sinatra
@@ -411,6 +411,7 @@ files:
411
411
  - examples/readme_client.rb
412
412
  - examples/readme_client_conf.rb
413
413
  - examples/server_config.yml
414
+ - examples/udp_benchmark.rb
414
415
  - lib/cmd.rb
415
416
  - lib/pulse-meter.rb
416
417
  - lib/pulse-meter/command_aggregator/async.rb