L
L
Lubovka9992017-06-14 13:45:40
PHP
Lubovka999, 2017-06-14 13:45:40

How to speed up a server based on NGINX - Php-Fpm?

Hello everyone, guys tell me how to speed up this car. Characteristics: Intel Core i5 4c/4t 3 GHz / 16 GB RAM / 4x2 TB SATA / 100 Mbps
The fact is that this server is designed to give the user an audio file, that is, he listens and downloads it.
Loads on PHP-FPM are just awful, 60-80% CPU load.
Here is the log:

top - 10:35:51 up  1:18,  1 user,  load average: 52.38, 52.66, 49.43
Tasks: 434 total,  19 running, 415 sleeping,   0 stopped,   0 zombie
%Cpu(s): 60.7 us, 23.0 sy,  0.0 ni, 12.6 id,  1.6 wa,  0.0 hi,  2.2 si,  0.0 st
KiB Mem : 16165052 total,  6993284 free,  3823340 used,  5348428 buff/cache
KiB Swap:  8388604 total,  8388604 free,        0 used. 11754556 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 4447 nginx     20   0  100844  34440   1292 S  10.0  0.2   1:35.22 nginx
 5622 api       20   0  559804  32432   8628 D  10.0  0.2   1:24.14 php-fpm
 6068 api       20   0  548908  21052   8576 S  10.0  0.1   0:04.74 php-fpm
 6454 api       20   0  544720  14384   5768 S  10.0  0.1   0:05.28 php-fpm
 7510 api       20   0  552488  24252   7964 S  10.0  0.2   0:08.79 php-fpm
11362 api       20   0  562160  34772   8628 D  10.0  0.2   2:03.26 php-fpm
16673 api       20   0  545232  14816   5772 S  10.0  0.1   0:09.19 php-fpm
24753 api       20   0  555020  26936   8064 S  10.0  0.2   0:37.86 php-fpm
31244 api       20   0  547876  17344   5780 S  10.0  0.1   2:11.62 php-fpm
  551 api       20   0  546016  15628   5772 R   5.0  0.1   0:16.45 php-fpm
 2157 api       20   0  552384  24776   8616 D   5.0  0.2   0:30.72 php-fpm
 2381 api       20   0  555740  27644   8012 S   5.0  0.2   0:26.68 php-fpm
 3575 api       20   0  554460  26240   8016 R   5.0  0.2   1:22.41 php-fpm
 3654 api       20   0  558540  30544   8032 D   5.0  0.2   0:51.10 php-fpm
 4545 api       20   0  546768  16284   5768 R   5.0  0.1   0:22.35 php-fpm
 4695 api       20   0  548148  19868   8016 S   5.0  0.1   0:28.25 php-fpm
 5722 api       20   0  552128  23980   7968 S   5.0  0.1   0:44.46 php-fpm
 6732 api       20   0  557020  29488   8628 S   5.0  0.2   0:24.95 php-fpm
 7242 api       20   0  546500  15896   5452 R   5.0  0.1   0:21.96 php-fpm
 7279 api       20   0  545248  16880   7972 S   5.0  0.1   0:08.13 php-fpm
 7548 api       20   0  559324  31192   8016 S   5.0  0.2   1:42.25 php-fpm
 7605 api       20   0  565016  37444   8668 S   5.0  0.2   0:59.67 php-fpm
 8402 api       20   0  561868  33696   8024 D   5.0  0.2   0:40.36 php-fpm
 8647 api       20   0  561852  34276   8632 R   5.0  0.2   1:07.91 php-fpm
 8855 api       20   0  554024  26404   8580 S   5.0  0.2   0:14.91 php-fpm
 9301 api       20   0  548136  19948   7968 S   5.0  0.1   0:16.27 php-fpm
 9540 api       20   0  546512  15992   5768 R   5.0  0.1   0:20.05 php-fpm
 9544 api       20   0  555724  27484   8012 D   5.0  0.2   0:20.87 php-fpm
11476 api       20   0  563900  36472   8636 R   5.0  0.2   1:34.43 php-fpm
11644 api       20   0  548284  20164   8028 R   5.0  0.1   0:40.70 php-fpm

--------------------------------------------------------------------------


--------------------------------------------------------------------------

Intel(R) Core(TM) i5-3550 CPU @ 3.30GHz
Intel(R) Core(TM) i5-3550 CPU @ 3.30GHz
Intel(R) Core(TM) i5-3550 CPU @ 3.30GHz
Intel(R) Core(TM) i5-3550 CPU @ 3.30GHz

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                4
On-line CPU(s) list:   0-3
Thread(s) per core:    1
Core(s) per socket:    4
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 58
Model name:            Intel(R) Core(TM) i5-3550 CPU @ 3.30GHz
Stepping:              9
CPU MHz:               3499.933
BogoMIPS:              6600.56
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              6144K
NUMA node0 CPU(s):     0-3

The message also shows: 216475720c4f4a9aa5a31c2900800af4.png
Please help, because there should not be such a load at all, Centos 7.3.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
B
Boris Korobkov, 2017-06-14
@BorisKorobkov

Throw out PHP, give the audio file using Nginx.

A
Alexander N++, 2017-06-14
@sanchezzzhak

If you send a file through php, then it's better to rewrite it, for example, give a link from php through
X-Accel-Redirect Let's
say the user requests a picture along this path to your php script
/get/mp3/1
in our code, parse the parameters and substitute them in the header real path to the file.

<?php
header('X-Accel-Redirect: /protected/1.mp3');

https://www.nginx.com/resources/wiki/start/topics/...

P
pavel zomrad, 2018-03-08
@zomradPRO

it is best to throw out PHP and give the audio file using Nginx, you can also try to rewrite it, for example, give a link from php through X-Accel-Redirect

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question