Skip to content

Commit

Permalink
Add some perf tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jordansissel committed Dec 21, 2013
1 parent b828b55 commit 4db52ad
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 27 deletions.
19 changes: 19 additions & 0 deletions spec/codecs/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,25 @@
insist { event["bah"] } == data["bah"]
end
end

it "should be fast" do
json = '{"message":"Hello world!","@timestamp":"2013-12-21T07:01:25.616Z","@version":"1","host":"Macintosh.local","sequence":1572456}'
iterations = 500000
count = 0

# Warmup
10000.times { subject.decode(json) { } }

start = Time.now
iterations.times do
subject.decode(json) do |event|
count += 1
end
end
duration = Time.now - start
insist { count } == iterations
puts "codecs/json speed: #{iterations/duration}/sec"
end
end

context "#encode" do
Expand Down
20 changes: 20 additions & 0 deletions spec/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,24 @@
end
end
end

it "timestamp parsing speed", :if => ENV["SPEEDTEST"] do
warmup = 10000
count = 1000000

data = { "@timestamp" => "2013-12-21T07:25:06.605Z" }
event = LogStash::Event.new(data)
insist { event["@timestamp"] }.is_a?(Time)

duration = 0
[warmup, count].each do |i|
start = Time.now
i.times do
data = { "@timestamp" => "2013-12-21T07:25:06.605Z" }
LogStash::Event.new(data.clone)
end
duration = Time.now - start
end
puts "event @timestamp parse rate: #{count / duration}/sec"
end
end
2 changes: 1 addition & 1 deletion spec/filters/date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
insist { subject["mydate"] } == input
insist { subject["@timestamp"] } == Time.iso8601(output).utc
rescue
require "pry"; binding.pry
#require "pry"; binding.pry
raise
end
end
Expand Down
45 changes: 19 additions & 26 deletions spec/filters/date_performance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,27 @@
describe LogStash::Filters::Date, :if => RUBY_ENGINE == "jruby" do
extend LogStash::RSpec

describe "performance test of java syntax parsing", :if => ENV["SPEEDTEST"] do
describe "speed test of date parsing", :if => ENV["SPEEDTEST"] do
it "should be fast" do
event_count = 100000
min_rate = 4000
max_duration = event_count / min_rate
input = "Nov 24 01:29:01 -0800"

event_count = 100000
min_rate = 4000

max_duration = event_count / min_rate
input = "Nov 24 01:29:01 -0800"
config <<-CONFIG
input {
generator {
add_field => ["mydate", "#{input}"]
count => #{event_count}
type => "generator"
}
}
filter {
date {
match => [ "mydate", "MMM dd HH:mm:ss Z" ]
}
}
output { null { } }
CONFIG

2.times do
agent do
puts "date parse rate: #{event_count / @duration}"
insist { @duration } < max_duration
filter = LogStash::Filters::Date.new("match" => [ "mydate", "MMM dd HH:mm:ss Z" ])
filter.register
duration = 0
# 10000 for warmup
[10000, event_count].each do |iterations|
start = Time.now
iterations.times do
event = LogStash::Event.new("mydate" => input)
filter.execute(event)
end
duration = Time.now - start
end
puts "date parse rate: #{event_count / duration}"
insist { duration } < max_duration
end
end
end

0 comments on commit 4db52ad

Please sign in to comment.