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

Feature #488 : Added benchmarking support in query logs #5116

Merged
merged 1 commit into from
Jan 6, 2016
Merged

Feature #488 : Added benchmarking support in query logs #5116

merged 1 commit into from
Jan 6, 2016

Conversation

sushantdhiman
Copy link
Contributor

Closes #488

Added an new option benchmark and node-microtime library to log time in microseconds it took to execute a SQL statement.

@mickhansen
Copy link
Contributor

Only problem i see here is you would no longer get the SQL on failure with benchmark turned on. Not sure that's a major issue since err.sql is still a thing.


if(self.sequelize.options.benchmark){
var queryTime = microtime.now() - queryBegin;
self.sequelize.log('Executed (' + (self.connection.uuid || 'default') + '): ' + self.sql + ' in ' + queryTime + ' μs', self.options);
Copy link
Contributor

Choose a reason for hiding this comment

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

No space between time and us is common i believe.
No reason to save a queryTime variable is there?

Please add a space after if before (

@sushantdhiman
Copy link
Contributor Author

Yes I thought that too @mickhansen . When error is thrown we actually don't need the benchmarks? Also error will have the generated SQL query as well.

@@ -62,7 +63,11 @@ Query.prototype.run = function(sql, parameters) {
, query = ((parameters && parameters.length) ? this.client.query(this.sql, parameters) : this.client.query(this.sql))
, rows = [];

this.sequelize.log('Executing (' + (this.client.uuid || 'default') + '): ' + this.sql, this.options);
if (!this.sequelize.options.benchmark) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably also allow per call benchmarking ala:

Model.findAll({
  logging: console.log,
  benchmark. true
})

@sushantdhiman
Copy link
Contributor Author

@mickhansen Done, for all model methods

@sushantdhiman
Copy link
Contributor Author

CI Clear, Let me know if PR need other changes

@@ -39,6 +39,7 @@
"inflection": "^1.6.0",
"lodash": "^3.9.3",
"moment": "^2.11.0",
"microtime": "^2.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

microtime requires gyp and uses gettimeofday. It won't work on windows, question is whether or not it will install.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They have a CI build for windows. I think it will install and work for 0.10+

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah okay, great.

@sushantdhiman
Copy link
Contributor Author

All done @mickhansen

@sushantdhiman
Copy link
Contributor Author

@mickhansen Any changes in this one.

@mickhansen
Copy link
Contributor

Looks good, do you mind squashing the commits to a single descriptive one though?

@sushantdhiman
Copy link
Contributor Author

@mickhansen Can you please restart the CI or accept it :)

@mickhansen
Copy link
Contributor

You've tested this locally i assume?
Not sure if we want to add unit tests for this, probably OK not to, just want to make sure you've run a few different calls with benchmark enabled.

@sushantdhiman
Copy link
Contributor Author

Yes I have ran full tests with benchmark and single findAll as well, it works

mickhansen added a commit that referenced this pull request Jan 6, 2016
Feature #488 : Added benchmarking support in query logs
@mickhansen mickhansen merged commit dafdb7e into sequelize:master Jan 6, 2016
@sushantdhiman
Copy link
Contributor Author

Thanks

@mickhansen
Copy link
Contributor

https://travis-ci.org/mickhansen/graphql-sequelize/builds/100633104 microtime has issues on Node v4.0 it looks like, will have to revert this PR.

@sushantdhiman
Copy link
Contributor Author

Ok, I will replace with getTime so we can still use new feature

@ThomasHambach
Copy link

Are there any plans incorporating this in the near future? If not, what can I do to help?

@janmeier
Copy link
Member

@sushantdhiman
Copy link
Contributor Author

@ThomasHambach #5154

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants