Professional Documents
Culture Documents
Eric Lubow
CTO, SimpleReach
http://eric.lubow.org
@elubow
Funny Image
SimpleReach is Hiring
Isnt everyone?
elubow@simplereach.com
SimpleReach
Comparisons
MRI 1.8.7-p302
Written in C
Pros
C extensions
Cons
No Java integration
No Garbage collection
Static Compilation
jRuby 1.5.3
Java (Java Virtual Machine)
Runs Java code
Pros
Optimizations
Hotspotting
Forced Compile vs. JIT
Garbage Collection
Cons
Warm Up time
Hotspots
Dynamic profiling is the path to excellent
performance. HotSpot has the benefit of profile
data from the running application to inform
itself. It also has the ability to de-optimize code.
When Hotspot does an optimization it puts a
cheap guard in front of the optimization to make
sure the rationale for the optimization still holds
true. If the guard ever fails then it de-optimizes
back to a slow path. Thomas Enebo (EngineYard)
Hotspots
JSON Comparisons
JSON Pure
MRI
jRuby
Results
Benchmark.bmbm do |x|
x.report("parse:") { 100_000.times { parser.parse(json); } }
end
parsed = parser.parse(json)
100_000.times { parsed.to_json }
Benchmark.bmbm do |x|
x.report("encode:") { 100_000.times { parsed.to_json } }
end
Results
require 'yajl'
parser = Yajl::Parser.new
parser.on_parse_complete = lambda {|obj|}
100_000.times { parser.parse(json); }
Benchmark.bm do |x|
x.report("parse:") { parser.parse(json) }
end
parsed = parser.parse(json)
100_000.times { parsed.to_json }
Benchmark.bm do |x|
x.report("encode:") { parsed.to_json }
end
jRuby-1.5.3 w/ JSON-jRuby
Code
Results
json = File.read('bid1.json')
100_000.times { JSON.parse(json) }
Benchmark.bmbm do |x|
x.report("parse:") { 100_000.times {
JSON.parse(json) } }
end
parsed = JSON.parse(json)
100_000.times { parsed.to_json }
Benchmark.bmbm do |x|
x.report("encode:") { 100_000.times {
parsed.to_json } }
end
jRuby-1.5.3 w/ JSON-jRuby
Code
Results
json = File.read('bid1.json')
100_000.times { JSON.parse(json) }
Benchmark.bmbm do |x|
x.report("parse:") { JSON.parse(json) }
end
parsed = JSON.parse(json)
100_000.times { parsed.to_json }
Benchmark.bmbm do |x|
x.report("encode:") { parsed.to_json }
end
JSON Comparisons
Yajl
C extension
Not a drop in replacement
JSON-jRuby
Java extension
Drop in replacement
JSON-jRuby
elubow@beacon json$ jruby --server -JDjruby.compile.fastops=true -S parse.rb
Rehearsal -----------------------------------------parse: 12.433000 0.000000 12.433000 ( 12.433000)
-------------------------------- total: 12.433000sec
user system total
real
parse: 11.735000 0.000000 11.735000 ( 11.735000)
Rehearsal ------------------------------------------encode: 2.840000 0.000000 2.840000 ( 2.840000)
---------------------------------- total: 2.840000sec
user system total
real
encode: 2.868000 0.000000 2.868000 ( 2.868000)
JSON-jRuby
elubow@beacon json$ jruby --server -JDjruby.compile.fastops=true -S parse.rb
Rehearsal -----------------------------------------parse: 0.001000 0.000000 0.001000 ( 0.000000)
--------------------------------- total: 0.001000sec
user system total
real
parse: 0.000000 0.000000 0.000000 ( 0.000000)
Rehearsal ------------------------------------------encode: 0.001000 0.000000 0.001000 (
0.001000)
---------------------------------- total: 0.001000sec
user system total
real
encode: 0.000000 0.000000 0.000000 (
0.000000)
Mongo
Mongo
Mongo + BSON
Code
Results
require 'mongo'
require 'benchmark'
@db = Mongo::Connection.new('localhost',
27017).db(simplereach_website_development)
100_000.times { @db[ads].find({}).to_a }
Benchmark.bm do |x|
x.report(find:") { @db[ads'].find({}).to_a }
end
Conclusions
Still have lots of testing to do
Discovered JSON conversions werent a large
problem
Discovered BSON conversions are
C extensions
FFI (Foreign Function Interface)
References
http://www.engineyard.com/blog/2009/j-isfor-jvm-why-the-j-in-jruby/
http://eric.lubow.org/2010/ruby/jruby/jsonbenchmarks-in-jruby/
http://www.infoq.com/presentations/enebojruby
Questions?
Eric Lubow
http://eric.lubow.org
eric@lubow.org