2

I have a cloud server, with: 5120 RAM and 4.6Ghz

My question is: if I add more CPU, (11.5 Ghz) will the load time of the pages be higher? I mean, is this always gradual? More CPU = faster pageload? And if not, how does it work and how can I learn more about this?

UPDATE: Symcbean's answer was very clear. But there is still something I don't understand (and what I find on Google, more people don't) I've tried to put it in a metafore:
Let's say I've got a bucket with water (the bucket with water = the PHP process, with caching etc) I want to empty the bucket into a funnel. (the end of the funnel = server speed, how bigger the end of the funnel, the faster the water runs through it)
If I have a funnel-end of 0.5 inch, it goes through slow. If I have one of 1 inch it goes faster. But if the funnel-end is (let's say) 10 inch, it doesn't matter if I have 10 inch or 20 inch, the water goes through it at the same speed.
So with this metafore I mean; how do I know I'm using 100% of the capacity and how do I know that I don't need more...?

PS: I would really appreciate it if somebody could explain, what the max is, and how this actually works or how I can find this out?

PPS: this is the output when I run 'top'

top - 23:06:18 up 54 days, 6:08, 1 user, load average: 0.51, 0.43, 0.47 Tasks: 107 total, 2 running, 105 sleeping, 0 stopped, 0 zombie Cpu(s): 28.1%us, 1.5%sy, 0.0%ni, 70.2%id, 0.0%wa, 0.0%hi, 0.0%si, 0.2%st Mem: 4966748k total, 4493968k used, 472780k free, 241436k buffers Swap: 4194300k total, 123252k used, 4071048k free, 2836028k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 16432 root 20 0 1115m 283m 30m R 95 5.8 1:11.39 php 16422 www-data 20 0 927m 45m 21m S 18 0.9 0:00.53 apache2 20270 mysql 20 0 2327m 330m 5500 S 7 6.8 474:19.11 mysqld 617 n2 20 0 14268 1140 488 S 1 0.0 182:58.64 n2txd 30212 root 20 0 0 0 0 S 1 0.0 24:50.48 flush-202:1 26848 root 20 0 99424 1108 856 S 0 0.0 2:47.63 sendmail-mta 1 root 20 0 24188 1556 872 S 0 0.0 0:09.09 init 2 root 20 0 0 0 0 S 0 0.0 0:00.00 kthreadd 3 root 20 0 0 0 0 S 0 0.0 0:48.36 ksoftirqd/0 4 root 20 0 0 0 0 S 0 0.0 1:27.21 kworker/0:0 5 root 20 0 0 0 0 S 0 0.0 0:00.05 kworker/u:0 6 root RT 0 0 0 0 S 0 0.0 0:00.00 migration/0 7 root RT 0 0 0 0 S 0 0.0 0:26.69 watchdog/0 8 root RT 0 0 0 0 S 0 0.0 21841:40 migration/1 9 root 20 0 0 0 0 S 0 0.0 0:00.00 kworker/1:0 10 root 20 0 0 0 0 S 0 0.0 0:56.84 ksoftirqd/1 11 root RT 0 0 0 0 S 0 0.0 0:23.78 watchdog/1 12 root RT 0 0 0 0 S 0 0.0 0:00.00 migration/2 13 root 20 0 0 0 0 S 0 0.0 0:00.00 kworker/2:0 14 root 20 0 0 0 0 S 0 0.0 0:48.05 ksoftirqd/2 15 root RT 0 0 0 0 S 0 0.0 0:19.11 watchdog/2 16 root RT 0 0 0 0 S 0 0.0 0:00.00 migration/3 17 root 20 0 0 0 0 S 0 0.0 0:00.00 kworker/3:0 18 root 20 0 0 0 0 S 0 0.0 0:40.08 ksoftirqd/3 19 root RT 0 0 0 0 S 0 0.0 0:19.24 watchdog/3 20 root 0 -20 0 0 0 S 0 0.0 0:00.00 cpuset 21 root 0 -20 0 0 0 S 0 0.0 0:00.00 khelper 22 root 20 0 0 0 0 S 0 0.0 0:00.00 kdevtmpfs 23 root 0 -20 0 0 0 S 0 0.0 0:00.00 netns 24 root 20 0 0 0 0 S 0 0.0 0:00.00 kworker/u:1 25 root 20 0 0 0 0 S 0 0.0 0:00.00 xenwatch 26 root 20 0 0 0 0 S 0 0.0 0:00.00 xenbus 27 root 20 0 0 0 0 S 0 0.0 0:22.29 sync_supers 28 root 20 0 0 0 0 S 0 0.0 0:00.42 bdi-default 29 root 0 -20 0 0 0 S 0 0.0 0:00.00 kintegrityd 30 root 0 -20 0 0 0 S 0 0.0 0:00.00 kblockd 31 root 20 0 0 0 0 S 0 0.0 1:57.23 kworker/2:1 32 root 0 -20 0 0 0 S 0 0.0 0:00.00 ata_sff 33 root 20 0 0 0 0 S 0 0.0 0:00.00 khubd 34 root 0 -20 0 0 0 S 0 0.0 0:00.00 md 36 root 20 0 0 0 0 S 0 0.0 0:01.45 khungtaskd 37 root 20 0 0 0 0 S 0 0.0 0:29.28 kswapd0 38 root 25 5 0 0 0 S 0 0.0 0:00.00 ksmd 39 root 20 0 0 0 0 S 0 0.0 0:00.00 fsnotify_mark 40 root 20 0 0 0 0 S 0 0.0 0:00.00 ecryptfs-kthrea 41 root 0 -20 0 0 0 S 0 0.0 0:00.00 crypto 49 root 0 -20 0 0 0 S 0 0.0 0:00.00 kthrotld 50 root 20 0 0 0 0 S 0 0.0 0:00.00 khvcd 51 root 20 0 0 0 0 S 0 0.0 1:19.07 kworker/3:1 70 root 0 -20 0 0 0 S 0 0.0 0:00.00 devfreq_wq 71 root 20 0 0 0 0 S 0 0.0 1:03.05 kworker/0:1 190 root 20 0 0 0 0 S 0 0.0 1:31.64 kworker/1:1 193 root 20 0 0 0 0 S 0 0.0 2:52.19 jbd2/xvda1-8 

2 Answers 2

3

Not sure where Shane sees 4 cpus in your top output. Certainly there's more than one. However your load average shows that never using more than half of your CPUs. Hence adding more CPUs isn't going to make it any faster.

Page response time is very much removed from PHP execution time. Typically the page load time will be in the region of 6-10 times the length of time to generate the HTML (assuming that the PHP is relatively efficient) - the difference is mostly due to stuff happenning at the network tier and o the browser. Tools like yslow and webpagetest will help with improving front end performance. I'd recommend getting a good book on the topic - like this one. There's a lot of good posts abut web performance here and about MySQL performance here.

Things like top, load average, cpu usage, free, vmstat et al, are good for telling you how your serverside performance is constrained - but as above this should only be a very small part of the story of the page lifecycle. From the snapshot you've provided, the hardware isn't overly taxed (there might be an I/O bottleneck but that's hard to see from these metrics).

If you have reason to suspect that your PHP code is rather slow then start logging and analysing your request data. How long do your PHP requests take to generate? What is your page load time?

One thing that does stand out from the top output you've shown is that there is only a single instance of PHP visible and a single instance of Apache. How is Apache configured? Which MPM? How does it connect to PHP? If you're using CGI, then you should get big improvements by switching to PHP-fpm or mod_php. Are you using an opcode cache?

Your mysqld has clocked up rather a lot of CPU cycles - you might want to start analysing your query log and tuning that. Try running mysqltuner against your instance.

I realise I'm asking a lot of questions here, but the solution to 'how to make my website go faster' would fill a very large book. It would take me about 2 days of work to get a server properly instrumented to capture the data to fully analyse it's performance - and at least 5 days to carry out the analysis - and that's before starting to find solutions to the problems - i.e. you're unlikely to get a specific answer here on Stack Overflow (I'm just trying to point you in the direction of asking the right questions).

2
  • Thanks for this very clear answer. But there still is something I don't understand. I've tried to explain it (see the update in the original post) under update Commented Jan 6, 2013 at 23:27
  • If you want to know the capacity of your server then you need to test it. This is rather complicated since you need to allow for different bandwidth / latency / packet loss on any simulated network connections and for the typical state of the client network stack (CWND, ssthresh) browser cache, along with the processing capacity of the browser (how quickly it can sink the data, generate related requests) Commented Jan 6, 2013 at 23:36
3

Looks like PHP is your CPU bottleneck, not Apache.

You seem to have 4 CPU cores, but the PHP process is only running on one of them; depending on how you have things configured, PHP may not be using all of the available CPU cores for different requests. At the time the load was in that state, how many requests were being handled?

If PHP's only running a single thread, you need to get it configured to run different requests on different cores to utilize your existing capacity.

If PHP's just executing a single request at that time, and that request is still returning too slowly, then more cores won't help, and you'll need to do some optimization and caching.

2
  • Thanks for the answer! Could you help me maybe by pointing me in the right direction on how to configure php to run on multiple cores (for example, how should it show up when I run 'top') When I google on this topic, I find a lot, but not an explanation on how to configure PHP. Commented Jan 6, 2013 at 22:44
  • I would also like to know how to configure PHP for most efficient usage of multiple cores. Any links would be appreciated. Thanks! Commented Mar 19, 2013 at 3:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.