cmcfarlen opened a new pull request, #13769:
URL: https://github.com/apache/trafficserver/pull/13769

   Follow-up to #13405.
   
   Before #13405, every 304 revalidation deleted and re-added the cached 
response's `Age`/`ETag`/`Expires` fields. A dead field slot only freed its 
block once all 16 slots were deleted, but a cache round trip 
(`MIMEFieldBlockImpl::unmarshal`) turns dead slots into empty ones, which that 
check never counted. So every revalidation of a long-lived object added 
permanent dead slots, and over time its cached response grew to hundreds of 
field blocks around a handful of live fields. We found one in production 
carrying ~300 blocks (~170 KB marshaled) for 17 live headers on an OCSP 
response with an 867-byte body.
   
   #13405 stopped the merge from creating dead slots, and #13455 reuses deleted 
slots instead of allocating new blocks. Neither releases blocks, and every copy 
and marshal of a header keeps them. So an object bloated by an older build 
stays that size for as long as it is cached, and every revalidation rewrites 
all of it to disk and unmarshals all of it on read.
   
   This compacts such a header when a cache update is about to write it back. 
If the stored response holds more than two field blocks beyond what its live 
fields need, it is rebuilt from its live fields in slot order into a fresh 
heap, which keeps field and duplicate order and the stored name spelling 
unchanged. The fresh heap is required: copying onto the existing heap frees the 
dead blocks but leaves their space inside the object region that marshal writes 
out. A header from a fresh cache should not reach the threshold, so ordinary 
updates only pay for a walk of the block chain.
   
   The unit test builds a header with a few hundred dead blocks around 11 live 
fields (including duplicate `Cache-Control` and `Vary` lines) and round-trips 
it through marshal/unmarshal as the update path would see it. It then checks 
that compaction leaves the printed header byte-identical, keeps duplicate order 
and presence bits, shrinks it to one block and under 1/20 of its marshaled 
size, and leaves an ordinary or already-compacted header alone.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to