Key parameters for significantly improving apache/php Performance

Source: Internet
Author: User
Recently, I want to test my website. I mainly use LoadRunner and apache to test the combination. LoadRunner is mainly used for stress testing. It can simulate user behavior, perform real-time monitoring, have average, and graph, and the results are relatively intuitive. ApacheBench is simple and can be used to test performance. This article focuses on testing Apachephp performance.

Recently, I want to test my website. I mainly use LoadRunner and apache to test the combination. LoadRunner is mainly used for stress testing. It can simulate user behavior, perform real-time monitoring, have average, and graph, and the results are relatively intuitive. ApacheBench is simple and can be used to test performance. This article focuses on testing the performance of Apache/php.

Recently, I want to test my website. I mainly use LoadRunner and apache to test the combination. LoadRunner is mainly used for stress testing. It can simulate user behavior, perform real-time monitoring, have average value, and graph, and the results are relatively intuitive. ApacheBench is simple and can be used to test performance. This article focuses on testing the performance of Apache/php, so we will describe it with apache.pdf.

A problem is found during the test.

This error "apr_poll: The timeout specified has expired (70007)" is often reported after I use apacheied for testing for a period of time, which aroused my strong attention.

Apache/php problem Testing Process

Testing Machine

Hardware CPU G620 2.60 GHz (dual-core) RAM 4.00 GB (2.99GB available)
Software win7 32-bit flagship version Apache/2.2.19 PHP/5.3.26
Test command
AB-n 10000-c 100 http: // localhost/
Test Results
Static Page (index.html) Testing Performance: 1200-1300 rps
PHP blank pages (only echo 1;) the test results are unstable and fluctuate greatly. 100-600 rps, the lower the test performance. Tests often reach 95% ~ When 99%, ApacheBench stops and reports an error or responds for a long time. The test result is more than 100.

Possible apachetings errors during PHP page testing:
Apr_poll: The timeout specified has expired( 70007)
Total of 9987 requests completed

The cause of this error was identified through various troubleshooting. When php uses session. auto_start, this problem will almost occur after testing for a period of time. On the contrary, the php session. auto_start is canceled and the problem does not occur. Key parameters for improving apache/php Performance Parameter 1: Apache KeepAlive
Apache KeepAlive needs to be bound to a thread. When the server is busy, all threads are consumed.
KeepAlive Off

Parameter 2: Apache MPM

Apache MPM can improve apache's processing capability by optimizing the scheduling of apache internal processes. Here, it is a windows parameter (other systems are not tested and are not provided for reference. For details, refer to the official documentation)

 
  #Win32DisableAcceptExThreadsPerChild 1000MaxRequestsPerChild 10000
 

The parameter Win32DisableAcceptEx reduces performance. However, if the server network is unstable, Apache often reports this error "the network name specified by [warn] (OS 64) is no longer available. Winnt_accept: Asynchronous AcceptEx failed. ", you must consider using

The use of the Win32DisableAcceptEx parameter is also risky and may cause another problem. During the ApacheBench test, the following errors may occur:

Apr_socket_recv: the remote host forces an existing connection to be closed. (730054)
Total of 195 requests completed

Parameter 3: PHP Session
session.auto_start = 0

The cost is very small. It is also a good habit to use session_start () explicitly every time a session is used.

The above three parameters have been modified to improve the performance of apache/php. Let's take a look at the test results:

Static Page test performance: 1500-1700 rps

Php blank page test performance 1100-1200 rps

Or the above results are not exciting enough. The test data in the article is tested on my normal computer. What will happen if I change to a server?

The Dell PowerEdge R610 (Xeon E5606 * 2/16 GB) server is equipped with a windows server 2008 System, and the php blank page rps reaches kb. 2.2k this processing capability is already impressive, and then Apache does not actually use iocp.

Php/session further discussion

If the page explicitly calls session_start (), what is the performance difference between session. auto_start in php?

I also did a test. The answer is the same. That is to say, session usage consumes a lot of performance.

So why does the session consume a lot of performance?

Is it related to the session. save_handler's method of saving the session? Is it an OS I/O bottleneck?

Next we will do some tests to study this problem.

Session. save_handler has several Storage Methods: files, memcache, mysql, etc.

The mysql storage method is similar to files, or the efficiency is not higher than those of files, because during high concurrency, the update is too frequent and there are too many problems.

Memcache is stored in the memory, and reading and writing are more efficient than system file io, but the disadvantage is that data cannot be persisted.

So here we test the memcache session saving efficiency. What is the default file mode?

Modify the php configuration file

session.save_handler = memcachesession.save_path = "tcp://127.0.0.1:11211"session.auto_start = 1

Php blank page test performance is stable at 500-750 rps, and no error occurs in apache.pdf

Back to the files method, is it related to the session storage path?

Modify the php configuration file
session.save_handler = filessession.save_path = "d:/sess_tmp/"session.auto_start = 1
The test result is similar to the initial result, which also causes an Apachebench error.
Conclusion

The main problem found during this test is the system file I/O bottleneck. Compared with memory io, file io is low speed and error-prone. Here are the following conclusions:

1. If you do not need to read or write files, consider using memory databases such as memcache.

2. Avoid file operations on a large page, such as MySQL Select/Update.

3. You can write static html files for accessing large pages and dynamically update them in js mode. The javascript script is executed only after the page is loaded. That is to say, this method improves the server's ability to defend against ddos attacks to some extent.


Continue reading

Windows server responds to high concurrency and DDOS attacks

Simple web server load balancing

Website Security: apache/php security configuration

Apache module improves webpage loading speed

Compile php extension memcache in windows

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.