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

Refactor PassportLoggingHandler to reduce unnecessary heap allocation #1095

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jfernandez
Copy link
Contributor

@jfernandez jfernandez commented Aug 17, 2021

The "slow response/request processing" INFO level adds too much noise when a slow GC pause slows down our filter processing.

This PR:

  • Downgrades slow response/request processing logging to DEBUG
  • Refactors PassportLoggingHandler to leverage isDebugEnabled and remove unnecessary heap allocation and timing calculation.

// Some logging of session states if certain criteria match:
if (LOG.isInfoEnabled()) {
if (passport.wasProxyAttempt()) {
StartAndEnd inReqToOutResp = passport.findFirstStartAndLastEndStates(PassportState.IN_REQ_HEADERS_RECEIVED, PassportState.OUT_REQ_LAST_CONTENT_SENT);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is a if (LOG.isDebugEnabled()) { conditional at the top of this block.

} else {
if (ctx != null && !isHealthcheckRequest(request)) {
// Why did we fail to attempt to proxy this request?
if (LOG.isDebugEnabled()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is redundant, and no longer necessary with the log4j implementation of slf4j.
It'd actually make sense to clean up the conditionals here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The input to LOG.debug below is evaluated before the logger method itself does the log level check. The advice I received is to wrap the call with this conditional if we're constructing a log message dynamically.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, I left a separate comment around string concat but there have been optimizations there.
It's difficult to discuss this without an allocation profile imo.

if (passport.wasProxyAttempt()) {
StartAndEnd inReqToOutResp = passport.findFirstStartAndLastEndStates(PassportState.IN_REQ_HEADERS_RECEIVED, PassportState.OUT_REQ_LAST_CONTENT_SENT);
if (passport.calculateTimeBetween(inReqToOutResp) > WARN_REQ_PROCESSING_TIME_NS.get()) {
LOG.debug("Request processing took longer than threshold! toplevelid = " + topLevelRequestId + ", "
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we actually want to improve allocation, avoiding string concatenation is a much better low hanging fruit here imo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We want to primarily reduce logging noise, and secondarily improve allocation.

Copy link
Contributor

Choose a reason for hiding this comment

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

The PR description calls out that this is for the purpose of reducing allocation.

Copy link

Choose a reason for hiding this comment

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

what would be a better alternative to not doing String concatenation, using a StringBuilder or StringBuffer to build the string only once and then LOG.debug once?

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.

None yet

4 participants