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

Improve performance of DefaultHttpLogFormatter #524

Merged
merged 5 commits into from Jun 18, 2019

Conversation

skjolber
Copy link
Contributor

@skjolber skjolber commented Jun 4, 2019

Improve performance of DefaultHttpLogFormatter.

Description

Construct log statement in a single 'streaming' fasion.

Motivation and Context

The previous implementation used a two-step approach via StructuredHttpLogFormatters format + prepare. Switching to a single step approach improves performance considerably, run HttpLogFormatterBenchmark for comparisons.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@skjolber skjolber force-pushed the jmhHttpLogFormatter branch 2 times, most recently from dc1d5ed to af05b0d Compare June 4, 2019 11:00
@zalando zalando deleted a comment Jun 4, 2019
@zalando zalando deleted a comment Jun 4, 2019
@zalando zalando deleted a comment Jun 4, 2019
@zalando zalando deleted a comment Jun 4, 2019
@whiskeysierra
Copy link
Collaborator

Improve performance of DefaultHttpLogFormatter.

The README states that

[..] provided by the DefaultHttpLogFormatter. It is primarily designed to be used for local development and debugging, not for production use.

https://github.com/zalando/logbook#http

I'm not saying that we shouldn't take low-hanging fruits and make it faster, but if it requires semi-significant changes to our API (seems to me that it does) then we should re-consider.

@skjolber
Copy link
Contributor Author

Visibility changes to API should be reverted now, must had leaked from previously adapting JsonHttpLogFormatter in the same branch. 👀

My initial description is incorrect, DefaultHttpLogFormatter does not currently use StructuredHttpLogFormatter, so this PR is essentially moving to directly writing with a StringBuilder instead of collecting a list of lines and appending them at the end.

I'll admit the performance of the HttpLogFormatter is not that important, but at least it is quite a lot faster now (like 10x). We're actually running both the HttpLogFormatter and the JsonHttpLogFormatter for build / local development, one is printed to console and the other is used for log statement unit testing.

@skjolber
Copy link
Contributor Author

BTW: Has Ansi coding been discussed?

@whiskeysierra
Copy link
Collaborator

I'll admit the performance of the HttpLogFormatter is not that important, but at least it is quite a lot faster now (like 10x). We're actually running both the HttpLogFormatter and the JsonHttpLogFormatter for build / local development, one is printed to console and the other is used for log statement unit testing.

I actually don't mind having this change. The code is still readable overall. 10x is quite appealing, tbh.

BTW: Has Ansi coding been discussed?

What do you mean?

}

private static boolean isNotStandardPort(final String scheme, final int port) {
return "http".equals(scheme) && port != 80 ||
"https".equals(scheme) && port != 443;
return ("http".equals(scheme) && port != 80) ||
Copy link
Collaborator

Choose a reason for hiding this comment

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

Those are not really needed, are they?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Strictly, no, it was intended as an improvement in readability, forgot to comment.

@skjolber
Copy link
Contributor Author

Ansi coding as in colors for improved readablity for local development and debugging. I guess it could be a future improvement (i.e. enabled by a config parameter).

@whiskeysierra
Copy link
Collaborator

Ansi coding as in colors for improved readablity for local development and debugging. I guess it could be a future improvement (i.e. enabled by a config parameter).

Let's move this to a separate issue.

@whiskeysierra
Copy link
Collaborator

👍

@whiskeysierra whiskeysierra merged commit 11d4f4a into zalando:master Jun 18, 2019
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

2 participants