Skip to content

Server uses sync.Pool for gzip.Writer allocations#484

Merged
tigrannajaryan merged 2 commits intoopen-telemetry:mainfrom
michel-laterman:enhancement/server-improvements
Jan 9, 2026
Merged

Server uses sync.Pool for gzip.Writer allocations#484
tigrannajaryan merged 2 commits intoopen-telemetry:mainfrom
michel-laterman:enhancement/server-improvements

Conversation

@michel-laterman
Copy link
Copy Markdown
Contributor

@michel-laterman michel-laterman commented Jan 7, 2026

Use of gzip.Writer pool for plain HTTP responses - gzip.Writers have a large memory footprint, if many agent clients clients were to respond at once a server could have an OOM crash. Use of the pool also reduces allocs.

go test -v -benchmem -benchtime 5s -bench=BenchmarkCompressGzip
...
goos: darwin
goarch: arm64
pkg: github.com/open-telemetry/opamp-go/server
cpu: Apple M3 Pro
BenchmarkCompressGzip
BenchmarkCompressGzip/with_pool
BenchmarkCompressGzip/with_pool-12         	  483432	     12155 ns/op	     113 B/op	       2 allocs/op
BenchmarkCompressGzip/no_pool
BenchmarkCompressGzip/no_pool-12           	   96456	     60972 ns/op	  813988 B/op	      19 allocs/op

@michel-laterman michel-laterman requested a review from a team as a code owner January 7, 2026 20:10
@michel-laterman michel-laterman force-pushed the enhancement/server-improvements branch 2 times, most recently from af30fb6 to bdaff56 Compare January 7, 2026 22:00
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.77%. Comparing base (d508718) to head (2594b4b).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #484      +/-   ##
==========================================
+ Coverage   81.71%   81.77%   +0.06%     
==========================================
  Files          27       27              
  Lines        2122     2129       +7     
==========================================
+ Hits         1734     1741       +7     
  Misses        263      263              
  Partials      125      125              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tigrannajaryan
Copy link
Copy Markdown
Member

Please break this down into individual PRs, one PR per topic.

use of gzip.Writer pool for plain HTTP responses - gzip.Writers have a large memory footprint, if many agent clients clients were to respond at once a server could have an OOM crash. Use of the pool also reduces allocs.

Please add a benchmark that shows before/after memory/CPU usage and demonstrates the improvement.

@michel-laterman
Copy link
Copy Markdown
Contributor Author

Callback fix pr: #488

@michel-laterman
Copy link
Copy Markdown
Contributor Author

non gwPool changes: #489

I'm going to rewrite this PR's history so that the 1st commit has both compress methods, and a benchmark for them, and the 2nd commit only has the (new) pool method.

@michel-laterman michel-laterman changed the title Various improvements to server library Server uses sync.Pool for gzip.Writer allocations Jan 9, 2026
@michel-laterman michel-laterman force-pushed the enhancement/server-improvements branch from a73d4c2 to ec10b07 Compare January 9, 2026 16:24
@tigrannajaryan tigrannajaryan merged commit f9e370c into open-telemetry:main Jan 9, 2026
11 checks passed
@michel-laterman michel-laterman deleted the enhancement/server-improvements branch January 9, 2026 20:20
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.

2 participants