Skip to content

Commit

Permalink
Buffer writes to the mongodb socket internally.
Browse files Browse the repository at this point in the history
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
orlandov committed Jan 18, 2010
1 parent 2f79562 commit 8678787
Show file tree
Hide file tree
Showing 6 changed files with 275 additions and 99 deletions.
3 changes: 1 addition & 2 deletions lib/mongodb.js
Expand Up @@ -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]);
Expand Down Expand Up @@ -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;
});
}

Expand Down
5 changes: 3 additions & 2 deletions run-tests.sh
@@ -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
1 change: 1 addition & 0 deletions src/bson.cc
Expand Up @@ -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();
Expand Down

0 comments on commit 8678787

Please sign in to comment.