Skip to content

performance: use first h2 frame header detect instead of read first frame from whole payload#705

Merged
cfc4n merged 1 commit into
gojue:masterfrom
yuweizzz:h2-patch
Dec 27, 2024
Merged

performance: use first h2 frame header detect instead of read first frame from whole payload#705
cfc4n merged 1 commit into
gojue:masterfrom
yuweizzz:h2-patch

Conversation

@yuweizzz

Copy link
Copy Markdown
Contributor

fix #700

the h2 response detect will read whole payload, which may cost too much memory.

@cfc4n

cfc4n commented Dec 25, 2024

Copy link
Copy Markdown
Member

@chilli13 Can you test the performance?

Comment thread pkg/event_processor/http2_request.go
Comment thread pkg/event_processor/http2_response.go
Comment thread pkg/event_processor/http2_response.go
@chilli13

Copy link
Copy Markdown
Contributor

@chilli13 Can you test the performance?

The optimization effect on memory consumption is quite obvious.
50MBps http2 traffic
taskset -c 8 ./bin/ecapture tls

before optimism (master)

=====================
Process ecapture resource consumption statistics
CPU Average: 128.20%
CPU Max: 152.00%
Memory Average: 629.41 MB
Memory Max: 694.56 MB
=====================

after optimism (h2-patch)

=====================
Process ecapture resource consumption statistics
CPU Average: 72.60%
CPU Max: 81.00%
Memory Average: 389.11 MB
Memory Max: 508.99 MB
=====================

@yuweizzz

Copy link
Copy Markdown
Contributor Author

Why the data[4] "works":

data[4] actually read the frame flags, look back for flags type:

const (
	// Data Frame
	FlagDataEndStream Flags = 0x1
	FlagDataPadded    Flags = 0x8

	// Headers Frame
	FlagHeadersEndStream  Flags = 0x1
	FlagHeadersEndHeaders Flags = 0x4
	FlagHeadersPadded     Flags = 0x8
	FlagHeadersPriority   Flags = 0x20

	// Settings Frame
	FlagSettingsAck Flags = 0x1

	// Ping Frame
	FlagPingAck Flags = 0x1

	// Continuation Frame
	FlagContinuationEndHeaders Flags = 0x4

	FlagPushPromiseEndHeaders Flags = 0x4
	FlagPushPromisePadded     Flags = 0x8
)

those value uint32(data[4])>>7 will always pass the check.

@cfc4n cfc4n added the improve label Dec 27, 2024

@cfc4n cfc4n left a comment

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.

LGTM, Thanks.

@cfc4n cfc4n merged commit 252f1c2 into gojue:master Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

performance issue: (*HTTP2Response).detect cost too much memory

3 participants