Created
December 21, 2016 09:06
-
-
Save okkez/4c72d7ce127a89246010cce492b3abe3 to your computer and use it in GitHub Desktop.
Benchmark for filter_geoip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark" | |
require "fluent/plugin/filter_geoip" | |
require "fluent/test/driver/filter" | |
require "fluent/test" | |
conf_geoip = <<CONF | |
geoip_lookup_key host | |
backend_library geoip | |
<record> | |
city ${city["host"]} | |
latitude ${latitude["host"]} | |
longitude ${longitude["host"]} | |
country_code3 ${country_code3["host"]} | |
country ${country_code["host"]} | |
country_name ${country_name["host"]} | |
#dma ${dma_code["host"]} | |
#area ${area_code["host"]} | |
region ${region["host"]} | |
</record> | |
flush_interval 1s | |
CONF | |
conf_geoip2_compat = <<CONF | |
geoip_lookup_key host | |
backend_library geoip2_compat | |
<record> | |
city ${city["host"]} | |
latitude ${latitude["host"]} | |
longitude ${longitude["host"]} | |
country ${country_code["host"]} | |
country_name ${country_name["host"]} | |
postal_code ${postal_code["host"]} | |
region ${region["host"]} | |
</record> | |
flush_interval 1s | |
CONF | |
conf_geoip2 = <<CONF | |
geoip_lookup_key host | |
backend_library geoip2 | |
<record> | |
city ${city.names.en["host"]} | |
latitude ${location.latitude["host"]} | |
longitude ${location.longitude["host"]} | |
country ${country.iso_code["host"]} | |
country_name ${country.names.en["host"]} | |
postal_code ${postal.code["host"]} | |
region ${subdivisions.0.iso_code["host"]} | |
</record> | |
flush_interval 1s | |
CONF | |
geoip = Fluent::Test::Driver::Filter.new(Fluent::Plugin::GeoipFilter).configure(conf_geoip) | |
geoip2_compat = Fluent::Test::Driver::Filter.new(Fluent::Plugin::GeoipFilter).configure(conf_geoip2_compat) | |
geoip2 = Fluent::Test::Driver::Filter.new(Fluent::Plugin::GeoipFilter).configure(conf_geoip2) | |
def random_ip_addresses(address_mask, n = 10) | |
IPAddr.new(address_mask).to_range.to_a.sample(n).map(&:to_s) | |
end | |
def run_driver(driver, messages) | |
driver.run(default_tag: "input.access") do | |
messages.each do |message| | |
driver.feed(message) | |
end | |
end | |
end | |
ips = [] | |
# generate 10000 IP addresses | |
1000.times do | |
ips.concat(random_ip_addresses("#{rand(256)}.#{rand(256)}.#{rand(256)}.0/24")) | |
end | |
messages = ips.map do |ip| | |
{ "host" => ip } | |
end | |
Benchmark.bm do |x| | |
x.report("geoip") do | |
run_driver(geoip, messages) | |
end | |
x.report("geoip2_compat") do | |
run_driver(geoip2_compat, messages) | |
end | |
x.report("geoip2") do | |
run_driver(geoip2, messages) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cd fluent-plugin-geoip | |
$ bundle install | |
$ bundle exec ruby bench.rb | |
user system total real | |
geoip 0.380000 0.000000 0.380000 ( 0.384503) | |
geoip2_compat 0.360000 0.000000 0.360000 ( 0.359350) | |
geoip2 0.120000 0.000000 0.120000 ( 0.121645) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment