Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added steed to benchmarks #887

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
require('../lib/fakes');
var steed = require('steed');

module.exports = function upload(stream, idOrPath, tag, done) {
var blob = blobManager.create(account);
var tx = db.begin();
var blobId, file, version, fileId;
async.waterfall([
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this is still trying to use async instead of steed?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol ^_^

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed :D.

function writeBlob(callback) {
blob.put(stream, callback);
},
function afterBlobWritten(callback) {
blobId = undefined // iBlobId;
self.byUuidOrPath(idOrPath).get(callback);
},
function afterFileFetched(callback) {
file = undefined; //iFile;
var previousId = file ? file.version : null;
version = {
userAccountId: userAccount.id,
date: new Date(),
blobId: blobId,
creatorId: userAccount.id,
previousId: previousId,
mergedId: null,
mergeType: 'mine',
comment: '',
tag: tag
};
version.id = Version.createHash(version);
Version.insert(version).execWithin(tx, callback);
},
function afterVersionInserted(callback) {
if (!file) {
var splitPath = idOrPath.split('/');
var fileName = splitPath[splitPath.length - 1];
var newId = uuid.v1();
self.createQuery(idOrPath, {
id: newId,
userAccountId: userAccount.id,
type: 'file',
name: fileName,
version: version.id
}, function (err, q) {
if (err) return backoff(err);
q.execWithin(tx, function (err) {
callback(err, newId);
});

})
}
else return callback(null, file.id);
},
function afterFileExists(iFileId, callback) {
fileId = iFileId;
FileVersion.insert({fileId: fileId, versionId: version.id})
.execWithin(tx, callback);
},
function afterFileVersionInserted(callback) {
File.whereUpdate({id: fileId}, { version: version.id })
.execWithin(tx, callback);
},
function afterFileUpdated(callback) {
tx.commit(callback);
}
],
function (err) {
if (err) tx.rollback();
done(err);
});
}
71 changes: 71 additions & 0 deletions benchmark/doxbee-sequential/callbacks-mcollina-steed-waterfall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
require('../lib/fakes');
var steed = require('steed');

module.exports = function upload(stream, idOrPath, tag, done) {
var blob = blobManager.create(account);
var tx = db.begin();
var blobId, file, version, fileId;
steed.waterfall([
function writeBlob(callback) {
blob.put(stream, callback);
},
function afterBlobWritten(callback) {
blobId = undefined // iBlobId;
self.byUuidOrPath(idOrPath).get(callback);
},
function afterFileFetched(callback) {
file = undefined; //iFile;
var previousId = file ? file.version : null;
version = {
userAccountId: userAccount.id,
date: new Date(),
blobId: blobId,
creatorId: userAccount.id,
previousId: previousId,
mergedId: null,
mergeType: 'mine',
comment: '',
tag: tag
};
version.id = Version.createHash(version);
Version.insert(version).execWithin(tx, callback);
},
function afterVersionInserted(callback) {
if (!file) {
var splitPath = idOrPath.split('/');
var fileName = splitPath[splitPath.length - 1];
var newId = uuid.v1();
self.createQuery(idOrPath, {
id: newId,
userAccountId: userAccount.id,
type: 'file',
name: fileName,
version: version.id
}, function (err, q) {
if (err) return backoff(err);
q.execWithin(tx, function (err) {
callback(err, newId);
});

})
}
else return callback(null, file.id);
},
function afterFileExists(iFileId, callback) {
fileId = iFileId;
FileVersion.insert({fileId: fileId, versionId: version.id})
.execWithin(tx, callback);
},
function afterFileVersionInserted(callback) {
File.whereUpdate({id: fileId}, { version: version.id })
.execWithin(tx, callback);
},
function afterFileUpdated(callback) {
tx.commit(callback);
}
],
function (err) {
if (err) tx.rollback();
done(err);
});
}
33 changes: 33 additions & 0 deletions benchmark/madeup-parallel/callbacks-mcollina-fastparallel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require('../lib/fakes');
var parallel = require('fastparallel')();

function work (op, cb) {
op.execWithin(this.tx, cb);
}

function Status (tx, done) {
this.tx = tx;
this.done = done;
}

function finish (err) {
if (err) {
this.tx.rollback();
this.done(err);
}
else {
this.tx.commit();
this.done();
}
}

module.exports = function upload(stream, idOrPath, tag, done) {
var queries = new Array(global.parallelQueries);
var tx = db.begin();

for( var i = 0, len = queries.length; i < len; ++i ) {
queries[i] = FileVersion.insert({index: i})
}

parallel(new Status(tx, done), work, queries, finish)
}
33 changes: 33 additions & 0 deletions benchmark/madeup-parallel/callbacks-mcollina-steed-map.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require('../lib/fakes');
var steed = require('steed');

function work (op, cb) {
op.execWithin(this.tx, cb);
}

function Status (tx, done) {
this.tx = tx;
this.done = done;
}

function finish (err) {
if (err) {
this.tx.rollback();
this.done(err);
}
else {
this.tx.commit();
this.done();
}
}

module.exports = function upload(stream, idOrPath, tag, done) {
var queries = new Array(global.parallelQueries);
var tx = db.begin();

for( var i = 0, len = queries.length; i < len; ++i ) {
queries[i] = FileVersion.insert({index: i})
}

steed.map(new Status(tx, done), queries, work, finish)
}
29 changes: 29 additions & 0 deletions benchmark/madeup-parallel/callbacks-mcollina-steed-parallel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require('../lib/fakes');
var steed = require('steed');

function fileInsertFor(i, tx) {
return function(callback) {
FileVersion.insert({index: i})
.execWithin(tx, callback);
};
}

module.exports = function upload(stream, idOrPath, tag, done) {
var queries = new Array(global.parallelQueries);
var tx = db.begin();

for( var i = 0, len = queries.length; i < len; ++i ) {
queries[i] = fileInsertFor(i, tx);
}

steed.parallel(queries, function(err, callback) {
if (err) {
tx.rollback();
done(err);
}
else {
tx.commit();
done();
}
});
}
1 change: 1 addition & 0 deletions benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"promise": "^7.0.4",
"q": "^1.4.1",
"rsvp": "^3.1.0",
"steed": "^1.1.0",
"streamline": "^1.0.7",
"text-table": "^0.2.0",
"vow": "^0.4.11",
Expand Down