Skip to content

Commit 1b10e11

Browse files
committed
Update benchmarks to new version
1 parent 38e7336 commit 1b10e11

File tree

6 files changed

+85
-78
lines changed

6 files changed

+85
-78
lines changed

package.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ Package.onTest(function(api) {
3333
'autopublish',
3434
'insecure',
3535
'grigio:babel@0.1.1',
36-
'numtel:mysql'
36+
'numtel:mysql',
37+
'numtel:benchmark-packages@0.0.1',
38+
'mongo', // for benchmark
39+
'thinksoftware:mongo-direct@1.0.2' // for benchmark
3740
]);
3841
api.use('test-helpers'); // Did not work concatenated above
3942
api.addFiles([
@@ -47,11 +50,27 @@ Package.onTest(function(api) {
4750
], 'client');
4851

4952
api.addFiles([
53+
'test/helpers/queryEx.js',
5054
'test/helpers/querySequence.js',
5155
'test/index.es6'
5256
], 'server');
5357

5458
api.addFiles([
5559
'test/MysqlSubscription.js'
5660
]);
61+
62+
63+
// Benchmark databases
64+
api.addFiles([
65+
'test/benchmark/server.mongo.js',
66+
'test/benchmark/server.mysql.js'
67+
], 'server');
68+
69+
// Benchmarks
70+
api.addFiles([
71+
'test/benchmark/insertMany.js'
72+
], 'client');
73+
api.addFiles([
74+
'test/benchmark/maxVsOrderBy.js'
75+
]);
5776
});

test/benchmark/insertMany.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
// test/benchmark/insertMany.js
44

