Ubuntu – Servers crash with 3000 concurrent clients – how to config it right? PHP & Apache

Apache2load-testingphp7Ubuntu

I've 4 web servers, 2 database servers (read & write), Redis and a load balancer. I'm using PHP 7.0 & Apache2 & MySQL 5.7, however when I do load tests with 3000 users which surf at the same time, the servers crash one by one.

The Apache servers are strong, each one has 32GB ram and sadly all of them reach to the maximum usage of RAM.

We've made a lot of changes to the code, however, it does not feel right to me, my hosting providers can't help me further config my server as they say this is the best they can do, and here I need your help – what are we missing? which configurations in the PHP / Apache / MySQL should be set?

I would clarify that the site works well for let's say 300 clients, but as more and more clients visit, the response time reaches to 50 seconds per request which is really weird, how only 400 clients make my server to respond so slowly?

I'm really despaired and confused, what should we look at?

Thanks a lot.

Best Answer

We had even 6000 last summer. How do 4 servers with load balancer not handle such requests?

So what changed? To answer the question, almost always by being bogged down in backend code processing, and sometimes by things like tcp socket exhaustion, and other times it is just simple pool/etc limits between apache and php.

Follow this process:

  1. Eliminate PHP from the stack. Serve only small static files for your testing
  2. Observe results and tune apache/OS to accommodate the desired connections
  3. Reintroduce PHP. The server will be unable to match static file serving performance
  4. Profile your PHP code, identify slowdowns and resolve them
  5. Finally: Cache whatever PHP results you possibly can.

"How do I get nondescript php application to meet x benchmark?" is a very broad question but the process is generally, get your frontend static serving to beat your requirements, then add your backend code to the mix. Either ix slowness in the backend code or eliminate it.

Once you start hitting thousands of concurrent users.. You're going to brush up against certain limits (filesystem speed, memory, cpu speed, communication latency, inefficient wordpress code and slow database calls as well as a ton of context switching on the cpu) that are going to compound and quickly result in exponential degradation of service.

Related Topic