Created
October 5, 2010 19:33
-
-
Save chuckremes/612176 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> db.ticks.findOne({'_id.cid': 732814}) | |
{ | |
"_id" : { | |
"cid" : 732814, | |
"ts" : 1245442500, | |
"drn" : 60 | |
}, | |
"vals" : [ | |
[ | |
3622, | |
0, | |
4 | |
] | |
] | |
} | |
# The "vals" array may have several thousand 3-element arrays inside of it |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Running the ruby program | |
Mac-Pro:perf cremes$ rvm use default | |
Using /Users/cremes/.rvm/gems/ruby-1.9.2-p0 | |
Mac-Pro:perf cremes$ time ruby test_mongo.rb | |
total ticks [155816736] | |
46.500000 9.390000 55.890000 (166.054945) | |
real 2m56.354s | |
user 0m46.640s | |
sys 0m9.461s | |
# Ran with an average of 100% cpu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Running the java program using the latest master (2.1) | |
Mac-Pro:examples cremestime $ java -classpath ../mongo.jar:../bson.jar:. Perf | |
total ticks [155816736] | |
real 9m43.431s | |
user 13m58.968s | |
sys 0m48.477s | |
# Ran with an average of 160% cpu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Running the Ruby program with JRuby | |
Mac-Pro:perf cremes$ rvm use jruby-1.5.1 | |
Using /Users/cremes/.rvm/gems/jruby-1.5.1 | |
Mac-Pro:perf cremes$ time ruby test_mongo.rb | |
total ticks [155816736] | |
544.005000 0.000000 544.005000 (544.005000) | |
real 9m16.736s | |
user 16m23.281s | |
sys 0m47.347s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.mongodb.Mongo; | |
import com.mongodb.DBCollection; | |
import com.mongodb.BasicDBObject; | |
import com.mongodb.BasicDBList; | |
import com.mongodb.DBObject; | |
import com.mongodb.DBCursor; | |
import com.mongodb.DB; | |
import java.util.Set; | |
import java.util.List; | |
public class Perf { | |
public static void main(String[] args) throws Exception { | |
// connect to the local database server | |
Mongo m = new Mongo( "192.168.0.104" ); | |
// get handle to "mydb" | |
DB db = m.getDB( "market_data" ); | |
// get a collection object to work with | |
DBCollection coll = db.getCollection("ticks"); | |
// query for a specific contract ID | |
BasicDBObject contract_query = new BasicDBObject(); | |
contract_query.put("_id.cid", 732814); | |
// request all ticks for a specific contract ordered by timestamp | |
DBCursor cur = coll.find(contract_query).sort( new BasicDBObject( "_id.ts", 1 )); | |
BasicDBList doc; | |
int count = 0; | |
while(cur.hasNext()) { | |
doc = (BasicDBList) cur.next().get("vals"); | |
count += doc.size(); | |
} | |
System.out.println("total ticks [" + count + "]"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'mongo' | |
require 'benchmark' | |
connection = Mongo::Connection.new '192.168.0.104' | |
db = connection.db "market_data" | |
collection = db.collection 'ticks' | |
cid = 732814 | |
cursor = Mongo::Cursor.new(collection, | |
{ | |
:timeout => false, | |
:limit => 0, | |
:skip => 0, | |
:order => [['_id.ts', Mongo::ASCENDING]], | |
:selector => { | |
'_id.cid' => cid | |
} | |
} | |
) | |
total_ticks = 0 | |
result = Benchmark.measure do | |
while cursor.has_next? | |
doc = cursor.next_document | |
total_ticks += doc['vals'].size | |
end | |
end | |
puts "total ticks [#{total_ticks}]" | |
puts result |
Also, reran with 2.1 release with -server and more heap and did NOT notice any performance difference. It ran the same as 2.1-master (or 2.2, whatever).
Mac-Pro:examples cremes$ java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02-279-10M3065)
Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01-279, mixed mode)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rerunning the Java program with a larger heap and -server gave some better results.
Mac-Pro:examples cremes$ time java -Xmx2g -server -classpath ../mongo.jar:../bson.jar:. Perf
total ticks [155816736]
real 7m5.905s
user 5m40.339s
sys 0m9.588s
This is better but still far slower than the Ruby C extension.