Pre‑gzip Optimization with APC User Cache for PHP Activity Pages
The article analyzes the trade‑offs of lowering gzip compression levels for high‑traffic activity pages, proposes pre‑compressing HTML and storing it in APC's user cache, discusses cache placement options, configuration parameters, testing results, and practical implementation details to boost QPS while managing bandwidth and latency.
The author revisits a previous attempt to increase QPS by adjusting gzip compression, noting that reducing the compression level saves CPU but increases bandwidth, resulting in a net neutral cost when accounting for machine and bandwidth expenses.
Because gzip remains a major bottleneck, the article explores pre‑compressing HTML pages and storing the compressed output in memory, evaluating where to place the cached data (process memory, Tair, disk, or shared memory) and concluding that APC's user cache in shared memory is the most viable solution.
Key APC configuration parameters are examined, including apc.shm_segments, apc.shm_size, apc.user_ttl, and apc.gc_ttl, highlighting that APC uses TTL‑based eviction rather than LRU.
Source code snippets from APC 3.0.9 illustrate the hash‑based storage structure and the insert/find logic that respects TTL values, ensuring expired entries are reclaimed.
To avoid double compression, the article suggests signaling Nginx not to gzip already‑compressed responses, for example by adjusting gzip_types or gzip_min_length based on content type and size.
Instrumentation ("打点") challenges are discussed, with two approaches: passing a timestamp via cookie or using segmented compression, noting the limitations of each in high‑traffic environments.
Performance tests using
ab -n 10000 -c 10 -H 'Accept-Encoding:gzip' http://localhost:8888/xxx.phpdemonstrate that pre‑gzip can raise QPS by up to tenfold and reduce response time by tens of milliseconds, while bandwidth savings are modest.
The article also evaluates the feasibility of storing compressed data in Swift object storage, concluding that user‑agent‑based variations would cause cache fragmentation and reduced hit rates.
In summary, the optimization combines APC user cache for pre‑compressed HTML, careful TTL settings, and avoidance of redundant gzip, resulting in significant QPS gains with minimal CPU overhead, while acknowledging remaining challenges such as metric collection.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Architecture Digest
Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
