我使用1G RAM在Centos 6上的Lighttpd上运行Moodle。 如果我打开10个线程给moodle,那么moodle开始很慢。
我怎样才能加快服务器? 我需要为很多用户服务。
我用free命令检查了内存并且有很多空闲的内存。
编辑:我可以看到php-cgi高CPU。
最佳:
# 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 -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:
虽然你的单个php-cgi线程很高,但系统负载不是; 你只是挂钩你的处理器的核心之一。 你的盒子似乎有很大的增长空间,你只需要调整configurationLighttpd和PHP-CGI来获得你需要的规模。
最初的问题是你正在发送所有的请求到一个单一的php-cgi线程。 所以你正在利用你的盒子的其他3个核心。 而不是使用php-cgi,我build议运行PHP-FPM,它将监听单个套接字或端口; 并会将请求负载平衡到您定义的工作线程数。 如果这个盒子也在执行MySQL或者其他任务,你可能只想扩展一个内核以满足其他处理需求。
另一个要看的是你正在testing的东西。 当你说10个线程 – 你在说什么。 当我在这里10个线程,我会假设你有10个进程,尽可能多的调用服务器,他们可以(JMeter)这可能会导致10 req /秒或可能导致50 req /秒。 另一个问题是,每个线程是否也加载了html请求中的所有资源,或者它只是HTML。
在Google上有很多关于configurationPHP-FPM和Lighttpd的教程,这里是我从谷歌search的顶部取得的一个快速的教程 – http://www.howtoforge.com/installing-lighttpd-with-php5-php -fpm和MySQL的支持上,Ubuntu的12.04
根据我所看到的; 一旦您将Lighttpd和PHPconfiguration为使用您的所有内核,您应该能够实现3-4倍的连接。
php-cgi的CPU使用率非常高。 通常可以将服务器的速度限制在两个方面:CPU或I / O。
通过%wa(等待)指示灯看到I / O(如果有障碍),可能是由于内存不足和交换(将内存放在磁盘上,然后放慢了一切)而导致的。 对于稳定性不是绝对关键的Web服务器来说,一般来说这是一个好主意(网页通常情况下是这样的:如果不起作用,只需刷新)就可以使用命令完全删除交换(以root用户身份)
swapoff -a
如果您的CPU使用率很高,而且来自PHP,但是%wa很低,那么您肯定会遇到一个绑定到PHP代码执行的性能问题(例如,与SQL查询相反)。 避免这种情况的最好方法是尝试使用操作码caching(如APC或PHP 5.5附带的Zend操作码caching)。 操作码caching有效地使用了一点内存,但避免了大量的计算(它把你的PHP脚本的预编译版本放在内存中,所以加载它们两次 – 或者十次 – 只“计算”它们一次)。
这就是说,如果你正在考虑在低CPU,低内存“服务器”上运行它,Moodle并不是最好的LMS。