jgeoip 0.1.5-java → 0.1.6-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rvmrc +1 -1
- data/README.md +23 -10
- data/lib/java/jgeoip-0.1.6.jar +0 -0
- data/lib/jgeoip/version.rb +1 -1
- data/script/benchmark.rb +23 -14
- data/src/main/java/org/github/tobsch/jgeoip/LocationProxy.java +6 -0
- data/test/unit/jgeoip_test.rb +16 -0
- metadata +2 -2
- data/lib/java/jgeoip-0.1.5.jar +0 -0
data/.rvmrc
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
rvm use jruby-
|
1
|
+
rvm use jruby-1.6.7
|
2
2
|
|
data/README.md
CHANGED
@@ -1,32 +1,45 @@
|
|
1
|
-
|
1
|
+
# Fast JRuby GeoIP Extension
|
2
2
|
This jRuby extension will help you with all your GeoIP needs in JRuby.
|
3
3
|
It is pretty small and simple right now but will surely grow up soon.
|
4
4
|
You can easily use it with the free GeoIP Library from maxmind.com aswell as the commercial one.
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
## example
|
7
|
+
### City Lookup
|
8
8
|
p JGeoIP.new('/opt/MaxMind/GeoLiteCity.dat').city('github.com')
|
9
9
|
|
10
10
|
Will return a Location object with all the result properties and a #to_hash method
|
11
|
+
|
12
|
+
### Distance between two locations (km)
|
13
|
+
p1 = @geo.city('github.com')
|
14
|
+
p2 = @geo.city('facebook.com')
|
15
|
+
|
16
|
+
p p1.distance(p2)
|
17
|
+
# => 46.25354059751858
|
11
18
|
|
12
|
-
|
13
|
-
### speed?
|
19
|
+
## speed?
|
14
20
|
There is a benchmark script included, so you'll be able to check it yourself.
|
15
21
|
We compared it to the GeoIP gem so far (because geoip-c won't compile with jRuby).
|
16
22
|
Results are promising:
|
17
23
|
|
18
|
-
|
19
|
-
35.614000 0.000000 35.614000 ( 35.614000)
|
24
|
+
#### JGeoIP
|
20
25
|
JGeoIP (>=0.1.5):
|
21
26
|
0.285000 0.000000 0.285000 ( 0.286000)
|
22
|
-
JGeoIP (non extension version, <0.1.5):
|
27
|
+
JGeoIP (old non extension version, <0.1.5):
|
23
28
|
1.047000 0.000000 1.047000 ( 1.048000)
|
24
|
-
|
29
|
+
|
30
|
+
#### Others
|
31
|
+
pure ruby GeoIP (jRuby):
|
32
|
+
35.614000 0.000000 35.614000 ( 35.614000)
|
33
|
+
geoip-c (MRI 1.9.3-p0):
|
34
|
+
1.140000 0.000000 1.140000 ( 1.145224)
|
35
|
+
pure ruby GeoIP (MRI 1.9.3-p0):
|
36
|
+
30.060000 16.420000 46.480000 ( 60.940723)
|
37
|
+
*Cool, eh?*
|
38
|
+
|
25
39
|
Please note that we did a warmup to give the JIT a chance.
|
26
40
|
The benchmark does 100k lookups.
|
27
41
|
Those results are Java 7, jruby-1.6.5 based. Looking forward to 1.7.0.
|
28
42
|
|
29
43
|
### TODO
|
30
|
-
* switch back to an extension and a proxy object: this is surely faster. but time is money at the moment
|
31
44
|
* integrate the other lookup methods: so far we're just able to do city lookups
|
32
45
|
* check all the license related stuff: the maxmind lib is LGPL, which would be okay for me
|
Binary file
|
data/lib/jgeoip/version.rb
CHANGED
data/script/benchmark.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'benchmark'
|
2
|
+
require 'rubygems'
|
2
3
|
|
3
4
|
def benchmark(description, &block)
|
4
5
|
puts description
|
@@ -13,24 +14,32 @@ def benchmark(description, &block)
|
|
13
14
|
}
|
14
15
|
}
|
15
16
|
end
|
16
|
-
# check the JGeoIP
|
17
|
-
require File.expand_path('../../lib/jgeoip.rb', __FILE__)
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
#
|
23
|
-
|
24
|
-
# end
|
18
|
+
jruby = defined?(JRUBY_VERSION)
|
19
|
+
DB_FILE = '/opt/MaxMind/GeoLiteCity.dat'
|
20
|
+
if jruby
|
21
|
+
# check the JGeoIP
|
22
|
+
require File.expand_path('../../lib/jgeoip.rb', __FILE__)
|
25
23
|
|
26
|
-
db = JGeoIP.new(
|
27
|
-
benchmark 'JGeoIP:' do
|
28
|
-
|
24
|
+
db = JGeoIP.new(DB_FILE)
|
25
|
+
benchmark 'JGeoIP:' do
|
26
|
+
result = db.city('github.com')
|
27
|
+
end
|
29
28
|
end
|
30
29
|
|
31
|
-
|
32
|
-
|
30
|
+
# check the pure lib
|
31
|
+
gem 'geoip'
|
32
|
+
require 'geoip'
|
33
|
+
db = GeoIP.new(DB_FILE)
|
34
|
+
benchmark 'pure ruby GeoIP:' do
|
33
35
|
result = db.city('github.com')
|
34
36
|
end
|
35
37
|
|
36
|
-
|
38
|
+
unless jruby
|
39
|
+
gem 'geoip-c'
|
40
|
+
require 'geoip-c/geoip'
|
41
|
+
db = GeoIP::City.new(DB_FILE)
|
42
|
+
benchmark 'geoip-c:' do
|
43
|
+
db.look_up('207.97.227.239')
|
44
|
+
end
|
45
|
+
end
|
@@ -79,6 +79,12 @@ public class LocationProxy extends RubyObject {
|
|
79
79
|
}
|
80
80
|
}
|
81
81
|
|
82
|
+
@JRubyMethod
|
83
|
+
public IRubyObject distance(ThreadContext context, IRubyObject p2) {
|
84
|
+
LocationProxy p2loc = (LocationProxy)p2;
|
85
|
+
return context.runtime.newFloat(location.distance(p2loc.location));
|
86
|
+
}
|
87
|
+
|
82
88
|
@JRubyMethod
|
83
89
|
public IRubyObject inspect(ThreadContext context) {
|
84
90
|
return toHash(context).inspect();
|
data/test/unit/jgeoip_test.rb
CHANGED
@@ -24,6 +24,22 @@ class JGeoIPTest < Test::Unit::TestCase
|
|
24
24
|
assert_equal 'United States', result[:country_name]
|
25
25
|
end
|
26
26
|
|
27
|
+
should 'find out the distance between to points' do
|
28
|
+
p1 = @geo.city('github.com')
|
29
|
+
p2 = @geo.city('alice.de')
|
30
|
+
p3 = @geo.city('facebook.com')
|
31
|
+
# from sf to hamburg
|
32
|
+
assert_equal 8893.200366609715, p1.distance(p2)
|
33
|
+
|
34
|
+
# from sf to sf
|
35
|
+
assert_equal 46.25354059751858, p1.distance(p3)
|
36
|
+
|
37
|
+
# no valid loation
|
38
|
+
assert_raises Java::JavaLang::ClassCastException do
|
39
|
+
p1.distance('foo')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
27
43
|
should 'return nil if an attribute does not exist' do
|
28
44
|
result = @geo.city('207.97.227.239')
|
29
45
|
assert_equal nil, result[:fooooooo]
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: jgeoip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.6
|
6
6
|
platform: java
|
7
7
|
authors:
|
8
8
|
- Tobias Schlottke
|
@@ -70,7 +70,7 @@ files:
|
|
70
70
|
- Rakefile
|
71
71
|
- jgeoip.gemspec
|
72
72
|
- lib/java/geoip-1.2.5.jar
|
73
|
-
- lib/java/jgeoip-0.1.
|
73
|
+
- lib/java/jgeoip-0.1.6.jar
|
74
74
|
- lib/jgeoip.rb
|
75
75
|
- lib/jgeoip/version.rb
|
76
76
|
- script/benchmark.rb
|
data/lib/java/jgeoip-0.1.5.jar
DELETED
Binary file
|