Rate This Document
Findability
Accuracy
Completeness
Readability

Squid Tuning

Purpose

Modify the Squid configuration file to improve the server performance.

Procedure

  1. Modify the Squid configuration file.

    Run the script /usr/local/squid/etc/squid.conf.

    The script content is as follows:

    #!/bin/bash
    SquidIP=$1
    SquidFile=/usr/local/squid/etc/squid.conf
    sed -i "s/http_access deny all/http_access allow all/" $SquidFile
    sed -i "/acl Safe_ports port 80/a acl Safe_ports port 82" $SquidFile
    sed -i "/coredump_dir/d" $SquidFile
    sed -i "/Leave coredumps/a coredump_dir /path/to/\n \
    pid_filename /usr/local/squid/var/run/squid.pid" $SquidFile
    sed -i "51 a\workers 43\n \
    cpu_affinity_map process_numbers=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48 cores=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48\n \
    acl maxconds maxconn 65535\n \
    http_access deny maxconds\n \
    cache_effective_user squid\n \
    cache_effective_group squid\n \
    minimum_object_size 0 bytes\n \
    maximum_object_size 512 KB\n \
    cache_mem 20480 MB\n \
    cache_dir rock /usr/local/squid/squid_cache 1024 slot-size=512\n \
    cache_log /usr/local/squid/var/logs/cache.log\n \
    cache_access_log none\n \
    cache_store_log none\n \
    cache_peer "$SquidIP" parent 80 0 no-query originserver name=httpd\n \
    http_port "$SquidIP":82 accel vhost vport\n \
    cache_peer_access httpd allow all\n" $SquidFile

    Table 1 describes the Squid startup parameters.

    Table 1 Squid startup parameters

    Parameter

    Description

    workers

    Number of processes to be started.

    cpu_affinity_map process_numbers

    Mapping between processes and CPUs. As shown in the preceding information, the processes 1 to 48 started by Squid correspond to CPUs 1 to 48.

  2. Start one Squid instance on each CPU.
    1
    /usr/local/squid/sbin/squid -s
    

    To start two Squid instances, create the squid_2.conf configuration file and start the second instance:

    1
    /usr/local/squid/sbin/squid -f /usr/local/squid/etc/squid_2.conf