This repository has been archived by the owner on Sep 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
async_test.js
65 lines (57 loc) · 2.01 KB
/
async_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#! /usr/bin/env node
var RedisStorage = require("./storages/redis.js");
var IORedisStorage = require("./storages/ioredis.js");
var NodeHandlerSocket = require("./storages/node-handlersocket.js");
var ManualHandlerSocket = require("./storages/hs-manual.js");
var Riak = require("./storages/riak.js");
var async = require("async");
function format_ms(hrtime) {
return (hrtime[0] * 1e9 + hrtime[1]) / 1e6;
}
function test_storage(options) {
for (var i = 0; i < options.iteration_count; i++) {
options.storage.read_one_random_record(function() {
options.index++;
if (options.index >= options.iteration_count) {
var stop = process.hrtime(options.start);
console.log("Test finished: %d ops, %d ms, %d ops/sec",
options.iteration_count,
format_ms(stop),
options.iteration_count * 1000 / format_ms(stop));
options.storage.teardown();
console.log();
options.done();
}
});
}
}
function simple_test(name, storage_creator, num_count, record_count, next) {
var start = process.hrtime();
console.log("Test '" + name + "' started");
storage_creator(record_count, function (err, storage) {
console.log("Storage created in %d ms", format_ms(process.hrtime(start)));
if (err)
{
console.log("Error on start: " + err);
next();
return;
}
test_storage({ storage: storage, iteration_count: num_count, done: next, start: process.hrtime(), index: 0 });
});
};
var num = 5e5;
var record_num = 1e6;
var runner = async.seq(
function (callback) { simple_test("redis", RedisStorage, num, record_num, callback); },
function (callback) { simple_test("ioredis", IORedisStorage, num, record_num, callback); },
function (callback) { simple_test("node-handlersocket", NodeHandlerSocket, num, record_num, callback); },
function (callback) { simple_test("manual-hs", ManualHandlerSocket, num, record_num, callback); }
// function (callback) { simple_test("riak", Riak, num, record_num, callback); }
);
runner(function(err) {
if (err) {
console.error(err);
}
console.log("Done");
process.exit();
})