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,
http://careers.directi.com/display/tu/Understanding+and+optimizing+Memory+utilization
"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 ac_memory_avg.sh
#!/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)
do
    cat /proc/$i/status | grep "VmHWM" | awk '{print $2}' >> /tmp/avg_cal.txt
done

#!/usr/bin/env ruby
f="/tmp/avg_cal.txt"
sum=0
size=File.readlines(f).size
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
./ac_memory_avg.sh
./ac_memory_avg.rb

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

php5-fpm consums lots of cpu resources relatively less memory.




#Funkload Test(google.com search funkload. It is free opensource load test tool. Not 99% perfect, but it is very good for testing web-based graphic result conveniently).

#My script as follows. It is for wordpress login.php(wp-login.php)
#To test, I had to mv xmlrpc.php to another directory, not harmful for testing.
#And backing up to where it is,not a problem. Also, I had edit cookie.py to disable error message. Also not affecting on load-test.

#This result is based on virtualbox vm.(cpu 2,memory:1024)



whatsup@whatsup-To-be-filled-by-O-E-M ~/funkload-demo/wp $ cat test_WpLogin.py
# -*- coding: iso-8859-15 -*-
"""wp_login FunkLoad test

$Id: $
"""
import unittest
from funkload.FunkLoadTestCase import FunkLoadTestCase
from webunit.utility import Upload
from funkload.utils import Data
#from funkload.utils import xmlrpc_get_credential

class WpLogin(FunkLoadTestCase):
    """XXX

    This test use a configuration file WpLogin.conf.
    """

    def setUp(self):
        """Setting up test."""
        self.logd("setUp")
        self.server_url = self.conf_get('main', 'url')
        # XXX here you can setup the credential access like this
        # credential_host = self.conf_get('credential', 'host')
        # credential_port = self.conf_getInt('credential', 'port')
        # self.login, self.password = xmlrpc_get_credential(credential_host,
        #                                                   credential_port,
        # XXX replace with a valid group
        #                                                   'members')

    def test_wp_login(self):
        # The description should be set in the configuration file
        server_url = self.server_url
        # begin of test ---------------------------------------------

        # /tmp/tmp97AwZf_funkload/watch0001.request
        self.get(server_url + "/wordpress/wp-login.php/",
            description="Get /wordpress/wp-login.php/")
        # /tmp/tmp97AwZf_funkload/watch0005.request
        self.post(server_url + "/wordpress/wp-login.php", params=[
            ['log', 'OYJ'],
            ['pwd', 'password'],
            ['wp-submit', 'Log In'],
            ['redirect_to', 'http://10.0.0.21/wordpress/wp-login.php'],
            ['testcookie', '1']],
            description="Post /wordpress/wp-login.php")
        # /tmp/tmp97AwZf_funkload/watch0011.request
        #self.get("http://2.gravatar.com/avatar/5ceb3152443edc6580e552b390a30d83?s=26&d=mm&r=g",
            #description="Get /avatar/5ceb3152443edc6580e552b390a30d83")
        # /tmp/tmp97AwZf_funkload/watch0012.request
        #self.get("http://2.gravatar.com/avatar/5ceb3152443edc6580e552b390a30d83?s=64&d=mm&r=g",
            #description="Get /avatar/5ceb3152443edc6580e552b390a30d83")

        # end of test -----------------------------------------------

    def tearDown(self):
        """Setting up test."""
        self.logd("tearDown.\n")

if __name__ in ('main', '__main__'):

    unittest.main()

#Not test start, I will show top result of php-fpm.
#It connect concurrent user 30,50,70 each for 30seconds


whatsup@whatsup-To-be-filled-by-O-E-M ~/funkload-demo/wp $ fl-run-bench -c 30:50:70 -D 30 test_WpLogin.py WpLogin.test_wp_login

========================================================================
Benching WpLogin.test_wp_login
========================================================================
Wordpress Apm Test on Linux Ubuntu 14.04
------------------------------------------------------------------------

Configuration
=============

* Current time: 2015-05-01T05:56:31.488849
* Configuration file: /home/whatsup/funkload-demo/wp/WpLogin.conf
* Log xml: /home/whatsup/funkload-demo/wp/wp_login-bench.xml
* Server: http://10.0.0.21
* Cycles: [100, 200, 250, 300]
* Cycle duration: 300s
* Sleeptime between request: from 0.0s to 2.0s
* Sleeptime between test case: 1.0s
* Startup delay between thread: 0.2s

