Replaced 'alias' calls with an instance variable.#47
Conversation
|
Hi @fimmtiu, thanks for the contribution! I didn't know about 1, do you know in this particular case what is the impact? My main concern is sacrificing the performance of the non-batched Thanks again for raising this issue! |
|
@degemer Good suggestion about the performance test! I've written a quick benchmark script, and the results seem to indicate that this PR is about the same for most cases, and faster in the case of small batches. On master: On the Here's the script I was testing with: #!/usr/bin/env ruby
require 'benchmark'
require 'rubygems'
$: << './lib'
require 'datadog/statsd'
statsd = Datadog::Statsd.new('localhost', 8125)
n = 5_000_000
Benchmark.bm(16) do |x|
x.report("regular") do
n.times { statsd.increment('woo') }
end
x.report("batched single") do
n.times do
statsd.batch { |s| s.increment('woo') }
end
end
x.report("batched 1k") do
(n / 1_000).times do
statsd.batch do |s|
1_000.times { s.increment('woo') }
end
end
end
x.report("batched 10k") do
(n / 10_000).times do
statsd.batch do |s|
10_000.times { s.increment('woo') }
end
end
end
end |
|
Thanks a lot for the benchmark! I re-ran it locally and obtained the same results (small improvements for small batches, equivalent everywhere else). |
This fixes two problems with
batch:Calling
aliasblows out the Ruby method cache for the current class and all its subclasses, so for performance reasons you don't want to be callingaliason a regular basis.If an exception occurred while sending the batched data, it would get stuck in batched mode.
Also fixed up a few typos in the specs for fun.