1

I'm trying to load test a LAMP application that my team developed and deployed on AWS ubuntu 14.04 using jmeter. We are using AWS CDN to serve static files, mysql and apache are on the same host.

When there is only one user doing stuff, the response time is normal, between 2 and 5 seconds depending on the page.

My goal is to make it respond with that same time to 100 connected users doing stuff at the same time.

I used an AWS T2.MEDIUM instance ( 2 vCPU + 4GB RAM ) and started with mod_php and prefork module but I wasn't satisfied at all. the server was ridiculously slow. The response time was +20s with high CPU and RAM usage.

I tried with php-fpm and event module after going on some SO ressources. RAM usage is better now but CPU used by php-fpm process is too high. (I tried with static/ondemand/dynamic with not result)

Here is my configuration using dynamic configuration with event module to serve 100 concurrent users on aws t2.medium instance ( 2 vCPU + 4GB RAM ) - PHP-FPM CPU usage is very high:

top - 17:21:41 up  1:58,  1 user,  load average: 5.52, 3.83, 1.86
Tasks: 128 total,   6 running, 122 sleeping,   0 stopped,   0 zombie
%Cpu(s): 97.0 us,  2.7 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  0.2 si,  0.2 st
KiB Mem:   4046848 total,  2170544 used,  1876304 free,   104788 buffers
KiB Swap:        0 total,        0 used,        0 free.  1107856 cached Mem
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND    
14285 www-data  20   0  603996 192688  25096 R  52.3  4.8   2:19.28 php5-fpm   
14300 www-data  20   0  814276 402980  29224 R  36.6 10.0   2:25.77 php5-fpm   
14318 www-data  20   0  448444  40480  25800 R  34.3  1.0   2:03.65 php5-fpm   
14384 www-data  20   0  455808  48472  25860 R  34.3  1.2   2:06.95 php5-fpm   
15022 www-data  20   0  447488  38748  24644 R  31.6  1.0   1:25.14 php5-fpm   
16309 perf      20   0  321248  39296   9632 S   5.0  1.0   0:00.15 php5       
 1106 mysql     20   0 1129640 148232   7548 S   1.7  3.7   0:38.17 mysqld

/etc/php5/fpm/php-fpm.conf

[global]
pid = /var/run/php5-fpm.pid
error_log = /var/log/php5-fpm.log
include=/etc/php5/fpm/pool.d/*.conf

/etc/php5/fpm/pool.d/www.conf

[www]

pm.status_path = /status

user = www-data
group = www-data

listen = /var/run/php5-fpm.sock

listen.owner = www-data
listen.group = www-data

pm = dynamic 
pm.max_children = 100
pm.start_servers = 5
pm.min_spare_servers = 4
pm.max_spare_servers = 6
pm.max_requests =0 

rlimit_files = 131072
rlimit_core = unlimited
catch_workers_output = yes

chdir = /

/etc/apache2/mods-enabled/mpm_event.conf

 <IfModule mpm_event_module>
            ServerLimit              10
            StartServers              5
            MinSpareThreads           5
            MaxSpareThreads          15
            ThreadLimit              50
            ThreadsPerChild          10
            MaxRequestWorkers       100
            MaxConnectionsPerChild    0
    </IfModule>

I feel I'm so close but I can't do it. I will update my question with any file, log or output you would ask for. PLEASE, this is very critical and I would be very grateful to you. Thank you very much

==================================== UPDATE:1

Looking at the php error log, I can see tons of PHP Fatal errors:

call to a member function xxxxx() on a non-object

Can PHP fatal error cause high cpu? ( May being written to by multiple process consumes more cpu's cycles )

  • Did you forget to enable opcache? – Michael Hampton Dec 5 '16 at 18:20
  • Profile your PHP application? Figure out what, and why it is using so much of your CPU? Then either fix it, or if it can't be fixed buy more cloud. – Zoredache Dec 5 '16 at 20:12
  • This is exactly why I posted this question. – another geek Dec 5 '16 at 20:13
  • opcache is enabled by default. – another geek Dec 6 '16 at 8:23
  • "When there is only one user doing stuff, the response time is normal, between 2 and 5 seconds depending on the page." -- what? Is the application particularly heavy, or since when 2-5 s page load times are normal when only a single user is accessing the site? I suspect excessive database queries, missing indexes, or something else rotten with the MySQL. – Janne Pikkarainen Dec 8 '16 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.