Thursday, 23 May 2013

Apache performance as well as MySQL Performance

For Apache :-


1- Prefork and worker are two type of MPM apache provides. Both have their merits and demerits.
By default mpm is prefork which is thread safe.
Prefork MPM uses multiple child processes with one thread each and each process handles one connection at a time.
Worker MPM uses multiple child processes with many threads each. Each thread handles one connection at a time.

2- Apache is the most common and famous webserver. Everyone knows about apache and most of us also have hands on experience with apache. But few of us know that apcahe2 comes with 2 multi processing modules(MPMs): 

1. Prefork
2. Worker




3. What is the difference between this two?

Prefork MPM uses multiple child processes with one thread each and each process handles one connection at a time.

Worker MPM uses multiple child processes with many threads each. Each thread handles one connection at a time.

On most of the systems, speed of both the MPMs is comparable but prefork uses more memory than worker.


Which one to use?
On high traffic websites worker is preferable because of low memory usage as comparison to worker MPM but worker is more safe if you are using libraries which are not thread safe.
For example you cannot use mod_php(not thread safe) with worker MPM but can use with prefork.
So if you are using all thread safe libraries then go with worker and if you are not sure then use default prefork MPM, you may have to increase your RAM in case of high traffic.
If you are on linux then run following command to check which MPM is on your machine
1
/usr/sbin/apache2 -V | grep MPM
for More Please review Given URL:-


Published by Arvind Saini on November 9, 2012 | Leave a response
If you have installed a new apache web server(prefork MPM), planning to launch an online application and exptecting good amount of traffic then before going live, check apache settings for prefork mpm otherwise your server will not able to serve even 20-30 users. Why, becouse apache default setting are not optimized for high traffic, you have to adjust prefork settings based on your application and hardware(RAM,Swap etc).
Before I will start explaining prefork configuration, if you are not aware of prefork mpm or how to check apache memory details then read following blogs before proceeding further:
Open your apache config file or run following command
gedit /etc/apache2/apache2.conf
Search prefork setting block, which look like this
?
1
2
3
4
5
6
7
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
</IfModule>
Above is the default settings of apache prefork mpm.
StartServers: The StartServers directive sets the number of child server processes created on startup. As the number of processes is dynamically controlled depending on the load, there is usually little reason to adjust this parameter.
MaxSpareServers: The MaxSpareServers directive sets the desired maximum number of idle child server processes. An idle process is one which is not handling a request. If there are more than MaxSpareServers idle, then the parent process will kill off the excess processes.
Tuning of this parameter should only be necessary on very busy sites. Setting this parameter to a large number is almost always a bad idea. If you are trying to set the value lower than MinSpareServer.
MinSpareServers: The MinSpareServers directive sets the desired minimum number of idle child server processes. An idle process is one which is not handling a request. If there are fewer than MinSpareServers idle, then the parent process creates new children at a maximum rate of 1 per second.
Tuning of this parameter should only be necessary on very busy sites. Setting this parameter to a large number is almost always a bad idea.
MaxClients: The MaxClients directive sets the limit on the number of simultaneous requests that will be served. Any connection attempts over the MaxClients limit will normally be queued. Once a child process is freed at the end of a different request, the connection will then be serviced.
Generally number of MaxClients=(Total RAM memory – RAM memory used for other process except Apache process) / (Memory used by Single Apache process)
MaxRequestsPerChild: The MaxRequestsPerChild directive sets the limit on the number of requests that an individual child server process will handle. After MaxRequestsPerChildrequests, the child process will die. If MaxRequestsPerChild is 0, then the process will never expire.
You can keep it high (20000-25000) but never set it to 0.
Above mentioned setting are for start purpose only. To get best optimized setting you have to analyze sever performance on different load(for that you can use jmeter) and accordingly change the settings.
You may also like


Apache performance(process) check command:-
ps aux | grep apache
cat /proc/2173/status



First, determine the PID of one of your Apache processes.
Then you can do something like this:
cat /proc/PIDHERE/status | grep VmRSS
This will yield the (current) resident-set-size of that particular process, similar to:
VmRSS: 304456 kB
This value is as it sounds, it is the size of the process resident in RAM.
Then normalize your unit of measure (4GB * 1024 * 1024 = 4,194,304 KB). Divide:
4194304 KB / 304456 KB = 13.77 processes
Consider that you probably have other processes running on your system that will consume memory too, and ideally you want to minimize swapping, therefore you would not likely want 13 Apache MaxClients configured (using my numbers), you want some amount less (at your discretion).
This is a crude estimate; the size of your Apache processes may grow over time depending on load.


Predicting the maxClients from test scenarios is a starting point - but to solve the problem properly you need to start measuring how your application is behaving with real traffic.
Assuming your apache is running pre-fork....
Set up a cron job to count the number of httpd processes and the output of 'free'. Note that if your webserver is serving up any content from local files (and in a lot of cases, even when it's not) the amount of memory available for cache/buffers will have a big impact on performance. i.e. if you get to the point of swapping, your web performance is probably horrible!
Once you've got some data, plot it on a chart and do a least squares regression on it - extrapolate to find the number of clients at which you reach your target limit for httpd memory usage. A starting point for memory target would be the lesser of 80% of the physical memory / 80% of the size of the content.
(note if you've got MinSpareServers set to a very high value, results may not be accurate)
#!/bin/bash
 
LOGFILE='/var/log/httpd/memusage'
PIDS = `ps -ef | grep httpd | grep -v grep | wc -l`
MEM = `free | grep 'buffers/cache'`
DAY = `date '%Y-%m-%d %H:%M:%S'`
echo ${DAY} ${PIDS} ${MEM} >>LOGFILE
In an ideal world, you'd also measure the URL response time in the same log file - but that's getting a lot more complex.


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------             Mysql

Using a MySQL Performance Tuning Analyzer Script

When you are working on increasing the speed of your website, a very important piece is making sure you get every last drop of performance out of your database server. Unfortunately, for most of us that aren’t normally database administrators this can be a difficult proposition.
There’s a number of performance tuning scripts that will analyze your server settings and current status and give you information on recommended changes that you should make. You shouldn’t necessarily follow all of the suggestions, but it’s worthwhile to take a look at anyway.
The script I’ve been using gives you recommendations for the following:
·  Slow Query Log
·  Max Connections
·  Worker Threads
·  Key Buffer
·  Query Cache
·  Sort Buffer
·  Joins
·  Temp Tables
·  Table (Open & Definition) Cache
·  Table Locking
·  Table Scans (read_buffer)
·  Innodb Status
Once you download the script, you’ll need to make it executable with the following command:
chmod u+x tuning-primer.sh
If you run this script as a regular user, it will prompt you for your password, so you’ll have to make sure to set access accordingly. If you run it as root it’ll pick up the mysql password from Plesk if you have that installed.
I’ve cut out a lot of the output, which had a lot more recommendations, but was just too long to fit on the page.
./tuning-primer.sh
        — MYSQL PERFORMANCE TUNING PRIMER –
             – By: Matthew Montgomery –
MySQL Version 4.1.20 i686
Uptime = 5 days 10 hrs 46 min 5 sec
Avg. qps = 4
Total Questions = 2020809
Threads Connected = 1
Server has been running for over 48hrs.
It should be safe to follow these recommendations
———– snipped ————–
QUERY CACHE
Query cache is enabled
Current query_cache_size = 8 M
Current query_cache_used = 7 M
Current query_cach_limit = 1 M
Current Query cache fill ratio = 89.38 %
However, 254246 queries have been removed from the query cache due to lack of memory
Perhaps you should raise query_cache_size
MySQL won’t cache query results that are larger than query_cache_limit in size
———– snipped ————–
Looks like I need to increase my query cache… I set it to only 8MB but it’s cleaning out the cache far too often.
———– snipped ————–
TEMP TABLES
Current max_heap_table_size = 16 M
Current tmp_table_size = 32 M
Of 35170 temp tables, 74% were created on disk
Effective in-memory tmp_table_size is limited to max_heap_table_size.
Perhaps you should increase your tmp_table_size and/or max_heap_table_size
to reduce the number of disk-based temporary tables
Note! BLOB and TEXT columns are not allow in memory tables.
If you are using these columns raising these values might not impact your 
ratio of on disk temp tables.
———– snipped ————–
This type of information is just invaluable when you are trying to tune the performance of your website.















No comments:

Post a Comment