nchan_tools 0.1.1 → 0.1.2

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: 03c7684cee5fb57143e8411351aea95d4bcb989cf8f2d66ebe716655f8f07b09
4
- data.tar.gz: ed22f3cdd7eb55acab2ad29684daacd4e09edf0a3ffda1c4e2d5309affa896f3
3
+ metadata.gz: a1dd4ceddaf522f6a4e493ac215a17b9989cec0a8412dd7df99798cf0261206b
4
+ data.tar.gz: 81988f661eaf53d32f06e1199f9508370c7fc65e481db90a23e81239fae10ffd
5
5
  SHA512:
6
- metadata.gz: 3009d9a05e5f8d6d81302cf81389be78ef165621fd433fd08beb1d16d0dcba5fa7cbcc6dd56a83a86a6d4756dcd609fa33136031bb4a50077f0d811405aef0ce
7
- data.tar.gz: cae127fd3166e2442625f3a177e6060561fb8fb0056dc63cc14f03b89404c80a87e1cfd9ee2ed3a0078f91e6665c4b090492f257e5e308368af1cff32a0e23c1
6
+ metadata.gz: 412ea567add374cc898383500193ca1b4fee644389777db3fe571561dc368f21256859e6266d54aba0fd332994036313ba3d62d44d79057c889bcac3b407912a
7
+ data.tar.gz: 4503fe9cacadf0c6baafd2a44f15fd3891540c3378cb2893c2844f3260a9766c4d216b93d6ff1f0be335936dc9b805725af290e70a3fa36ba4db2c1c48414ae2
@@ -9,11 +9,16 @@ require "pry"
9
9
  require "HDRHistogram"
10
10
 
11
11
  verbose = false
12
+ save_csv = false
12
13
 
13
14
  opt_parser=OptionParser.new do |opts|
14
15
  opts.on("-v", "--verbose", "somewhat rather extraneously wordful output") do
15
16
  verbose = true
16
17
  end
18
+ opts.on("--csv FILENAME", "Append results to file in CSV format") do |f|
19
+ save_csv = f
20
+ end
21
+
17
22
  end
18
23
  opt_parser.banner="Usage: benchan.rb [options] url1 url2 url3..."
19
24
  opt_parser.parse!
@@ -74,6 +79,7 @@ class Benchan
74
79
  msg = msg[8..-1]
75
80
  parsed = JSON.parse msg
76
81
  @results[sub.url] = parsed
82
+ @results[sub.url]["raw"] = msg if @results[sub.url]
77
83
  1+1
78
84
  else
79
85
  binding.pry
@@ -128,59 +134,59 @@ class Benchan
128
134
  end
129
135
 
130
136
  def results
131
- channels = 0
132
- runtime = []
133
- subscribers = 0
134
- message_length = []
135
- messages_sent = 0
136
- messages_send_confirmed = 0
137
- messages_send_unconfirmed = 0
138
- messages_send_failed = 0
139
- messages_received = 0
140
- messages_unreceived = 0
141
- hdrh_publish = nil
142
- hdrh_receive = nil
137
+ @channels = 0
138
+ @runtime = []
139
+ @subscribers = 0
140
+ @message_length = []
141
+ @messages_sent = 0
142
+ @messages_send_confirmed = 0
143
+ @messages_send_unconfirmed = 0
144
+ @messages_send_failed = 0
145
+ @messages_received = 0
146
+ @messages_unreceived = 0
147
+ @hdrh_publish = nil
148
+ @hdrh_receive = nil
143
149
  @results.each do |url, data|
144
- channels += data["channels"]
145
- runtime << data["run_time_sec"]
146
- subscribers += data["subscribers"]
147
- message_length << data["message_length"]
148
- messages_sent += data["messages"]["sent"]
149
- messages_send_confirmed += data["messages"]["send_confirmed"]
150
- messages_send_unconfirmed += data["messages"]["send_unconfirmed"]
151
- messages_send_failed += data["messages"]["send_failed"]
152
- messages_received += data["messages"]["received"]
153
- messages_unreceived += data["messages"]["unreceived"]
150
+ @channels += data["channels"]
151
+ @runtime << data["run_time_sec"]
152
+ @subscribers += data["subscribers"]
153
+ @message_length << data["message_length"]
154
+ @messages_sent += data["messages"]["sent"]
155
+ @messages_send_confirmed += data["messages"]["send_confirmed"]
156
+ @messages_send_unconfirmed += data["messages"]["send_unconfirmed"]
157
+ @messages_send_failed += data["messages"]["send_failed"]
158
+ @messages_received += data["messages"]["received"]
159
+ @messages_unreceived += data["messages"]["unreceived"]
154
160
 
155
161
  if data["message_publishing_histogram"]
156
162
  hdrh = HDRHistogram.unserialize(data["message_publishing_histogram"], unit: :ms, multiplier: 0.001)
157
- if hdrh_publish
158
- hdrh_publish.merge! hdrh
163
+ if @hdrh_publish
164
+ @hdrh_publish.merge! hdrh
159
165
  else
