Skip to content

Commit 48e915f

Browse files
author
Karl Kirch
committed
Initial commit of benchmark
1 parent 9e04a92 commit 48e915f

File tree

66 files changed

+13222
-24
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+13222
-24
lines changed

.gitignore

-24
Original file line numberDiff line numberDiff line change
@@ -1,25 +1 @@
1-
# Logs
2-
logs
3-
*.log
4-
5-
# Runtime data
6-
pids
7-
*.pid
8-
*.seed
9-
10-
# Directory for instrumented libs generated by jscoverage/JSCover
11-
lib-cov
12-
13-
# Coverage directory used by tools like istanbul
14-
coverage
15-
16-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17-
.grunt
18-
19-
# Compiled binary addons (http://nodejs.org/api/addons.html)
20-
build/Release
21-
22-
# Dependency directory
23-
# Deployed apps should consider commenting this line out:
24-
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
251
node_modules

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,12 @@ js-flow-control-bench
22
=====================
33

44
Various benchmarks of js flow control libraries
5+
6+
Shamelessly borrowed from https://github.com/petkaantonov/bluebird
7+
8+
##Run benchmarks
9+
There are 3 benchmarks:
10+
11+
* `./bench parallel` - contrived simple loop benchmark
12+
* `./bench doxbee` - Run simulated mixed task flow benchmark
13+
* `./bench doxbee-errors` - Run simulated mixed task flow benchmark with 10% errors

