Skip to content

Http2FrameLogger avoid hex dump of the ByteBufs when log disabled#7026

Closed
Gordiychuk wants to merge 4 commits intonetty:4.1from
Gordiychuk:http2_frame_encoder_reduce_memory_allocation_by_logger
Closed

Http2FrameLogger avoid hex dump of the ByteBufs when log disabled#7026
Gordiychuk wants to merge 4 commits intonetty:4.1from
Gordiychuk:http2_frame_encoder_reduce_memory_allocation_by_logger

Conversation

@Gordiychuk
Copy link
Copy Markdown
Contributor

Currentry logger create hex dump even if log write will not apply.
It's unecessary GC overhead. Restore optiomization from #3492

Close #7025

Currentry logger create hex dump even if log write will not apply.
It's unecessary GC overhead. Restore optiomization from netty#3492

Close netty#7025
@normanmaurer
Copy link
Copy Markdown
Member

@Gordiychuk please fix checkstyle error
https://garage.netty.io/teamcity/viewLog.html?buildId=22635&buildTypeId=pulls_netty&tab=buildLog

Also please sign out icla and let me know once done
https://netty.io/s/icla

@Gordiychuk
Copy link
Copy Markdown
Contributor Author

Also please sign out icla and let me know once done

done

int windowSizeIncrement) {
logger.log(level, "{} {} WINDOW_UPDATE: streamId={} windowSizeIncrement={}", ctx.channel(),
direction.name(), streamId, windowSizeIncrement);
if (isEnable()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The log level will be enforced by the logger. We should only have to "double check" the log level if creation of one of the arguments may potentially be expensive. We should only need this double check on methods with a toString(..) as a parameter.

Alternatively we could isolate the check in toString:

private String toString(ByteBuf buf) {
        if (!logger.isEnabled(level)) {
           return "";
        }
        if (level == InternalLogLevel.TRACE || buf.readableBytes() <= BUFFER_LENGTH_THRESHOLD) {
            // Log the entire buffer.
            return ByteBufUtil.hexDump(buf);
        }

        // Otherwise just log the first 64 bytes.
        int length = Math.min(buf.readableBytes(), BUFFER_LENGTH_THRESHOLD);
        return ByteBufUtil.hexDump(buf, buf.readerIndex(), length) + "...";
    }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Gordiychuk please address and once done we can merge it :)


private String toString(ByteBuf buf) {
if (!logger.isEnabled(level)) {
return "";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

just one last nit: StringUtil.EMPTY

@normanmaurer
Copy link
Copy Markdown
Member

Squashed and cherry-picked into 4.1 (fe8ecea).

@Gordiychuk thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants