Repository navigation
handler3: gzip-compress cached OpenAPI V3 JSON specs - #656
Open
mauriciopoppe wants to merge 1 commit into
Open
mauriciopoppe wants to merge 1 commit into
mauriciopoppe wants to merge 1 commit into
Conversation
Contributor
mauriciopoppe
force-pushed
the
pr-handler3-compressed-cache
branch
from
October 8, 2026 00:04
82f223b to
fa06d53
Compare
Contributor
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mauriciopoppe The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
mauriciopoppe
force-pushed
the
pr-handler3-compressed-cache
branch
from
October 8, 2026 00:41
fa06d53 to
5c71d05
Compare
…mpressed gzip responses
mauriciopoppe
force-pushed
the
pr-handler3-compressed-cache
branch
from
October 8, 2026 01:49
5c71d05 to
115a031
Compare
mauriciopoppe
marked this pull request as ready for review
October 8, 2026 16:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
In
kube-apiserver,pkg/handler3caches the marshaled JSON bytes of each accessed GroupVersion's OpenAPI V3 spec inopenAPIV3Group.jsonCachefor the lifetime of the server (6.85 MBof retained heap for just 3 GroupVersions, and~18+ MBacross all built-in GroupVersions).This PR stores gzip-compressed JSON bytes in
jsonCachewithout changing ETag hashes, discovery URLs, or response payloads:openAPIV3Group.jsonCache(pkg/handler3/handler.goandnewOpenAPIV3Group): ComputescomputeETag(jsonBytes)on the uncompressed JSON first, then stores the gzip-compressed slice (bytes.Clone(buf.Bytes())) intimedSpec.specusingsync.Pool(gzipWriterPoolandgzipReaderPool) to reusegzip.Writerandgzip.Readerstate machines without lock contention. Only readers that completeio.ReadAllandClosewithout error are returned togzipReaderPool.Accept-Encoding: gzipand lazy-decompress vialazyGzipReadSeeker(pkg/handler3/handler.goandHandleGroupVersion):HandleGroupVersionsetsVary: Accept-Encodingon JSON responses so HTTP caches and reverse proxies distinguish compressed and uncompressed representations. WhenacceptsGzip(r)is true (iterating allr.Header.Values("Accept-Encoding")header lines per RFC 9110 and verifying noRangeheader is present),HandleGroupVersionsetsContent-Encoding: gzipand servestimedSpec.specdirectly. Plain JSON requests pass&lazyGzipReadSeeker{compressed: data}tohttp.ServeContent, delaying decompression untilSeekorReadis invoked afterhttp.ServeContentevaluatesIf-None-MatchandIf-Modified-Sincepreconditions (304 Not Modifiedresponses perform zero gzip decompression).Special notes for your reviewer:
1.
pkg/handler3Benchmarks (go test -bench=. -benchmem -count=5 ./pkg/handler3/...)e2e80c32a35f)BenchmarkHandler3CachedSpecMemorycached-bytes(len)604,218 B16,386 B-97.3%(36.9xsmaller)BenchmarkHandler3CachedSpecMemorycached-cap-bytes(cap)622,592 B18,432 B-97.0%(33.8xsmaller)BenchmarkServeGroupVersionGzipns/op)263,455 ns/op17,590 ns/op-93.3%(15.0xfaster)BenchmarkServeGroupVersionGzipB/op)526,292 B/op11,784 B/op-97.8%(-514.5 KB/op)2.
kube-apiserverHeap Impact (pprof inuse_spaceviaTestAPIServerMemoryIntegration, 3 GroupVersions Queried)pprofSymbol (inuse_space)bytes.Clone(fromhandler3json.Marshal)6,853.25 kB< 218 kB-6.67 MB(-96.8%)kube-apiserverLive Heap Impact6,853.25 kB~1,481 kB-5.51 MBnet live heapDoes this PR introduce a user-facing change?