55
// Benchmark number of inserts published to client per second
6-
// Compare MySQL poll table, MySQL binlog, Mongo, and Mongo-Direct
7-
var genMysqlTest = function(prefix){
8-
var subscription = new MysqlSubscription(prefix + 'players');
6+
// Compare MySQL binlog, Mongo, and Mongo-Direct
7+
var genMysqlTest = function(){
8+
var subscription = new MysqlSubscription('benchmark_players');
99
return {
1010
run: function(options, done){
1111
var startCount = subscription.length;
@@ -16,9 +16,8 @@ var genMysqlTest = function(prefix){
1616
done();
1717
}
1818
});
19-
Meteor.call(prefix + 'insert', options.count, function(error){
19+
Meteor.call('benchmark_insert', options.count, function(error){
2020
if(error && error.error === 404){
21-
// Server connection (UDF) may not be available
2221
subscription.removeEventListener(/insertRows/);
2322
done();
2423
}
@@ -27,7 +26,7 @@ var genMysqlTest = function(prefix){
2726
},
2827
reset: function(options, done){
2928
if(subscription.length === 0) return done();
30-
Meteor.call(prefix + 'reset');
29+
Meteor.call('benchmark_reset');
3130
subscription.addEventListener('removed.resetTable', function(){
3231
if(subscription.length === 0){
3332
subscription.removeEventListener(/resetTable/);
@@ -78,10 +77,9 @@ Benchmark.addCase({
7877
count: 1000,
7978
sampleSize: 1,
8079
// Explictly specify methods for easy omission
81-
methods: ['mysql-poll', 'mysql-binlog', 'mongo-standard', 'mongo-direct']
80+
methods: ['mysql-binlog', 'mongo-standard', 'mongo-direct']
8281
},
83-
'mysql-poll': genMysqlTest('benchmark_poll_'),
84-
'mysql-binlog': genMysqlTest('benchmark_binlog_'),
82+
'mysql-binlog': genMysqlTest(),
8583
'mongo-standard': genMongoTest('insDocs'),
8684
'mongo-direct': genMongoTest('insDocsDirect')
8785
});

test/benchmark/maxVsOrderBy.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,10 @@ if(Meteor.isClient){
2727
});
2828

2929
}else if(Meteor.isServer){
30-
var conn;
30+
var conn = liveDb;
3131
var TABLE = 'benchmark_max_vs_orderby';
3232

3333
Meteor.startup(function(){
34-
conn = mysql.createConnection(Meteor.settings.mysql);
35-
conn.connect();
36-
37-
conn.queryEx('drop table if exists `' + TABLE + '`');
38-
conn.initUpdateTable(TABLE);
3934
});
4035

4136
Meteor.methods({

test/benchmark/server.mysql.js

Lines changed: 37 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,70 +3,46 @@
33
// test/benchmark/server.mysql.js
44

55
// Provide server for MySQL benchmarks
6-
var connections = [
7-
{
8-
tablePrefix: 'benchmark_poll_',
9-
init: function(conn){
10-
var upTable = this.tablePrefix + 'updates';
11-
conn.queryEx('drop table if exists `' + upTable + '`');
12-
conn.initUpdateTable(upTable);
13-
}
14-
}
15-
]
166

17-
Meteor.settings.binlog && connections.push({
18-
tablePrefix: 'benchmark_binlog_',
19-
init: function(conn){
20-
var settings = _.clone(Meteor.settings.mysql);
21-
settings.serverId++; // Unique serverId required
22-
conn.initBinlog(settings);
23-
}
24-
});
7+
var conn = liveDb;
8+
var playersTable = 'benchmark_players';
9+
Meteor.startup(function(){
10+
var settings = _.clone(Meteor.settings.mysql);
11+
settings.serverId *= 2; // Unique serverId required
2512

26-
connections.forEach(function(def){
27-
var conn;
28-
var playersTable = def.tablePrefix + 'players';
29-
Meteor.startup(function(){
30-
conn = mysql.createConnection(Meteor.settings.mysql);
31-
conn.connect();
13+
conn.queryEx('drop table if exists `' + playersTable + '`');
14+
conn.queryEx([
15+
"CREATE TABLE `" + playersTable + "` (",
16+
" `id` int(11) NOT NULL AUTO_INCREMENT,",
17+
" `name` varchar(45) DEFAULT NULL,",
18+
" `score` int(11) NOT NULL DEFAULT '0',",
19+
" PRIMARY KEY (`id`)",
20+
") ENGINE=InnoDB DEFAULT CHARSET=latin1;"
21+
].join('\n'));
22+
});
3223

33-
def.init.call(def, conn);
34-
35-
conn.queryEx('drop table if exists `' + playersTable + '`');
36-
conn.queryEx([
37-
"CREATE TABLE `" + playersTable + "` (",
38-
" `id` int(11) NOT NULL AUTO_INCREMENT,",
39-
" `name` varchar(45) DEFAULT NULL,",
40-
" `score` int(11) NOT NULL DEFAULT '0',",
41-
" PRIMARY KEY (`id`)",
42-
") ENGINE=InnoDB DEFAULT CHARSET=latin1;"
43-
].join('\n'));
24+
var connMethods = {};
25+
connMethods['benchmark_reset'] = function(){
26+
// Truncate doesn't call delete trigger!
27+
conn.queryEx('delete from `' + playersTable + '`');
28+
};
29+
connMethods['benchmark_insert'] = function(count){
30+
if(typeof count !== 'number' || count < 1 || Math.floor(count) !== count)
31+
throw new Error('invalid-count');
32+
conn.queryEx(function(esc, escId){
33+
var query = 'INSERT INTO `' + playersTable + '` (`name`, `score`) VALUES ';
34+
var rows = [];
35+
for(var i = 0; i < count; i++){
36+
rows.push('(' + esc(randomString(10)) + ', ' +
37+
esc(Math.floor(Math.random() * 20) * 5) + ')');
38+
}
39+
return query + rows.join(', ');
4440
});
41+
};
42+
Meteor.methods(connMethods);
4543

46-
var connMethods = {};
47-
connMethods[def.tablePrefix + 'reset'] = function(){
48-
// Truncate doesn't call delete trigger!
49-
conn.queryEx('delete from `' + playersTable + '`');
50-
};
51-
connMethods[def.tablePrefix + 'insert'] = function(count){
52-
if(typeof count !== 'number' || count < 1 || Math.floor(count) !== count)
53-
throw new Error('invalid-count');
54-
conn.queryEx(function(esc, escId){
55-
var query = 'INSERT INTO `' + playersTable + '` (`name`, `score`) VALUES ';
56-
var rows = [];
57-
for(var i = 0; i < count; i++){
58-
rows.push('(' + esc(randomString(10)) + ', ' +
59-
esc(Math.floor(Math.random() * 20) * 5) + ')');
60-
}
61-
return query + rows.join(', ');
62-
});
63-
};
64-
Meteor.methods(connMethods);
65-
66-
Meteor.publish(playersTable, function(){
67-
conn.select(this, {
68-
query: 'select * from `' + playersTable + '` order by score desc',
69-
triggers: [ { table: playersTable } ]
70-
});
71-
});
44+
Meteor.publish(playersTable, function(){
45+
return conn.select(
46+
'select * from `' + playersTable + '` order by score desc',
47+
[ { table: playersTable } ]);
7248
});

test/helpers/queryEx.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
var Future = Npm.require('fibers/future');
3+
4+
// Must be bound to node-mysql connection instance
5+
queryEx = function(query){
6+
var self = this;
7+
var fut = new Future();
8+
if(typeof query === 'function'){
9+
var escId = self.escapeId;
10+
var esc = self.escape.bind(self);
11+
query = query(esc, escId);
12+
}
13+
self.query(query, Meteor.bindEnvironment(function(error, rows, fields){
14+
if(error) return fut['throw'](error);
15+
fut['return'](rows);
16+
}));
17+
return fut.wait();
18+
}

test/index.es6

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ if(Meteor.settings.recreateDb){
99
delete Meteor.settings.mysql.database;
1010
}
1111

12-
var liveDb = new LiveMysql(Meteor.settings.mysql);
12+
liveDb = new LiveMysql(Meteor.settings.mysql);
13+
liveDb.queryEx = queryEx.bind(liveDb.db);
1314

1415
if(Meteor.settings.recreateDb){
1516
querySequence(liveDb.db, [

0 commit comments

Comments
 (0)