Benching
========

* setUpBench hook: ... done.

Cycle #0 with 100 virtual users
-------------------------------

* setUpCycle hook: ... done.
* Current time: 2015-05-01T05:56:31.492174
========================================================================
Benching WpLogin.test_wp_login
========================================================================
Wordpress Apm Test on Linux Ubuntu 14.04
------------------------------------------------------------------------

Configuration
=============

* Current time: 2015-05-01T06:47:53.805307
* Configuration file: /home/whatsup/funkload-demo/wp/WpLogin.conf
* Log xml: /home/whatsup/funkload-demo/wp/wp_login-bench.xml
* Server: http://10.0.0.21
* Cycles: [30, 50, 70]
* Cycle duration: 30s
* Sleeptime between request: from 0.0s to 2.0s
* Sleeptime between test case: 1.0s
* Startup delay between thread: 0.2s

Benching
========

* setUpBench hook: ... done.

Cycle #0 with 30 virtual users
------------------------------

* setUpCycle hook: ... done.
* Current time: 2015-05-01T06:47:53.808304
* Starting threads: .............................. done.
* Logging for 30s (until 2015-05-01T06:48:29.859197): ......................................................................................................................... done.
* Waiting end of threads: .............................. done.
* Waiting cycle sleeptime 1s: ... done.
* tearDownCycle hook: ... done.
* End of cycle, 44.09s elapsed.
* Cycle result: **SUCCESSFUL**, 121 success, 0 failure, 0 errors.

Cycle #1 with 50 virtual users
------------------------------

* setUpCycle hook: ... done.
* Current time: 2015-05-01T06:48:37.903268
* Starting threads: .................................................. done.
* Logging for 30s (until 2015-05-01T06:49:17.990075): ............................................................................................................................ done.
* Waiting end of threads: .................................................. done.
* Waiting cycle sleeptime 1s: ... done.
* tearDownCycle hook: ... done.
* End of cycle, 51.39s elapsed.
* Cycle result: **SUCCESSFUL**, 124 success, 0 failure, 0 errors.

Cycle #2 with 70 virtual users
------------------------------

* setUpCycle hook: ... done.
* Current time: 2015-05-01T06:49:29.289398
* Starting threads: ...................................................................... done.
* Logging for 30s (until 2015-05-01T06:50:13.407927): .......................................................................................................................... done.
* Waiting end of threads: ...................................................................... done.
* Waiting cycle sleeptime 1s: ... done.
* tearDownCycle hook: ... done.
* End of cycle, 59.97s elapsed.
* Cycle result: **SUCCESSFUL**, 122 success, 0 failure, 0 errors.

* tearDownBench hook: ... done.

Result
======

* Success: 367
* Failures: 0
* Errors: 0

Bench status: **SUCCESSFUL**

#Web report (html)
whatsup@whatsup-To-be-filled-by-O-E-M ~/funkload-demo/wp $ fl-build-report --html wp_login-bench.xml
Creating html report: ...done:
/home/whatsup/funkload-demo/wp/test_wp_login-20150501T064753/index.html

#cp to web root

#Browsing











 When 30 users, good, 50 users fair,,,,70 users fair


6   Slowest requests

The 5 slowest average response time during the best cycle with 30 CUs:
  • In page 002, Apdex rating: POOR, avg response time: 2.01s, post: /wordpress/wp-login.php Post /wordpress/wp-login.php
  • In page 002, Apdex rating: Good, avg response time: 1.22s, get: /wordpress/wp-login.php ``
  • In page 001, Apdex rating: Excellent, avg response time: 0.89s, get: /wordpress/wp-login.php/ Get /wordpress/wp-login.php/
  • In page 001, Apdex rating: Excellent, avg response time: 0.24s, link: /css?family=Open+Sans%3A300italic%2C400italic%2C600italic%2C300%2C400%2C600&subset=latin%2Clatin-ext&ver=4.2.1 ``
  • In page 001, Apdex rating: Excellent, avg response time: 0.00s, link: /wordpress/wp-includes/css/dashicons.min.css?ver=4.2.1 ``

 #Well, most importantly wp-login.php shows not good. Should upgrade cpu cores or distribute requests.^^;
 



 #top command result shows cpu is being exploited pretty much.

30 users.




50users


70 users