Skip to content

Commit

Permalink
update node-mongodb-native driver to V0.9.6-5
Browse files Browse the repository at this point in the history
  • Loading branch information
aheckmann committed Jul 6, 2011
1 parent 65208d1 commit 6b811a3
Show file tree
Hide file tree
Showing 38 changed files with 2,486 additions and 1,413 deletions.
5 changes: 5 additions & 0 deletions support/node-mongodb-native/HISTORY
@@ -1,3 +1,8 @@
0.9.6-5 2011-07-06
* Rewritten BSON js parser now faster than the C parser on my core2duo laptop
* Added option full to indexInformation to get all index info Issue #265
* Passing in ObjectID for new Gridstore works correctly Issue #272

0.9.6-4 2011-07-01
* Added test and bug fix for insert/update/remove without callback supplied

Expand Down
94 changes: 94 additions & 0 deletions support/node-mongodb-native/benchmark/bson_benchmark.js
@@ -0,0 +1,94 @@
var BSON = require('../lib/mongodb').BSONNative.BSON,
ObjectID = require('../lib/mongodb').BSONNative.ObjectID,
debug = require('util').debug,
inspect = require('util').inspect;

var BSON = require('../lib/mongodb').BSONPure.BSON;
var ObjectID = require('../lib/mongodb').BSONPure.ObjectID;

// require('util').debug(require('util').inspect(BSON))

var COUNT = 10000;
// var COUNT = 1;
// var object = {
// string: "Strings are great",
// decimal: 3.14159265,
// bool: true,
// integer: 5,
//
// subObject: {
// moreText: "Bacon ipsum dolor sit amet cow pork belly rump ribeye pastrami andouille. Tail hamburger pork belly, drumstick flank salami t-bone sirloin pork chop ribeye ham chuck pork loin shankle. Ham fatback pork swine, sirloin shankle short loin andouille shank sausage meatloaf drumstick. Pig chicken cow bresaola, pork loin jerky meatball tenderloin brisket strip steak jowl spare ribs. Biltong sirloin pork belly boudin, bacon pastrami rump chicken. Jowl rump fatback, biltong bacon t-bone turkey. Turkey pork loin boudin, tenderloin jerky beef ribs pastrami spare ribs biltong pork chop beef.",
// longKeylongKeylongKeylongKeylongKeylongKey: "Pork belly boudin shoulder ribeye pork chop brisket biltong short ribs. Salami beef pork belly, t-bone sirloin meatloaf tail jowl spare ribs. Sirloin biltong bresaola cow turkey. Biltong fatback meatball, bresaola tail shankle turkey pancetta ham ribeye flank bacon jerky pork chop. Boudin sirloin shoulder, salami swine flank jerky t-bone pork chop pork beef tongue. Bresaola ribeye jerky andouille. Ribeye ground round sausage biltong beef ribs chuck, shank hamburger chicken short ribs spare ribs tenderloin meatloaf pork loin."
// },
//
// subArray: [1,2,3,4,5,6,7,8,9,10],
// anotherString: "another string"
// }

var x, start, end, i
var objectBSON, objectJSON

console.log(COUNT + "x (objectBSON = BSON.serialize(object))")
start = new Date

for (i=COUNT; --i>=0; ) {
var object = {
id: new ObjectID(),
string: "Strings are great",
decimal: 3.14159265,
bool: true,
integer: 5,

subObject: {
moreText: "Bacon ipsum dolor sit amet cow pork belly rump ribeye pastrami andouille. Tail hamburger pork belly, drumstick flank salami t-bone sirloin pork chop ribeye ham chuck pork loin shankle. Ham fatback pork swine, sirloin shankle short loin andouille shank sausage meatloaf drumstick. Pig chicken cow bresaola, pork loin jerky meatball tenderloin brisket strip steak jowl spare ribs. Biltong sirloin pork belly boudin, bacon pastrami rump chicken. Jowl rump fatback, biltong bacon t-bone turkey. Turkey pork loin boudin, tenderloin jerky beef ribs pastrami spare ribs biltong pork chop beef.",
longKeylongKeylongKeylongKeylongKeylongKey: "Pork belly boudin shoulder ribeye pork chop brisket biltong short ribs. Salami beef pork belly, t-bone sirloin meatloaf tail jowl spare ribs. Sirloin biltong bresaola cow turkey. Biltong fatback meatball, bresaola tail shankle turkey pancetta ham ribeye flank bacon jerky pork chop. Boudin sirloin shoulder, salami swine flank jerky t-bone pork chop pork beef tongue. Bresaola ribeye jerky andouille. Ribeye ground round sausage biltong beef ribs chuck, shank hamburger chicken short ribs spare ribs tenderloin meatloaf pork loin."
},

subArray: [1,2,3,4,5,6,7,8,9,10],
anotherString: "another string"
}

objectBSON = BSON.serialize(object, null, true)
}

end = new Date
console.log("bson size (bytes): ", objectBSON.length)
console.log("time = ", end - start, "ms -", COUNT * 1000 / (end - start), " ops/sec")


// console.log(COUNT + "x (objectJSON = JSON.stringify(object))")
// start = new Date
//
// for (i=COUNT; --i>=0; ) {
// objectJSON = JSON.stringify(object)
// }
//
// end = new Date
// console.log("json size (chars): ", objectJSON.length)
// console.log("time = ", end - start, "ms -", COUNT * 1000 / (end - start), " ops/sec")


console.log(COUNT + " BSON.deserialize(objectBSON)")
start = new Date

for (i=COUNT; --i>=0; ) {
x = BSON.deserialize(objectBSON)
// debug("=====================================================================")
// debug(inspect(x))
// x = BSON.deserialize2(objectBSON)
// debug(inspect(x))
}

end = new Date
console.log("time = ", end - start, "ms -", COUNT * 1000 / (end - start), " ops/sec")


// console.log(COUNT + " JSON.parse(objectJSON)")
// start = new Date
//
// for (i=COUNT; --i>=0; ) {
// x = JSON.parse(objectJSON)
// }
//
// end = new Date
// console.log("time = ", end - start, "ms -", COUNT * 1000 / (end - start), " ops/sec")
15 changes: 11 additions & 4 deletions support/node-mongodb-native/benchmark/streaming_benchmark.js
Expand Up @@ -6,14 +6,21 @@ var Db = require('mongodb').Db,
Cursor = require('mongodb').Cursor,
Collection = require('mongodb').Collection,
sys = require('util'),
debug = require('util').debug;
debug = require('util').debug,
inspect = require('util').inspect;

var BSON = require('bson');

// var parser = require('mongodb').BSONPure;
// var objectID = require('mongodb').ObjectID;
var parser = BSON;
var objectID = BSON.ObjectID;

var db = new Db('streaming_benchmark', new Server("127.0.0.1", 27017, {auto_reconnect: true, poolSize:4}), {})
// Set native deserializer
db.bson_deserializer = BSON;
db.bson_serializer = BSON;
db.pkFactory = BSON.ObjectID;
db.bson_deserializer = parser;
db.bson_serializer = parser;
db.pkFactory = objectID;

// Open the db
db.open(function(err, client) {
Expand Down
16 changes: 13 additions & 3 deletions support/node-mongodb-native/external-libs/bson/binary.cc
Expand Up @@ -184,13 +184,20 @@ Handle<Value> Binary::Write(const Arguments &args) {
HandleScope scope;

// Ensure we have the right parameters
if(args.Length() != 1 && (!args[0]->IsString() || Buffer::HasInstance(args[0]))) return VException("Function takes one argument of type String or Buffer");
if(args.Length() == 1 && (!args[0]->IsString() || Buffer::HasInstance(args[0]))) return VException("Function takes one argument of type String or Buffer");
if(args.Length() == 2 && (!args[0]->IsString() || Buffer::HasInstance(args[0])) && !args[1]->IsUint32()) return VException("Function takes one argument of type String or Buffer");

// Reference variables
char *data;
uint32_t length;
uint32_t offset = 0;
Local<Object> obj = args[0]->ToObject();

// Unpack the offset value
if(args.Length() == 2) {
offset = args[1]->ToUint32()->Value();
}

// If we have a buffer let's retrieve the data
if(Buffer::HasInstance(obj)) {
#if NODE_MAJOR_VERSION == 0 && NODE_MINOR_VERSION < 3
Expand Down Expand Up @@ -218,10 +225,13 @@ Handle<Value> Binary::Write(const Arguments &args) {
binary->number_of_bytes = (binary->number_of_bytes * 2) + length;
}

// If no offset specified use internal index
if(offset == 0) offset = binary->index;

// Write the element out
memcpy((binary->data + binary->index), data, length);
memcpy((binary->data + offset), data, length);
// Update the index pointer
binary->index = binary->index + length;
binary->index = offset + length;
// free the memory if we have allocated
if(!Buffer::HasInstance(args[0])) {
free(data);
Expand Down
29 changes: 20 additions & 9 deletions support/node-mongodb-native/external-libs/bson/bson.cc
Expand Up @@ -85,10 +85,13 @@ Handle<Value> BSON::New(const Arguments &args) {
}

Handle<Value> BSON::BSONSerialize(const Arguments &args) {
HandleScope scope;

// printf("= BSONSerialize ===================================== USING Native BSON Parser\n");
if(args.Length() == 1 && !args[0]->IsObject()) return VException("One or two arguments required - [object] or [object, boolean]");
if(args.Length() == 2 && !args[0]->IsObject() && !args[1]->IsBoolean()) return VException("One or two arguments required - [object] or [object, boolean]");
if(args.Length() > 2) return VException("One or two arguments required - [object] or [object, boolean]");
if(args.Length() == 1 && !args[0]->IsObject()) return VException("One, two or tree arguments required - [object] or [object, boolean] or [object, boolean, boolean]");
if(args.Length() == 2 && !args[0]->IsObject() && !args[1]->IsBoolean()) return VException("One, two or tree arguments required - [object] or [object, boolean] or [object, boolean, boolean]");
if(args.Length() == 3 && !args[0]->IsObject() && !args[1]->IsBoolean() && !args[2]->IsBoolean()) return VException("One, two or tree arguments required - [object] or [object, boolean] or [object, boolean, boolean]");
if(args.Length() > 3) return VException("One, two or tree arguments required - [object] or [object, boolean] or [object, boolean, boolean]");

// Calculate the total size of the document in binary form to ensure we only allocate memory once
uint32_t object_size = BSON::calculate_object_size(args[0]);
Expand All @@ -98,7 +101,7 @@ Handle<Value> BSON::BSONSerialize(const Arguments &args) {
try {
// Check if we have a boolean value
bool check_key = false;
if(args.Length() == 2 && args[1]->IsBoolean()) {
if(args.Length() == 3 && args[1]->IsBoolean()) {
check_key = args[1]->BooleanValue();
}

Expand All @@ -115,13 +118,21 @@ Handle<Value> BSON::BSONSerialize(const Arguments &args) {
// Return error
return error;
}

// Write the object size
BSON::write_int32((serialized_object), object_size);
// Encode the string (string - null termiating character)
Local<Value> bin_value = Encode(serialized_object, object_size, BINARY)->ToString();
// Return the serialized content
return bin_value;

// If we have 3 arguments
if(args.Length() == 3) {
// Local<Boolean> asBuffer = args[2]->ToBoolean();
Buffer *buffer = Buffer::New(serialized_object, object_size);
return scope.Close(buffer->handle_);
} else {
// Encode the string (string - null termiating character)
Local<Value> bin_value = Encode(serialized_object, object_size, BINARY)->ToString();
// Return the serialized content
return bin_value;
}
}

Handle<Value> BSON::ToLong(const Arguments &args) {
Expand Down

0 comments on commit 6b811a3

Please sign in to comment.