Squid_ The Definitive Guide - Duane Wessels [62]
Figure 7-2 demonstrates the LM-factor algorithm. Squid caches an object that is 3 hours old (based on the Date and Last-Modified headers). With an LM-factor value of 50%, the response will be fresh for the next 1.5 hours, after which the object expires and is considered stale. If a user requests the cached object during the fresh period, Squid returns an unvalidated cache hit. For a request that occurs during the stale period, Squid forwards a validation request to the origin server.
Figure 7-2. Calculating expiration times based on LM-factor
It's important to understand the order that Squid checks the various values. Here is a simplified description of Squid's refresh_pattern algorithm:
The response is stale if the response age is greater than the refresh_pattern max value.
The response is fresh if the LM-factor is less than the refresh_pattern percent value.
The response is fresh if the response age is less than the refresh_pattern min value.
Otherwise, the response is stale.
The refresh_pattern directive also has a handful of options that cause Squid to disobey the HTTP protocol specification. They are as follows:
override-expire
When set, this option causes Squid to check the min value before checking the Expires header. Thus, a non-zero min time makes Squid return an unvalidated cache hit even if the response is preexpired.
override-lastmod
When set, this option causes Squid to check the min value before the LM-factor percentage.
reload-into-ims
When set, this option makes Squid transform a request with a no-cache directive into a validation (If-Modified-Since) request. In other words, Squid adds an If-Modified-Since header to the request before forwarding it on. Note that this only works for objects that have a Last-Modified timestamp. The outbound request retains the no-cache directive, so that it reaches the origin server.
ignore-reload
When set, this option causes Squid to ignore the no-cache directive, if any, in the request.
Exercises
Run df on your existing filesystems and calculate the ratio of inodes to disk space. If any of those partitions are used for Squid's disk cache, do you think you'll run out of space, or inodes first?
Try to intentionally make Squid run out of disk space on a cache directory. How does Squid deal with this situation?
Write a shell script to search the cache for given URIs and optionally remove them.
Examine Squid's store.log and estimate the percentage of requests that are subject to the refresh_pattern rules.
Can you think of any negative side effects of the ignore-reload, override-expire, and related options?
Chapter 8. Advanced Disk Cache Topics
Performance is one of the biggest concerns for Squid administrators. As the load placed on Squid increases, disk I/O is typically the primary bottleneck. The reason for this performance limitation is due to the importance that Unix filesystems place on consistency after a system crash.
By default, Squid uses a relatively simple storage scheme (ufs). All disk I/O is performed by the main Squid process. With traditional Unix filesystems, certain operations always block the calling process. For example, calling open( ) on the Unix Fast Filesystem (UFS) causes the operating system to allocate and initialize certain on-disk data structures. The system call doesn't return until these I/O operations complete, which may take longer than you'd like if the disks are already busy with other tasks.
Under heavy load, these filesystem operations can block the Squid process for small, but significant, amounts of time. The point at which the filesystem becomes a bottleneck depends