bench

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
benchmark=$1
3+
nodepath=${2:-node}
4+
cwd=${PWD}
5+
6+
trap 'cd "$cwd"' EXIT
7+
8+
if [ "$benchmark" = "doxbee" ]; then
9+
cd "$cwd"
10+
npm install
11+
echo "Doxbee sequential"
12+
$nodepath performance.js --n 10000 --t 1 ./doxbee-sequential/*.js --harmony
13+
exit 0
14+
elif [ "$benchmark" = "doxbee-errors" ]; then
15+
cd "$cwd"
16+
npm install
17+
echo "Doxbee sequential with 10% errors"
18+
$nodepath performance.js --n 10000 --t 1 --e 0.1 ./doxbee-sequential-errors/*.js --harmony
19+
exit 0
20+
elif [ "$benchmark" = "parallel" ]; then
21+
cd "$cwd"
22+
npm install
23+
echo "Madeup parallel"
24+
$nodepath performance.js --n 10000 --t 1 --p 25 ./madeup-parallel/*.js --harmony
25+
exit 0
26+
else
27+
echo "Invalid benchmark name $benchmark. Usage `./bench {parallel, doxbee, doxbee-errors}`"
28+
exit -1
29+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
require('../lib/fakes');
2+
3+
module.exports = function upload(stream, idOrPath, tag, done) {
4+
var blob = blobManager.create(account);
5+
var tx = db.begin();
6+
function backoff(err) {
7+
tx.rollback();
8+
return done(err);
9+
}
10+
var intentionalErrorShouldBeTriggered = function(){
11+
return LIKELIHOOD_OF_REJECTION && Math.random() <= LIKELIHOOD_OF_REJECTION;
12+
}
13+
14+
blob.put(stream, function (err, blobId) {
15+
if (err) return done(err);
16+
self.byUuidOrPath(idOrPath).get(function (err, file) {
17+
if (err) return done(err);
18+
var previousId = file ? file.version : null;
19+
var version = {
20+
userAccountId: userAccount.id,
21+
date: new Date(),
22+
blobId: blobId,
23+
creatorId: userAccount.id,
24+
previousId: previousId,
25+
};
26+
version.id = Version.createHash(version);
27+
Version.insert(version).execWithin(tx, function (err) {
28+
if (err) return backoff(err);
29+
if(intentionalErrorShouldBeTriggered()) return done(new Error("intentional failure"));
30+
if (!file) {
31+
var splitPath = idOrPath.split('/');
32+
var fileName = splitPath[splitPath.length - 1];
33+
var newId = uuid.v1();
34+
self.createQuery(idOrPath, {
35+
id: newId,
36+
userAccountId: userAccount.id,
37+
name: fileName,
38+
version: version.id
39+
}, function (err, q) {
40+
if (err) return backoff(err);
41+
if(intentionalErrorShouldBeTriggered()) return done(new Error("intentional failure"));
42+
q.execWithin(tx, function (err) {
43+
afterFileExists(err, newId);
44+
});
45+
46+
})
47+
}
48+
else return afterFileExists(null, file.id);
49+
});
50+
function afterFileExists(err, fileId) {
51+
if (err) return backoff(err);
52+
if(intentionalErrorShouldBeTriggered()) return done(new Error("intentional failure"));
53+
FileVersion.insert({fileId: fileId,versionId: version.id})
54+
.execWithin(tx, function (err) {
55+
if (err) return backoff(err);
56+
if(intentionalErrorShouldBeTriggered()) return done(new Error("intentional failure"));
57+
File.whereUpdate({id: fileId}, {
58+
version: version.id
59+
}).execWithin(tx, function (err) {
60+
if (err) return backoff(err);
61+
if(intentionalErrorShouldBeTriggered()) return done(new Error("intentional failure"));
62+
tx.commit(done);
63+
});
64+
})
65+
}
66+
});
67+
});
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
require('../lib/fakes');
2+
var async = require('async');
3+
4+
module.exports = function upload(stream, idOrPath, tag, done) {
5+
var blob = blobManager.create(account);
6+
var tx = db.begin();
7+
var blobId, file, version, fileId;
8+
async.waterfall([
9+
function writeBlob(callback) {
10+
blob.put(stream, callback);
11+
},
12+
function afterBlobWritten(callback) {
13+
blobId = undefined // iBlobId;
14+
self.byUuidOrPath(idOrPath).get(callback);
15+
},
16+
function afterFileFetched(callback) {
17+
file = undefined; //iFile;
18+
var previousId = file ? file.version : null;
19+
version = {
20+
userAccountId: userAccount.id,
21+
date: new Date(),
22+
blobId: blobId,
23+
creatorId: userAccount.id,
24+
previousId: previousId,
25+
mergedId: null,
26+
mergeType: 'mine',
27+
comment: '',
28+
tag: tag
29+
};
30+
version.id = Version.createHash(version);
31+
Version.insert(version).execWithin(tx, callback);
32+
},
33+
function afterVersionInserted(callback) {
34+
if (!file) {
35+
var splitPath = idOrPath.split('/');
36+
var fileName = splitPath[splitPath.length - 1];
37+
var newId = uuid.v1();
38+
self.createQuery(idOrPath, {
39+
id: newId,
40+
userAccountId: userAccount.id,
41+
type: 'file',
42+
name: fileName,
43+
version: version.id
44+
}, function (err, q) {
45+
if (err) return backoff(err);
46+
q.execWithin(tx, function (err) {
47+
callback(err, newId);
48+
});
49+
50+
})
51+
}
52+
else return callback(null, file.id);
53+
},
54+
function afterFileExists(iFileId, callback) {
55+
fileId = iFileId;
56+
FileVersion.insert({fileId: fileId, versionId: version.id})
57+
.execWithin(tx, callback);
58+
},
59+
function afterFileVersionInserted(callback) {
60+
File.whereUpdate({id: fileId}, { version: version.id })
61+
.execWithin(tx, callback);
62+
},
63+
function afterFileUpdated(callback) {
64+
tx.commit(callback);
65+
}
66+
],
67+
function (err) {
68+
if (err) tx.rollback();
69+
done(err);
70+
});
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
require('../lib/fakes');
2+
var fastsync = require('../../fastsync');
3+
4+
module.exports = function upload(stream, idOrPath, tag, done) {
5+
var blob = blobManager.create(account);
6+
var tx = db.begin();
7+
var blobId, file, version, fileId;
8+
fastsync.waterfall([
9+
function writeBlob(callback) {
10+
blob.put(stream, callback);
11+
},
12+
function afterBlobWritten(callback) {
13+
blobId = undefined // iBlobId;
14+
self.byUuidOrPath(idOrPath).get(callback);
15+
},
16+
function afterFileFetched(callback) {
17+
file = undefined; //iFile;
18+
var previousId = file ? file.version : null;
19+
version = {
20+
userAccountId: userAccount.id,
21+
date: new Date(),
22+
blobId: blobId,
23+
creatorId: userAccount.id,
24+
previousId: previousId,
25+
mergedId: null,
26+
mergeType: 'mine',
27+
comment: '',
28+
tag: tag
29+
};
30+
version.id = Version.createHash(version);
31+
Version.insert(version).execWithin(tx, callback);
32+
},
33+
function afterVersionInserted(callback) {
34+
if (!file) {
35+
var splitPath = idOrPath.split('/');
36+
var fileName = splitPath[splitPath.length - 1];
37+
var newId = uuid.v1();
38+
self.createQuery(idOrPath, {
39+
id: newId,
40+
userAccountId: userAccount.id,
41+
type: 'file',
42+
name: fileName,
43+
version: version.id
44+
}, function (err, q) {
45+
if (err) return backoff(err);
46+
q.execWithin(tx, function (err) {
47+
callback(err, newId);
48+
});
49+
50+
})
51+
}
52+
else return callback(null, file.id);
53+
},
54+
function afterFileExists(iFileId, callback) {
55+
fileId = iFileId;
56+
FileVersion.insert({fileId: fileId, versionId: version.id})
57+
.execWithin(tx, callback);
58+
},
59+
function afterFileVersionInserted(callback) {
60+
File.whereUpdate({id: fileId}, { version: version.id })
61+
.execWithin(tx, callback);
62+
},
63+
function afterFileUpdated(callback) {
64+
tx.commit(callback);
65+
}
66+
],
67+
function (err) {
68+
if (err) tx.rollback();
69+
done(err);
70+
});
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
global.useBluebird = true;
2+
global.useQ = false;
3+
var bluebird = require('bluebird');
4+
require('../lib/fakesP');
5+
6+
module.exports = bluebird.coroutine(function* upload(stream, idOrPath, tag, done) {
7+
try {
8+
var blob = blobManager.create(account);
9+
var tx = db.begin();
10+
var blobId = yield blob.put(stream);
11+
var file = yield self.byUuidOrPath(idOrPath).get();
12+
13+
var previousId = file ? file.version : null;
14+
version = {
15+
userAccountId: userAccount.id,
16+
date: new Date(),
17+
blobId: blobId,
18+
creatorId: userAccount.id,
19+
previousId: previousId,
20+
};
21+
version.id = Version.createHash(version);
22+
yield Version.insert(version).execWithin(tx);
23+
triggerIntentionalError();
24+
if (!file) {
25+
var splitPath = idOrPath.split('/');
26+
var fileName = splitPath[splitPath.length - 1];
27+
file = {
28+
id: uuid.v1(),
29+
userAccountId: userAccount.id,
30+
name: fileName,
31+
version: version.id
32+
}
33+
var query = yield self.createQuery(idOrPath, file);
34+
yield query.execWithin(tx);
35+
triggerIntentionalError();
36+
}
37+
yield FileVersion.insert({fileId: file.id, versionId: version.id})
38+
.execWithin(tx);
39+
triggerIntentionalError();
40+
yield File.whereUpdate({id: file.id}, {version: version.id})
41+
.execWithin(tx);
42+
triggerIntentionalError();
43+
tx.commit();
44+
done();
45+
} catch (err) {
46+
tx.rollback();
47+
done(err);
48+
}
49+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
global.useBluebird = true;
2+
global.useQ = false;
3+
var bluebird = require('bluebird');
4+
require('../lib/fakesP');
5+
6+
module.exports = function upload(stream, idOrPath, tag, done) {
7+
var blob = blobManager.create(account);
8+
var tx = db.begin();
9+
var blobIdP = blob.put(stream);
10+
var fileP = self.byUuidOrPath(idOrPath).get();
11+
var version, fileId, file;
12+
13+
bluebird.all([blobIdP, fileP]).spread(function(blobId, fileV) {
14+
file = fileV;
15+
var previousId = file ? file.version : null;
16+
version = {
17+
userAccountId: userAccount.id,
18+
date: new Date(),
19+
blobId: blobId,
20+
creatorId: userAccount.id,
21+
previousId: previousId,
22+
};
23+
version.id = Version.createHash(version);
24+
return Version.insert(version).execWithin(tx);
25+
}).then(function() {
26+
triggerIntentionalError();
27+
if (!file) {
28+
var splitPath = idOrPath.split('/');
29+
var fileName = splitPath[splitPath.length - 1];
30+
var newId = uuid.v1();
31+
return self.createQuery(idOrPath, {
32+
id: newId,
33+
userAccountId: userAccount.id,
34+
name: fileName,
35+
version: version.id
36+
}).then(function(q) {
37+
return q.execWithin(tx);
38+
}).then(function() {
39+
return newId;
40+
});
41+
} else {
42+
return file.id;
43+
}
44+
}).then(function(fileIdV) {
45+
triggerIntentionalError();
46+
fileId = fileIdV;
47+
return FileVersion.insert({
48+
fileId: fileId,
49+
versionId: version.id
50+
}).execWithin(tx);
51+
}).then(function() {
52+
triggerIntentionalError();
53+
return File.whereUpdate({id: fileId}, {version: version.id})
54+
.execWithin(tx);
55+
}).then(function() {
56+
triggerIntentionalError();
57+
tx.commit();
58+
return done();
59+
}).then(null, function(err) {
60+
tx.rollback();
61+
return done(err);
62+
});
63+
}

0 commit comments

Comments
 (0)