How to use more than one core in apache?

Marcus

Well-known member
I wrote a small script to measure performance on my server and it looks like only one core is used. Do you have an idea how to tell apache to also use the other cores?

Code:
#!/bin/bash
 
for ((i=1; $i<=100000; i++)); do
  wget --no-cache --spider http://domain.com/threads/$i/
done
 
exit

Code:
top - 19:52:03 up 3 days, 2:14, 3 users, load average: 0.77, 0.77, 0.68
Tasks: 298 total, 3 running, 295 sleeping, 0 stopped, 0 zombie
Cpu0 : 34.0%us, 10.4%sy, 0.0%ni, 39.4%id, 16.2%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu1 : 25.6%us, 8.6%sy, 0.0%ni, 51.8%id, 14.0%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu2 : 8.6%us, 2.3%sy, 0.0%ni, 88.7%id, 0.3%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu3 : 2.7%us, 3.0%sy, 0.0%ni, 80.3%id, 14.0%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu4 : 0.0%us, 0.0%sy, 0.0%ni, 99.7%id, 0.0%wa, 0.0%hi, 0.3%si, 0.0%st
Cpu5 : 2.6%us, 13.2%sy, 0.0%ni, 84.1%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu6 : 2.0%us, 0.3%sy, 0.0%ni, 97.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu7 : 1.7%us, 4.3%sy, 0.0%ni, 94.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu8 : 3.0%us, 0.0%sy, 0.0%ni, 97.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu9 : 1.3%us, 2.0%sy, 0.0%ni, 96.7%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu10 : 0.0%us, 0.0%sy, 0.0%ni, 99.7%id, 0.3%wa, 0.0%hi, 0.0%si, 0.0%st
Cpu11 : 0.7%us, 1.3%sy, 0.0%ni, 98.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 65379420k total, 41652240k used, 23727180k free, 184844k buffers
Swap: 33554352k total, 0k used, 33554352k free, 37154256k cached
 
any reason why apache should use more than one core when it's mostly bored with few requests? Would be completely unefficient, especially with hyperthreading (caching).
Give more load to the server with ab and apache will take more cores if needed.
 
I massively attacked my server to display all threads in my forum at once. You can see the same effect with ab.
 
Real-world performance can be a lot different than a benchmark. IMO use nginx if you are concerned about performance. Having said that, I haven't used Apache in years, but I would think it should leverage multiple cores out of the box...

Edit: also, if you are testing this on a PHP page it could be down to your configuration there. PHP-FPM will take advantage of multiple cores, just make sure to create enough workers.
 
Quite simple
  1. apache is multi-threaded but will only use as many cores as the app allows for
  2. wget is single threaded app so only utilises 1 cpu core at most
  3. if you want multi threaded download tool equivalent to wget, then look at axel accelerator which grabs/downloads files by default at the same number of concurrent threads as your cpu supports.
If you want to benchmark apps like xenforo, use
  1. apachebench
  2. siege benchmark
  3. httpperf
or online services such as
  1. blitz.io
  2. loadimpact.com
 
Top Bottom