Thursday, April 30, 2015

#Calulation of Maximum process number(Apache mpm_event)

#Calulation of Maximum process number(Apache mpm_event)

1. Memory size per process.
Let's suppose we are running LAMP 1024Megabytes server.
I want to allocate 300 Megabytes on apache2.4.(cause of mysql server).
We have to inspect size of memory per apache process.

According to proc man page, "VmPeak: Peak virtual memory size" and below address,
"VmPeak: Peak virtual memory size" means, "Note that the VmHWM parameter is interesting inasmuch as it signifies the amount of physical memory required for the process at peak times.".

So, I want to calculate avg memory size per apache process with ruby and bash.

vagrant@apm1:~$ cat
#!/usr/bin/env bash
#apache processes pid to /tmp/temp.txt
ps -ef | grep apache | grep "www-data" | awk -F " " '{print $2}' > /tmp/temp.txt
#Total process count
n=$(cat /tmp/temp.txt | wc -l)

rm -f /tmp/avg_cal.txt

for i in $(cat /tmp/temp.txt)
    cat /proc/$i/status | grep "VmHWM" | awk '{print $2}' >> /tmp/avg_cal.txt

#!/usr/bin/env ruby
File.readlines("/tmp/avg_cal.txt").collect { |line| sum += line.to_i;}

puts "Average memory size of apache process is #{sum/size}"

#Available memory 300MB,(300*1024)/(sum/size)#
puts "Maximum process number would be #{(300*1024)/(sum/size)} on 300MB Linux apache server"

vagrant@apm1:~$ cat as
#!/usr/bin/env bash

vagrant@apm1:~$ chmod 700 as ac_memory_avg.*
vagrant@apm1:~$ ./as
Average memory size of apache process is 7002
Maxmum process number would be 43 on 300MB left Linux apache server

#Obtaining apache thread count.
root@apm1:/etc/apache2/mods-enabled# ps -eLf  | grep apache | grep www-data | wc -l

No comments:

Post a Comment