不要怂,就是干,撸起袖子干!

Commit 2a168da8 by Mick Hansen

Merge pull request #5154 from sushantdhiman/feat-488

Feat #488 : Benchmarks based on the pure JS Date.now()
2 parents 9d99adc2 9960398c
...@@ -30,7 +30,14 @@ Query.prototype.run = function(sql, parameters) { ...@@ -30,7 +30,14 @@ Query.prototype.run = function(sql, parameters) {
var self = this; var self = this;
this.sql = sql; this.sql = sql;
this.sequelize.log('Executing (' + (this.connection.uuid || 'default') + '): ' + this.sql, this.options); //do we need benchmark for this query execution
var benchmark = this.sequelize.options.benchmark || this.options.benchmark;
if (!benchmark) {
this.sequelize.log('Executing (' + (this.connection.uuid || 'default') + '): ' + this.sql, this.options);
} else {
var queryBegin = Date.now();
}
var promise = new Utils.Promise(function(resolve, reject) { var promise = new Utils.Promise(function(resolve, reject) {
// TRANSACTION SUPPORT // TRANSACTION SUPPORT
...@@ -63,6 +70,11 @@ Query.prototype.run = function(sql, parameters) { ...@@ -63,6 +70,11 @@ Query.prototype.run = function(sql, parameters) {
var results = []; var results = [];
var request = new self.connection.lib.Request(self.sql, function(err) { var request = new self.connection.lib.Request(self.sql, function(err) {
if (benchmark) {
self.sequelize.log('Executed (' + (self.connection.uuid || 'default') + '): ' + self.sql + ' in ' + (Date.now() - queryBegin) + 'ms', self.options);
}
if (err) { if (err) {
err.sql = sql; err.sql = sql;
reject(self.formatError(err)); reject(self.formatError(err));
......
...@@ -26,10 +26,22 @@ Query.prototype.run = function(sql, parameters) { ...@@ -26,10 +26,22 @@ Query.prototype.run = function(sql, parameters) {
var self = this; var self = this;
this.sql = sql; this.sql = sql;
this.sequelize.log('Executing (' + (this.connection.uuid || 'default') + '): ' + this.sql, this.options); //do we need benchmark for this query execution
var benchmark = this.sequelize.options.benchmark || this.options.benchmark;
if (!benchmark) {
this.sequelize.log('Executing (' + (this.connection.uuid || 'default') + '): ' + this.sql, this.options);
} else {
var queryBegin = Date.now();
}
var promise = new Utils.Promise(function(resolve, reject) { var promise = new Utils.Promise(function(resolve, reject) {
self.connection.query(self.sql, function(err, results) { self.connection.query(self.sql, function(err, results) {
if (benchmark) {
self.sequelize.log('Executed (' + (self.connection.uuid || 'default') + '): ' + self.sql + ' in ' + (Date.now() - queryBegin) + 'ms', self.options);
}
if (err) { if (err) {
err.sql = sql; err.sql = sql;
......
...@@ -62,7 +62,14 @@ Query.prototype.run = function(sql, parameters) { ...@@ -62,7 +62,14 @@ Query.prototype.run = function(sql, parameters) {
, query = ((parameters && parameters.length) ? this.client.query(this.sql, parameters) : this.client.query(this.sql)) , query = ((parameters && parameters.length) ? this.client.query(this.sql, parameters) : this.client.query(this.sql))
, rows = []; , rows = [];
this.sequelize.log('Executing (' + (this.client.uuid || 'default') + '): ' + this.sql, this.options); //do we need benchmark for this query execution
var benchmark = this.sequelize.options.benchmark || this.options.benchmark;
if (!benchmark) {
this.sequelize.log('Executing (' + (this.client.uuid || 'default') + '): ' + this.sql, this.options);
} else {
var queryBegin = Date.now();
}
var promise = new Promise(function(resolve, reject) { var promise = new Promise(function(resolve, reject) {
query.on('row', function(row) { query.on('row', function(row) {
...@@ -82,6 +89,11 @@ Query.prototype.run = function(sql, parameters) { ...@@ -82,6 +89,11 @@ Query.prototype.run = function(sql, parameters) {
}); });
query.on('end', function(result) { query.on('end', function(result) {
if (benchmark) {
self.sequelize.log('Executed (' + (self.client.uuid || 'default') + '): ' + self.sql + ' in ' + (Date.now() - queryBegin) + 'ms', self.options);
}
if (receivedError) { if (receivedError) {
return; return;
} }
......
...@@ -84,7 +84,14 @@ Query.prototype.run = function(sql, parameters) { ...@@ -84,7 +84,14 @@ Query.prototype.run = function(sql, parameters) {
this.sql = sql; this.sql = sql;
} }
this.sequelize.log('Executing (' + (this.database.uuid || 'default') + '): ' + this.sql, this.options); //do we need benchmark for this query execution
var benchmark = this.sequelize.options.benchmark || this.options.benchmark;
if (!benchmark) {
this.sequelize.log('Executing (' + (this.database.uuid || 'default') + '): ' + this.sql, this.options);
} else {
var queryBegin = Date.now();
}
promise = new Promise(function(resolve) { promise = new Promise(function(resolve) {
var columnTypes = {}; var columnTypes = {};
...@@ -95,6 +102,11 @@ Query.prototype.run = function(sql, parameters) { ...@@ -95,6 +102,11 @@ Query.prototype.run = function(sql, parameters) {
} else { } else {
resolve(new Promise(function(resolve, reject) { resolve(new Promise(function(resolve, reject) {
var afterExecute = function(err, results) { var afterExecute = function(err, results) {
if (benchmark) {
self.sequelize.log('Executed (' + (self.database.uuid || 'default') + '): ' + self.sql + ' in ' + (Date.now() - queryBegin) + 'ms', self.options);
}
if (err) { if (err) {
err.sql = self.sql; err.sql = self.sql;
reject(self.formatError(err)); reject(self.formatError(err));
......
...@@ -81,7 +81,8 @@ var url = require('url') ...@@ -81,7 +81,8 @@ var url = require('url')
* @param {Boolean} [options.quoteIdentifiers=true] Set to `false` to make table names and attributes case-insensitive on Postgres and skip double quoting of them. * @param {Boolean} [options.quoteIdentifiers=true] Set to `false` to make table names and attributes case-insensitive on Postgres and skip double quoting of them.
* @param {String} [options.transactionType='DEFERRED'] Set the default transaction type. See `Sequelize.Transaction.TYPES` for possible options. Sqlite only. * @param {String} [options.transactionType='DEFERRED'] Set the default transaction type. See `Sequelize.Transaction.TYPES` for possible options. Sqlite only.
* @param {String} [options.isolationLevel='REPEATABLE_READ'] Set the default transaction isolation level. See `Sequelize.Transaction.ISOLATION_LEVELS` for possible options. * @param {String} [options.isolationLevel='REPEATABLE_READ'] Set the default transaction isolation level. See `Sequelize.Transaction.ISOLATION_LEVELS` for possible options.
* @param {Boolean} [options.typeValidation=false] Run built in type validators on insert and update, e.g. validate that arguments passed to integer fields are integer-like * @param {Boolean} [options.typeValidation=false] Run built in type validators on insert and update, e.g. validate that arguments passed to integer fields are integer-like.
* @param {Boolean} [options.benchmark=false] Print query execution time in milliseconds when logging SQL.
*/ */
/** /**
...@@ -147,7 +148,8 @@ var Sequelize = function(database, username, password, options) { ...@@ -147,7 +148,8 @@ var Sequelize = function(database, username, password, options) {
transactionType: Transaction.TYPES.DEFERRED, transactionType: Transaction.TYPES.DEFERRED,
isolationLevel: Transaction.ISOLATION_LEVELS.REPEATABLE_READ, isolationLevel: Transaction.ISOLATION_LEVELS.REPEATABLE_READ,
databaseVersion: 0, databaseVersion: 0,
typeValidation: false typeValidation: false,
benchmark: false
}, options || {}); }, options || {});
if (this.options.dialect === 'postgresql') { if (this.options.dialect === 'postgresql') {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!