Rate This Document
Findability
Accuracy
Completeness
Readability

Apache Tuning

Purpose

Modify the Apache configuration file to improve the server performance. In the following example, bind the Apache processes to 8 CPU cores to process HTTP short connections.

Procedure

  1. Edit the httpd-mpm.conf file.
    1. Open httpd-mpm.conf.
      1
      vim /usr/local/apache2/conf/extra/httpd-mpm.conf
      
    2. Add the following content to the file:
      <IfModule mpm_worker_module>
      StartServers 3
      ServerLimit 3
      MinSpareThreads 12
      MaxSpareThreads 12
      ThreadsPerChild 4
      MaxRequestWorkers 12
      MaxConnectionsPerChild 0
      </IfModule>
      Table 1 describes the parameters of mpm_worker_module.
      Table 1 mpm_worker_module parameter description

      Parameter

      Description

      StartServers

      Specifies the number of child processes created during service startup.

      ServerLimit

      Specifies the maximum number of processes that can be created.

      MinSpareThreads

      Specifies the minimum number of threads in idle state. If the number is insufficient, new idle threads are automatically created.

      MaxSpareThreads

      Specifies the maximum number of threads in idle state. If the number of idle threads exceeds this threshold, extra idle threads are killed.

      ThreadsPerChild

      Specifies the number of threads generated by each child process.

      MaxRequestWorkers

      Specifies the maximum number of requests that can be concurrently accessed by clients. When the number of requests exceeds this threshold, the extra requests enter the waiting queue.

      MaxConnectionsPerChild

      Specifies the maximum number of connections that can be processed during the lifecycle of a subthread. If the number of connections reaches this threshold, the subthread ends.

    3. Press Esc, type :wq!, and press Enter to save the file and exit.
  2. Bind the Apache process to a core and start it.
    1
    taskset -c N /usr/local/apache2/bin/httpd -f /usr/local/apache2/conf/httpd.conf -k start
    

    Bind the Apache process to core N. N indicates the core number. For example, 0-7 indicates cores 0 to 7.

  3. Configure an independent directory for each Apache instance.

    Start one Apache instance for one CPU, and two Apache instances for two CPUs. Each Apache instance accesses its own directory file.

    • Start the second Apache instance.
      1
      cp -r /usr/local/apache2 /usr/local/apache2-2
      
    • Modify Apache configuration parameters. Bind different instances to different cores.
      1
      taskset -c N /usr/local/apache2-2/bin/httpd -f /usr/local/apache2-2/conf/httpd.conf -k start