160
- hdrh_publish = hdrh
166
+ @hdrh_publish = hdrh
161
167
  end
162
168
  end
163
169
  if data["message_delivery_histogram"]
164
170
  hdrh = HDRHistogram.unserialize(data["message_delivery_histogram"], unit: :ms, multiplier: 0.001)
165
- if hdrh_receive
166
- hdrh_receive.merge! hdrh
171
+ if @hdrh_receive
172
+ @hdrh_receive.merge! hdrh
167
173
  else
168
- hdrh_receive = hdrh
174
+ @hdrh_receive = hdrh
169
175
  end
170
176
  end
171
177
  end
172
178
 
173
- message_length.uniq!
174
- runtime.uniq!
179
+ @message_length = @message_length.sum.to_f / @message_length.size
180
+ @runtime = @runtime.sum.to_f / @runtime.size
175
181
 
176
182
  fmt = <<-END.gsub(/^ {6}/, '')
177
183
  Nchan servers: %d
178
- runtime: %s
184
+ runtime: %d
179
185
  channels: %d
180
186
  subscribers: %d
181
187
  subscribers per channel: %.1f
182
188
  messages:
183
- length: %s
189
+ length: %d
184
190
  sent: %d
185
191
  send_confirmed: %d
186
192
  send_unconfirmed: %d
@@ -193,22 +199,46 @@ class Benchan
193
199
  receive rate per subscriber: %.3f/min
194
200
  END
195
201
  out = fmt % [
196
- @n, runtime.join(","), channels, subscribers, subscribers.to_f/channels,
197
- message_length.join(","), messages_sent, messages_send_confirmed, messages_send_unconfirmed, messages_send_failed,
198
- messages_received, messages_unreceived,
199
- messages_sent.to_f/runtime.max,
200
- messages_received.to_f/runtime.max,
201
- (messages_sent.to_f* 60)/(runtime.max*channels),
202
- (messages_received.to_f * 60)/(runtime.max * subscribers)
202
+ @n, @runtime, @channels, @subscribers, @subscribers.to_f/@channels,
203
+ @message_length, @messages_sent, @messages_send_confirmed, @messages_send_unconfirmed, @messages_send_failed,
204
+ @messages_received, @messages_unreceived,
205
+ @messages_sent.to_f/@runtime,
206
+ @messages_received.to_f/@runtime,
207
+ (@messages_sent.to_f* 60)/(@runtime * @channels),
208
+ (@messages_received.to_f * 60)/(@runtime * @subscribers)
203
209
  ]
204
210
 
205
- out << hdrhistogram_stats("message publishing latency", hdrh_publish) if hdrh_publish
206
- out << hdrhistogram_stats("message delivery latency", hdrh_receive) if hdrh_receive
211
+ out << hdrhistogram_stats("message publishing latency", @hdrh_publish) if @hdrh_publish
212
+ out << hdrhistogram_stats("message delivery latency", @hdrh_receive) if @hdrh_receive
207
213
 
208
214
  puts out
209
215
  end
216
+
217
+ def append_csv_file(file)
218
+ require "csv"
219
+ write_headers = File.zero?(file)
220
+ headers = %i[servers runtime channels subscribers
221
+ message_length messages_sent messages_send_confirmed messages_send_unconfirmed messages_send_failed
222
+ messages_send_received messages_send_unreceived
223
+ messages_send_rate messages_receive_rate messages_send_rate_per_channel messages_receive_rate_per_subscriber
224
+ message_publishing_response_avg message_publishing_response_99percentile message_publishing_response_stddev message_publishing_response_count
225
+ message_delivery_avg message_delivery_99percentile message_delivery_stddev message_delivery_count]
226
+ csv = CSV.open(file, "a", {headers: headers, write_headers: write_headers})
227
+ csv << [@n, @runtime, @channels, @subscribers,
228
+ @message_length, @messages_sent, @messages_send_confirmed, @messages_send_unconfirmed, @messages_send_failed,
229
+ @messages_received, @messages_unreceived,
230
+ @messages_sent.to_f/@runtime, @messages_received.to_f/@runtime,
231
+ (@messages_sent.to_f* 60)/(@runtime * @channels), (@messages_received.to_f * 60)/(@runtime * @subscribers),
232
+ @hdrh_publish.mean, @hdrh_publish.percentile(99.0), @hdrh_publish.max, @hdrh_publish.stddev, @hdrh_publish.count,
233
+ @hdrh_receive.mean, @hdrh_receive.percentile(99.0), @hdrh_receive.max, @hdrh_receive.stddev, @hdrh_receive.count
234
+ ]
235
+ csv.flush
236
+ csv.close
237
+ end
210
238
  end
211
239
 
212
240
  benchan = Benchan.new urls
213
241
  benchan.run
214
242
  benchan.results
243
+ benchan.append_csv_file(save_csv) if save_csv
244
+
@@ -1,3 +1,3 @@
1
1
  module NchanTools
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
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.1
4
+ version: 0.1.2
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-09-30 00:00:00.000000000 Z
11
+ date: 2018-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus