-
Notifications
You must be signed in to change notification settings - Fork 3
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
(perf) Refactor logger class to encapsulate bunyan instance; add requestLogger stress test #68
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should all read this. Its pretty awesome. @GLosch @ricardo-quinones
*/ | ||
export default function ClientLogger(config = {}) { | ||
export default function ClientLogger(config = {}, logger) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
requestsPerSecond: 20, | ||
}; | ||
|
||
function printResults(results) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😮
const newArgs = args.map((arg) => scrub(arg, this.config)); | ||
return original.apply(this, newArgs); | ||
} | ||
// Dynamically hoist + wrap bunyan log instance methods (logger.info, logger.warn, etc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be worth adding to readme that we're only hoisting these logger levels, if we want to access the api you have to logger._logger.addStream...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is awesome!
Summary
This is a fun one. We've been seeing some performance issues with this logger since the
scrubFields
function was added. Related to #47 #53 #54 #58This change updates the
Logger
class to encapsulate a bunyan logger instance rather than return one. This allows us to be much more explicit with the behavior we'd like the logger to maintain.It also changes the behavior of or data scrubber -- the entire
arguments
object is passed tohide-secrets
now (only ifscrubFields
is configured), which avoids some bottlenecks in this path.Benchmarks
The slowdown from scrub fields is significant, but also expected. I think this is still in the realm of "acceptable" performance since we're not logging anywhere near 30-40k times/sec in our apps.
The
child
method is noticeably slow. This is a bottleneck that we should look into optimizing (#67), but it should be ok for now.Stress tests:
A stress test suite was added in this PR that spins up a simple
express
server with therequestLogger
middleware and puts it under load. Here's what that looks like as of this change:These tests can be run via
npm run test:stress