java_bin
This is an Apache Solr JavaBin format (binary format) implementation for Ruby.
Features
-
fast parse(2.5 - 5 times faster than ruby eval), and less network traffic.
MRI 1.8.7
[data2]
ruby eval parse. 5000 times. elapsed time 6.664981
javabin parse. 5000 times. elapsed time 1.472825
4.52530409247534 times
REE 1.8.7
[data2]
ruby eval parse. 5000 times. elapsed time 4.844482
javabin parse. 5000 times. elapsed time 1.059044
4.57439162112245 times
YARV 1.9.2 pre1
[data2]
ruby eval parse. 5000 times. elapsed time 6.659331328
javabin parse. 5000 times. elapsed time 1.261828473
5.277525012704322 times
-
rsolr/solr-ruby support.
-
pure and c extension code.
-
ruby 1.8/1.9/2.0 support.
-
solr 1.4/3.1 support.
Requirements
-
Ruby1.8.7 or later (include 1.9.x, 2.0.x)
-
(recommended) C compiler (gcc or vc++): you can also use java_bin without c extension, but ‘pure’ is 30 times slower than ‘ext’.
-
JavaBin has been tested with MRI 1.8.7, REE 1.8.7, YARV 1.9.2, YARV 1.9.3 and 2.0.0 on CentOS6.3 (x86_64bit) with Apache Solr 1.4, 3.1
Install
(Linux)
gem sources -a http://gemcutter.org
gem install java_bin
(Windows)
fix (path to)\ruby\lib\ruby\1.8\i386-mswin32\config.h
#if _MSC_VER != 1200
↓
#if _MSC_VER < 1200
start => visual studio c++ 200x xxxx edition => visual studio tools => visual studio 200x command prompt
gem sources -a http://gemcutter.org
gem install java_bin
or
cd (path to)\ext\java_bin\ext
ruby extconf.rb
nmake
Simple Usage
require 'rubygems'
require 'java_bin'
@parser = JavaBin.parser.new
result = @parser.parse( javabin format string )
With RSolr/Solr-Ruby
-
By RSolr/Solr-Ruby support, a parser automatically uses javabin format instead of ruby format.
require 'rubygems'
require 'rsolr'
require 'java_bin'
solr = RSolr.connect
solr.select :q => '*:*'
Valgrind/Memory Leaks
-
In this project we use Valgrind (www.valgrind.org) to ensure that the native extension is leak-free.
-
On any Debian-based Linux you simply need to install the valgrind package:
apt-get install valgrind
-
On homebrew-powered OSX, simply type:
brew install valgrind
-
Then invoke the Rake task. If any errors are present, it will fail.
rake valgrind
TODO
-
more parse speed
-
license
-
shared string over parsing
-
builder(writer)
References
-
javabin wiki.apache.org/solr/javabin
-
javabin codec (for java) svn.apache.org/viewvc/lucene/solr/trunk/src/common/org/apache/solr/common/util/JavaBinCodec.java?view=markup
-
rsolr github.com/mwmitchell/rsolr/
-
solr-ruby wiki.apache.org/solr/solr-ruby
Note on Patches/Pull Requests
-
Fork the project.
-
Make your feature addition or bug fix.
-
Add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-
Send me a pull request. Bonus points for topic branches.
Author
Toshinori Kajihara <[email protected]>
Copyright
Copyright © 2010 - 2013 kennyj. See LICENSE for details.