How To: Optimze Squid Cache Performance

Howto optimze squid cache performance


Squid makes high demands on the hardware in order to work effectively. Squid requires as much main memory AND a very fast storage medium as possible. In the main memory, Squid holds the “hot objects”, i.e. many small elements that have often been requested. The hard disk memory contains larger, less frequently requested elements.

Configuration Parameters

Two parameters in squid.conf mainly determine the memory usage of squid:


Specifies the location, type (UFS,…) and size of the disk space used. Several directories can be specified (e.g. for performance reasons).

cache_dir ufs /var/cache/squid/ 100 16 256
Creates a 100MB cache with 16 main directories and 256 subdirectories each.
Note: Cache size should not be more than 80% of the disk space available.


This entry determines how much memory Squid can use for particularly popular responses. The default value is 8 MB. This value does not indicate the real memory usage of Squid and can be exceeded.

Approximate Determination of RAM Usage
cache mem is about one third of the cache memory for the “Hot Objects” of Squid (apart from the cache, indexes and metadata are also kept in the main memory). In addition there are indices for the hard disk cache, which are also kept in the main memory. Rule: Per 1G hard disk space 14MB RAM are required.

 cache_dir ufs /var/cache/squid/ 2048 16 256
 cache_mem 256MB

Maximum memory requirement is here:
Total = (256MB * 3)+(14MB * 2) = 768MB+28MB = 796MB

Monitoring bottlenecks

As soon as swapping activities occur on a system running Squid, measures must be taken to optimize the system.

Possible indications of bottlenecks:

  • swap: memory usage is constantly changing (top)
  • so/si: Multiple values >0 (vmstat)
  • wait: High I/O load of the CPU (top)

Remedy either by hardware upgrade (RAID, SSDs, RAM) or reduction of the RAM used by Squid with the help of the above parameters.