Apache Tuning Overview

Source: Internet
Author: User
Tags memory usage thread

Set up a Web server, in the actual site running, perhaps the performance of the server will not be satisfactory, this needs to analyze specific server performance bottlenecks and find a solution to achieve an ideal load state, the Apache hardware tuning should consider his working mode, loaded modules, system kernel parameters , as well as connection requests, and so on, only do some common and simple tuning introduction

Apache tuning should be considered in the following considerations:

L Module: Because the module will occupy a certain amount of memory resources, so useless modules recommend not install.

L Connection Status: Because the connection is built and maintained all need to consume hardware resources, so in order to ensure the hardware performance and access to the coordination of the number, need to the numerical optimization

/proc/sys/net/ipv4/tcp_max_syn_backlog

For connection requests that still have not been confirmed by the client, you need to save the maximum number in the queue

/proc/sys/net/ipv4/tcp_syn_retrirs

/proc/sys/net/ipv4/tcp_synack_retries

Retries the number of times, the test specified number of times to confirm the disconnect, recommended to change the small to 2

/proc/sys/net/ipv4/tcp_keepalive_time

/proc/sys/net/ipv4/tcp_keepalive_intvl

/proc/sys/net/ipv4/tcp_keepalive_probes

Tcp_keepalive_time for the time to keep a conversation,

TCP_KEEPALIVE_INTVL for the number of seconds probes once,

Tcp_keepalive_probes for a couple of times.

/proc/sys/net/ipv4/tcp_tw_recycle

/proc/sys/net/ipv4/tcp_tw_reuse

The value is set to 1 for recyclable memory

/proc/sys/net/ipv4/tcp_max_syn_backlog

Maximum number of connection requests (starting three handshake, but not yet completed)

/proc/sys/net/ipv4/tcp_max_syn_backlog

To control the number of queues in the socket listen

Lkeepalive off/on stay connected, reduces handshake by three times, but consumes memory

Whether to open depends on whether multiple connections are made within the unit time (three handshake),

A connection has been requested several times, it is recommended to open it and adjust keepalivetimeout time appropriately

LMPM Working mode:

1, Prefork mode: The use of multiple child processes, each child process has only one thread. Each process can maintain only one connection at a certain time. On most platforms, prefork MPM is more efficient than worker mpm, but memory usage is much higher. Prefork's wireless path design will in some cases be more advantageous than the worker: it can use Third-party modules that do not handle thread safety well, and it is easier to debug for those platforms where thread debugging is difficult.

2. Worker mode: Using multiple child processes, each child process has multiple threads. Each thread can maintain only one connection at a certain time. In general, the worker mpm is a good choice on a high-traffic HTTP server, because worker MPM memory usage is much lower than prefork MPM. But the worker mpm also by the imperfect place, if a thread crashes, the whole process will "die" along with all its threads. Because the thread shares the memory space, a program must be recognized by the system at run time as "every thread is safe."

Minspareservers and Maxspareservers in the MPM

The minspareservers instruction sets the minimum number of idle child processes. An idle subprocess is a child process that is not processing a request. If the current number of idle child processes is less than minspareservers, Apache will produce a new subprocess at a maximum rate of one per second. This parameter needs to be adjusted only on very busy machines. It is not recommended to adjust too much.

The maxspareservers instruction sets the maximum number of idle child processes. An idle subprocess is a child process that is not processing a request. If there is currently an idle subprocess exceeding the maxspareservers number, the parent process kills the extra child processes.

For example, the process of Apache is the barber shop master, minspareservers setting is a barber for a customer service, but also came to other guests need service is it, this is the case. Maxsparservers is the maximum number of barbers idle, such as an ordinary barber shop, there are 10,000 barber, it is obviously unscientific, the barber live in the place is not enough. So the setting of this value depends on the actual situation. When the traffic is large, it should be properly adjusted.

In short: The value of Startservers is to start several processes immediately as soon as the service is started, and try to keep several idle servers running. The hard limit for the number of processes is specified by maxclients. Although a process can handle many successive requests, Apache will still cancel the process after the number of connections exceeds the Maxrequestsperchild value, to reduce the memory waste!

This article is from the "Tuesday" blog, please be sure to keep this source http://cuimk.blog.51cto.com/6649029/1217598

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Servers/web/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.