lua-users home
lua-l archive

Re: [ANN] lua-geoip 0.1.1

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Fri, Mar 25, 2011 at 22:04, Petite Abeille <petite.abeille@gmail.com> wrote:
> On Mar 25, 2011, at 7:35 PM, Alexander Gladysh wrote:

>> Binary city DB can process about 100K queries/second on my machine,
>> and country DB — about 10K

> Hmmm... are you sure it's not the other way around? For countries, GeoIP.dat is ~1 MB. For cities, GeoLiteCity.dat weights ~30 MB. I would expect countries to be much faster than cities, no?

I would so too. But no. Here is a microbenchmark to prove it (see source below).

lua
-------------------------------------------------------------------
                name |     rel | abs s / iter = us (1e-6 s) / iter
-------------------------------------------------------------------
                city |  1.0000 |   8.71 /    1000000 = 8.710000 us
             country |  2.6625 |  23.19 /    1000000 = 23.190000 us
luajit2
-------------------------------------------------------------------
                name |     rel | abs s / iter = us (1e-6 s) / iter
-------------------------------------------------------------------
                city |  1.0000 |   6.48 /    1000000 = 6.480000 us
             country |  3.4969 |  22.66 /    1000000 = 22.660000 us

Run it with ./run_benchmark.sh lua-geoip.lua 1e6, using https://github.com/agladysh/luamarca. LuaJIT2 is LJ2b5.

Tests for lua-geoip also include more complete benchmark. 

https://github.com/agladysh/lua-geoip/blob/master/test/test.lua#L186

Here are the results from the same machine (luajit2 test/test.lua):

country49323.207403637ipnum queries per second
country48619.92706844addr queries per second
country18.74746325292name queries per second

city342370.6428249ipnum queries per second
city248724.68161516addr queries per second
city18.942332824983name queries per second

Somehow it is not 10x difference as I remembered it, but still, quite noticeable. (Note that name queries seem to be hindered by DNS lookup.)

Maybe it is a bug in my bindings code somewhere...

Alexander.

Microbenchmark source:

require 'geoip.city'
require 'geoip.country'

local IP = "8.8.8.8"

local CITY = assert(
    geoip.city.open(
        "./GeoLiteCity.dat"
      )
  )

local COUNTRY = assert(
    geoip.country.open(
        "./GeoIP.dat"
      )
  )

local bench = { }

bench.city = function()
  assert(CITY:query_by_addr(IP))
end

bench.country = function()
  assert(COUNTRY:query_by_addr(IP))
end

return bench


AltStyle によって変換されたページ (->オリジナル) /