Skip to content

Instantly share code, notes, and snippets.

View charliedavi's full-sized avatar

Charlie Davies charliedavi

View GitHub Profile
require 'java'
require 'libssrckdtree-j-1.0.2.jar'
def rand_coord
rand(0) * 10 - 5
end
@kdsize = 1000
@points = (0...1000).map { |i| [rand_coord, rand_coord, i ] }
Firstly I know that having a C extension in JRUBY is not a great idea, however, I am kind of being forced in a way.
I have a system at the moment that uses a Ruby KDTree https://github.com/MagLev/maglev/tree/master/examples/persistence/kdtree/
It works, but its not very quick. I am using Jruby because of its great performance and would love to stay with it.
To improve the speed of the KDTree, I found and used https://github.com/consti/tupalo-kdtree which is crazy quick, it also has the same syntax for use http://rubydoc.info/gems/tupalo-kdtree/0.2.3/frames and it works great under MRI 1.9.3 - it brings down on benchmark from 30 seconds to around 0.01 seconds.
However when I try and load this gem in Jruby it only works to load using JRUBY_OPTS=--1.8 - which is odd, but it loads find and installs.
charlie@Charlie-Vostro ~/tech/dev/lab/kdtree $ gem install tupalo-kdtree
Building native extensions. This could take a while...
Successfully installed tupalo-kdtree-0.2.3
1 gem installed
charlie@Charlie-Vostro ~/tech/dev/lab/kdtree $ ruby newtest.rb
LoadError: no such file to load -- kdtree
require at org/jruby/RubyKernel.java:1033
require at /home/charlie/.rvm/rubies/jruby-1.6.7/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36
(root) at newtest.rb:2
charlie@Charlie-Vostro ~/tech/dev/lab/kdtree $
JAVA_OPTS already set in environment; overriding default settings with values: -XX:MaxPermSize=2000m -Xmx4000m
=========================================================================
JBoss Bootstrap Environment
JBOSS_HOME: /home/charlie/tech/server/torquebox-current/jboss
JAVA: java
JAVA_OPTS: -server -XX:+UseCompressedOops -XX:+TieredCompilation -XX:MaxPermSize=2000m -Xmx4000m
class PostCodeGo
class << self
include TorqueBox::Messaging::Backgroundable
always_background :postcode, :priority => :normal
def postcode(time, origin, mode, email)
iso = Real::Chrone.new_or_cached(time: time, origin: origin, mode: mode.to_sym)
csvs = [iso.postcode_csv, iso.postcode_sector_csv, iso.postcode_district_csv]
source 'http://rubygems.org'
gem 'rails', '3.1.0'
gem 'rake'
# Asset template engines
gem 'sass'
gem 'coffee-script'
gem 'uglifier'
gem 'jquery-rails'
gem 'rails-backbone'
(in /home/charlie/dev/igeolise-api)
/home/charlie/.rvm/gems/jruby-1.6.5.1@global/gems/bundler-1.0.21/lib/bundler/rubygems_integration.rb:161 warning: already initialized constant Deprecate
/home/charlie/.rvm/gems/jruby-1.6.5.1@global/gems/bundler-1.0.21/lib/bundler/rubygems_ext.rb:151 warning: already initialized constant JAVA
/home/charlie/.rvm/gems/jruby-1.6.5.1@global/gems/bundler-1.0.21/lib/bundler/rubygems_ext.rb:152 warning: already initialized constant MSWIN
/home/charlie/.rvm/gems/jruby-1.6.5.1@global/gems/bundler-1.0.21/lib/bundler/rubygems_ext.rb:153 warning: already initialized constant MINGW
/home/charlie/.rvm/gems/jruby-1.6.5.1@global/gems/bundler-1.0.21/lib/bundler/rubygems_ext.rb:202 warning: already initialized constant GENERIC_CACHE
/home/charlie/.rvm/gems/jruby-1.6.5.1@global/gems/bundler-1.0.21/lib/bundler/rubygems_ext.rb:203 warning: already initialized constant GENERICS
/home/charlie/.rvm/gems/jruby-1.6.5.1@global/gems/bundler-1.0.21/lib/bundler.rb:17 warning: already initialized constant
** [10:42:52 2012-01-23] 6518: resque-1.19.0: Processing email since 1327315372
rake aborted!
Java heap space
java.util.Arrays.copyOf(Arrays.java:2894)
java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:117)
java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:407)
java.lang.StringBuilder.append(StringBuilder.java:136)
org.jruby.RubyBasicObject.inspectObj(RubyBasicObject.java:1108)
org.jruby.RubyBasicObject.hashyInspect(RubyBasicObject.java:1080)
org.jruby.RubyBasicObject.inspect(RubyBasicObject.java:1059)
IgeoliseApi::Application.routes.draw do
# The priority is based upon order of creation:
# first created -> highest priority.
resources :iterations
resource :time_filter do
post :email_csv, on: :collection
end
resource :route_tree do
post :email_csvs, on: :collection
:public is no longer used to avoid overloading Module#public, use :public_folder instead
from /home/charlie/.rvm/gems/jruby-1.6.4/gems/resque-1.19.0/lib/resque/server.rb:12:in `Server'
19-Jan-2012 17:18:03 sun.reflect.NativeMethodAccessorImpl invoke0
INFO: Using Ehcache version 2.4.6
** Invoke default (first_time)
** Invoke spec (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment