Skip to content

Instantly share code, notes, and snippets.

@neumino
Last active January 2, 2016 13:09
Show Gist options
  • Save neumino/8307741 to your computer and use it in GitHub Desktop.
Save neumino/8307741 to your computer and use it in GitHub Desktop.
var rdbConn = {};
var r = require('rethinkdb');
if (r.protobuf_implementation !== 'cpp') console.log("WARNING: Wrong protobuf backend");
var async = require('async');
// Parameters
var numInserts = 5000;
// Global var
var numFields;
var numConn;
function genDoc() {
var doc = {}
doc.id = guid();
for(var i=0; i<numFields; i++) {
doc["field"+i] = guid();
}
return doc;
}
function s4() {
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
};
function guid() {
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
function dropCreateTable(args, cb) {
var conn = args.conn;
r.tableDrop("benchmark").run(conn, function(err, result) {
if (err) {
if (err.msg !== "Table `benchmark` does not exist.") throw err;
}
r.tableCreate("benchmark").run(conn, function(err, result) {
if (err) throw err;
cb();
})
})
}
function connectRdb(item, cb) {
r.connect(rdbConn, function(err, conn) {
if (err) throw err;
cb(err, conn);
})
}
function rethinkdbTest(item, lastCb) {
numFields = item.numFields;
numConn = item.numConn;
var connAr = []
for(var k=0; k<numConn; k++) {
connAr.push(k);
}
async.map(connAr, connectRdb, function(err, connections) {
if (err) throw err;
dropCreateTable({db: "rdb", conn: connections[0]}, function() {
var done = 0;
var docs = []
for(var i=0; i<numInserts;i++) {
docs.push(genDoc());
}
for(var i=0; i<numInserts;i++) {
r.db('test').table('benchmark').insert(docs[i]).run( connections[i%numConn], function(err, result) {
if (err) throw err;
done++;
if (done === numInserts) {
for(var k=0; k<numConn; k++) {
connections[k].close();
}
rethinkdbTest({
numFields: 100,
numConn: 100
}, function() {
});
}
})
}
})
})
}
// Single test
rethinkdbTest({
numFields: 100,
numConn: 100
}, function() {
});
@neumino
Copy link
Author

neumino commented Jan 7, 2014

michel@T520:~/projects/test$ gdb --args node test.js
GNU gdb (GDB) 7.6.1-ubuntu
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/local/bin/node...done.
(gdb) run
Starting program: /usr/local/bin/node test.js
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff7ff7700 (LWP 3977)]
[New Thread 0x7ffff64b1700 (LWP 3978)]
[New Thread 0x7ffff5cb0700 (LWP 3979)]
[New Thread 0x7ffff54af700 (LWP 3980)]
[New Thread 0x7ffff4cae700 (LWP 3981)]
Program received signal SIGSEGV, Segmentation fault.
0x00001e319980d699 in ?? ()
(gdb) bt
#0  0x00001e319980d699 in ?? ()
#1  0x00002416fb006c91 in ?? ()
#2  0x0000371977e248b9 in ?? ()
#3  0x00001e319980d601 in ?? ()
#4  0x0000000600000000 in ?? ()
#5  0x0000000000000000 in ?? ()
(gdb) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment