nchan_tools 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1dd4ceddaf522f6a4e493ac215a17b9989cec0a8412dd7df99798cf0261206b
4
- data.tar.gz: 81988f661eaf53d32f06e1199f9508370c7fc65e481db90a23e81239fae10ffd
3
+ metadata.gz: 7ebb8bad8e4eab2ac6e0dafd8b93941d8001324158feadbd4638701d45b2ca0e
4
+ data.tar.gz: 89351ee1297b3b3bc01535e5da7a8fb2795ce16c0f3da3a7b1a5b89c2d6f4dcf
5
5
  SHA512:
6
- metadata.gz: 412ea567add374cc898383500193ca1b4fee644389777db3fe571561dc368f21256859e6266d54aba0fd332994036313ba3d62d44d79057c889bcac3b407912a
7
- data.tar.gz: 4503fe9cacadf0c6baafd2a44f15fd3891540c3378cb2893c2844f3260a9766c4d216b93d6ff1f0be335936dc9b805725af290e70a3fa36ba4db2c1c48414ae2
6
+ metadata.gz: 5cf14c247f20f07962a1087f6f9adf509576dc6e0b9d6e9285ce30401847c038d5ab072bd259271cac48212ebcdf571283a52e30ee79fabf0e3bd884e801a50c
7
+ data.tar.gz: 7dc9a2ad487a014212fa27b936f5bab403f428403eb22bbede56705d17dbfc44daff7b30005b82fe6dfb2289cdb1b9a8857473290e5011584f7e565c556f4e5e
@@ -11,6 +11,8 @@ require "HDRHistogram"
11
11
  verbose = false
12
12
  save_csv = false
13
13
 
14
+ init_args = {}
15
+
14
16
  opt_parser=OptionParser.new do |opts|
15
17
  opts.on("-v", "--verbose", "somewhat rather extraneously wordful output") do
16
18
  verbose = true
@@ -18,9 +20,23 @@ opt_parser=OptionParser.new do |opts|
18
20
  opts.on("--csv FILENAME", "Append results to file in CSV format") do |f|
19
21
  save_csv = f
20
22
  end
21
-
23
+ opts.on("-t", "--time TIME", "Time to run benchmark") do |v|
24
+ init_args[:time] = v
25
+ end
26
+ opts.on("-r", "--msgrate NUMBER", "Message publishing rate per minute per channel") do |v|
27
+ init_args[:messages_per_channel_per_minute] = v
28
+ end
29
+ opts.on("-p", "--msgpadding NUMBER", "Message padding, in bytes") do |v|
30
+ init_args[:message_padding_bytes] = v
31
+ end
32
+ opts.on("-c", "--channels NUMBER", "Number of channels") do |v|
33
+ init_args[:channels] = v
34
+ end
35
+ opts.on("-s", "--subscribers NUMBER", "Subscribers per channel") do |v|
36
+ init_args[:subscribers_per_channel] = v
37
+ end
22
38
  end
23
- opt_parser.banner="Usage: benchan.rb [options] url1 url2 url3..."
39
+ opt_parser.banner="Usage: nchan-benchmark [options] url1 url2 url3..."
24
40
  opt_parser.parse!
25
41
 
26
42
  urls = []
@@ -33,7 +49,9 @@ end
33
49
  urls.uniq!
34
50
 
35
51
  class Benchan
36
- def initialize(urls)
52
+ class BenchmarkError < StandardError
53
+ end
54
+ def initialize(urls, init_args=nil)
37
55
  @urls = urls
38
56
  @n = urls.count
39
57
  @initializing = 0
@@ -44,6 +62,8 @@ class Benchan
44
62
  @results = {}
45
63
  @failed = {}
46
64
 
65
+ @init_args = init_args
66
+
47
67
  @hdrh_publish = nil
48
68
  @hdrh_receive = nil
49
69
 
@@ -66,14 +86,14 @@ class Benchan
66
86
  sub.on_message do |msg|
67
87
  msg = msg.to_s
68
88
  case msg
69
- when "READY"
89
+ when /^READY/
70
90
  puts " #{sub.url} ok"
71
91
  @ready +=1
72
92
  if @ready == @n
73
93
  control :run
74
94
  puts "start benchmark..."
75
95
  end
76
- when "RUNNING"
96
+ when /^RUNNING/
77
97
  puts " #{sub.url} running"
78
98
  when /^RESULTS\n/
79
99
  msg = msg[8..-1]
@@ -81,9 +101,10 @@ class Benchan
81
101
  @results[sub.url] = parsed
82
102
  @results[sub.url]["raw"] = msg if @results[sub.url]
83
103
  1+1
104
+ when /^INITIALIZING/
105
+ #do nothing
84
106
  else
85
- binding.pry
86
- 1+1
107
+ raise BenchmarkError, "unexpected server response: #{msg}"
87
108
  end
88
109
  end
89
110
  @subs << sub
@@ -97,7 +118,7 @@ class Benchan
97
118
  end
98
119
  return if @failed.count > 0
99
120
  puts "initializing benchmark..."
100
- control :initialize
121
+ control :init
101
122
  self.wait
102
123
  puts "finished."
103
124
  puts ""
@@ -108,6 +129,9 @@ class Benchan
108
129
  end
109
130
 
110
131
  def control(msg)
132
+ if @init_args && (msg.to_sym ==:init || msg.to_sym ==:initialize)
133
+ msg = "#{msg.to_s} #{@init_args.map{|k,v| "#{k}=#{v}"}.join(" ")}"
134
+ end
111
135
  @subs.each { |sub| sub.client.send_data msg.to_s }
112
136
  end
113
137
 
@@ -237,7 +261,7 @@ class Benchan
237
261
  end
238
262
  end
239
263
 
240
- benchan = Benchan.new urls
264
+ benchan = Benchan.new urls, init_args
241
265
  benchan.run
242
266
  benchan.results
243
267
  benchan.append_csv_file(save_csv) if save_csv
@@ -248,7 +248,7 @@ class Subscriber
248
248
  end
249
249
  end
250
250
 
251
- class SubscriberError < Exception
251
+ class SubscriberError < StandardError
252
252
  end
253
253
  class Client
254
254
  attr_accessor :concurrency
@@ -1646,7 +1646,7 @@ end
1646
1646
  class Publisher
1647
1647
  #include Celluloid
1648
1648
 
1649
- class PublisherError < Exception
1649
+ class PublisherError < StandardError
1650
1650
  end
1651
1651
 
1652
1652
  attr_accessor :messages, :response, :response_code, :response_body, :nofail, :accept, :url, :extra_headers, :verbose, :ws, :channel_info, :channel_info_type
@@ -1,3 +1,3 @@
1
1
  module NchanTools
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nchan_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leo Ponomarev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-03 00:00:00.000000000 Z
11
+ date: 2018-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus