Permalink
Browse files

Buffer writes to the mongodb socket internally.

Previously, writes to the mongodb socket happened immediately. However, this
will inevitable overflow the send buffer. So now, we store commands in a buffer
and write them out on the next write event window. Inserting 1000+ things still
is an edge case where performance suffers, since you'll be memcpy'ing and
growing the buffer each time. But at least now it will not segfault.
  • Loading branch information...
1 parent 2f79562 commit 86787870c64bd9ecab785adcfc528a3bc565da9c @orlandov committed Jan 18, 2010
Showing with 275 additions and 99 deletions.
  1. +1 −2 lib/mongodb.js
  2. +3 −2 run-tests.sh
  3. +1 −0 src/bson.cc
  4. +220 −94 src/mongo.cc
  5. +36 −0 tests/test_many_insert.js
  6. +14 −1 tests/test_mongo.js
View
@@ -33,7 +33,6 @@ Collection.prototype.find_one = function(query, fields, ns) {
var user_promise = new process.Promise;
this.mongo.addQuery(promise, ns || this.ns, query, fields, 1);
-
promise.addCallback(function (results) {
// XXX what if result.Length < 1
user_promise.emitSuccess(results[0]);
@@ -77,8 +76,8 @@ function MongoDB() {
this.connection.addListener("result", function(result) {
var promise = self.currentQuery[0];
- self.currentQuery = null;
promise.emitSuccess(result);
+ self.currentQuery = null;
});
}
View
@@ -1,4 +1,5 @@
#!/bin/sh
-node tests/test_bson.js
-node tests/test_mongo.js
+for f in `ls tests/test_*.js`; do
+ node $f
+done
View
@@ -40,6 +40,7 @@ Handle<Value> ObjectID::New(const Arguments &args) {
String::Utf8Value hex(args[0]->ToString());
+ // XXX where should this be deleted?
ObjectID *o = new ObjectID((const char *) *hex);
o->Wrap(args.This());
return args.This();
Oops, something went wrong.

0 comments on commit 8678787

Please sign in to comment.