0

I runnnig Moodle on Lighttpd on Centos 6 with 1G RAM. If I open 10 threads to moodle then moodle starting to be very slow.

How I can to speed the server? I need to serve lot of users.

I checked the memory with free command ande I have lot of free memory.

EDIT: I can to see high CPU of php-cgi.

top:

# top -b -n 1 | head -30
top - 08:55:32 up 24 days, 21:37,  2 users,  load average: 0.70, 0.24,
 0.08
Tasks: 153 total,   2 running, 151 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.2%us,  0.3%sy,  0.0%ni, 99.4%id,  0.0%wa,  0.0%hi,  0.0%si,
0.1%st
Mem:   1016480k total,   828692k used,   187788k free,   151316k buffers
Swap:   999992k total,     4036k used,   995956k free,   426880k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
29247 lighttpd  20   0  477m 103m  61m R 92.1 10.4   1:37.25 php-cgi
23947 root      20   0 15020 1188  864 R  3.6  0.1   0:00.03 top
    1 root      20   0 19228 1040  860 S  0.0  0.1   0:00.61 init
    2 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthreadd
    3 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0
    4 root      20   0     0    0    0 S  0.0  0.0   0:05.49 ksoftirqd/0
    5 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0
    6 root      RT   0     0    0    0 S  0.0  0.0   0:08.99 watchdog/0
    7 root      20   0     0    0    0 S  0.0  0.0   4:35.86 events/0
    8 root      20   0     0    0    0 S  0.0  0.0   0:00.00 cgroup
    9 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khelper
   10 root      20   0     0    0    0 S  0.0  0.0   0:00.00 netns
   11 root      20   0     0    0    0 S  0.0  0.0   0:00.00 async/mgr
   12 root      20   0     0    0    0 S  0.0  0.0   0:00.00 pm
   13 root      20   0     0    0    0 S  0.0  0.0   0:00.00 xenwatch
   14 root      20   0     0    0    0 S  0.0  0.0   6:02.87 xenbus
   15 root      20   0     0    0    0 S  0.0  0.0   0:21.59 sync_supers
   16 root      20   0     0    0    0 S  0.0  0.0   0:18.66 bdi-default
   17 root      20   0     0    0    0 S  0.0  0.0   0:00.00
kintegrityd/0
   18 root      20   0     0    0    0 S  0.0  0.0   0:13.23 kblockd/0
   19 root      20   0     0    0    0 S  0.0  0.0   0:00.00 ata/0
   20 root      20   0     0    0    0 S  0.0  0.0   0:00.00 ata_aux
   21 root      20   0     0    0    0 S  0.0  0.0   0:00.00
ksuspend_usbd

free:

# free -m
         total       used       free     shared    buffers     cached
Mem:           992        809        183          0        147        416
-/+ buffers/cache:        244        748
Swap:          976          3        972

cat /proc/cpuinfo:

processor   : 0
vendor_id   : AuthenticAMD
cpu family  : 16
model               : 4
model name  : Quad-Core AMD Opteron(tm) Processor 2374 HE
stepping    : 2
cpu MHz             : 2200.130
cache size  : 512 KB
fpu         : yes
fpu_exception       : yes
cpuid level : 5
wp          : yes
flags               : fpu de tsc msr pae cx8 cmov pat clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt lm 3dnowext
3dnow up rep_good unfair_spinlock pni cx16 popcnt hypervisor lahf_lm cmp_legacy extapic cr8_legacy abm sse4a misalignsse
3dnowprefetch
bogomips    : 4400.26
TLB size    : 1024 4K pages
clflush size        : 64
cache_alignment     : 64
address sizes       : 48 bits physical, 48 bits virtual
power management:
3
  • Check top also. It may help if you post the output of free as well. Commented Jun 16, 2013 at 7:57
  • Paste into the question, the output from free, uptime and cat /proc/cpuinfo. Commented Jun 16, 2013 at 8:46
  • Links to the configuration of your Lighthttpd and php-cgi would be useful (gist, paste bin, etc) Commented Jul 25, 2013 at 3:18

2 Answers 2

1

While your single php-cgi thread is high, the system load is not; You are only pegging one of the cores of your processor. Your box appears to have plenty of room to grow, you just need to adjust the configuration Lighttpd and PHP-CGI to get the scale you need.

The initial problem is that you are sending all the request to a single php-cgi thread. So you are utilizing the the other 3 cores of your box. Instead of using php-cgi, I'd suggest running PHP-FPM, which will listen to a single socket or port; and will load balance the request to the number of worker threads that you define. If this box is also performing MySQL or other tasks you might want to only scale it out to leave one core empty for other processing needs.

The other thing to look at is what you are actually testing. When you say 10 threads - what are you actually talking about. When I here 10 threads, I would assume you have a 10 processes that are making as many calls to the server as they can (JMeter) This could lead to 10 req/sec or it could lead to 50 req/sec. The other question is, is each thread also loading all the resources in the html request, or it is just the HTML.

There are a lot of tutorials on Google on configuring PHP-FPM and Lighttpd, here is a quick one I pulled from the top of a google search - http://www.howtoforge.com/installing-lighttpd-with-php5-php-fpm-and-mysql-support-on-ubuntu-12.04

Based on what I'm seeing; you should be able to achieve 3-4x the connections once you get Lighttpd and PHP configured to use all your cores.

1
  • Note, that ywarnier post is still 100% valid. And I highly recommend using PHP APC Caching (or the new Zend Opcode if you are on PHP-5.5) Commented Jul 25, 2013 at 3:17
0

The CPU usage for php-cgi is effectively quite high. The slowliness of your server can usually be bound to two things: CPU or I/Os.

I/Os (if a hindrance) are seen through the %wa (wait) indicator, and might be caused by lack of memory and swapping (which puts memory on disk and then slows down everything). It is generally a good idea for web servers where the stability is not absolutely critical (as is the case usually with web pages: if it doesn't work, just refresh) to remove the swap completely with the command (as root)

swapoff -a

If your CPU usage is high and it comes from PHP, but the %wa is low, then you are definitely hitting a performance issue bound to the execution of PHP code (by opposition to SQL queries, for example). The best way to avoid that is to try and use opcode caching (like APC or the Zend opcode cache that comes shipped in with PHP 5.5). Opcode cache effectively uses a little memory but avoids a lot of computing (it puts pre-compiled versions of your PHP scripts in memory so loading them twice - or ten times - only "computes" them once).

This being said, Moodle is not the best LMS around if you are looking at running it on a low CPU, low memory "server".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .