So I am describing the ways to use for optimization of your database (MySql):
1. Benchmarking
2. Profiling
1. Benchmarking: - It make simple performance comparisons, Determine load limits, Test your application’s ability to deal with change. here are following benchmarking tools that are available:
- Mysql Benchmarking suite
- Mysql super smack
- MyBench
- ApacheBench ( It comes installed on almost any Unix/Linux distribution with the Apache web server installed, to use it you have to run following command like: > ab -n 100 -c 10 http://127.0.0.1/finduser1.php where 100 is the total no of connections and 10 the total concurrent requsts send at a time. )
- Httperf
2. Profiling: This enable you to procure information about - memory consumption, response times, locking, process counts from the engines that execute your SQL scripts and application code. There are a lot of profiling tools are available:
- The SHOW FULL PROCESSLIST and SHOW STATUS command ( SHOW FULL PROCESSLIST example: mysql> SHOW FULL PROCESSLIST; run this command and then see the result. SHOW STATUS Command Example:
mysql> SHOW STATUS LIKE 'Qcache%';) - The EXPLAIN command (Run Query with using EXPLAIN Command, it will give you the whole process of a query such as which column is used as index and how many rows are coming as a result and type of query.)
- SLOW QUERY and GENERAL QUERY LOG (This you can use by adding some lines in your mysql conf file (my.cnf): log-slow-queries = /var/log/mysql/mysql-slow.log long_query_time = 1 here /var/log/mysql/mysql-slow.log is the path of your log file by default this will create a file at /var/lib/mysql with a suffix of -slow.log and long_query_time is the time which is the longest time a query can take and its lowest value is 1 and DEFAULT value is 10)
- MyTop (It summarizes the SHOW FULL PROCESSLIST and various SHOW STATUS statements. Practicallu used it, its a good tool for profiling, but you need to install it from http://www.cpan.org/modules/by-module/Term/ )
- The Zend Advanced PHP Debugger extension (APD) - It is very good Profiling tool for profiling PHP as it does function call traces for your pages, memory consumption, execution time etc.
I also used indexing for the tables in which SELECT queries were more called more that INSERT, UPDATE or DELETE. (I suggest to use index for a table for only that column which is called many time in WHERE clause of query and also make indexing for a single column when you are using AB so that you will get to know easily for which column index your query processing time is lower.)
I also suggest to INSERT or SELECT data in BUNDLE. (So that less data base hit will occur)
2 comments:
Try commenting on normalization... anyways a good article
Amit
amitsoni@microsoft.com
Yes Sumesh, You can do many things like:
1. avoid left join as much possible, use mostly inner join.
2. use Union in place of left join, although it will make query 2 but the over all load will be less than the whole one query process.
3. Use 'IN' in place of AND, OR. this increase query performance.
4. If you are giving more than one join in a query then the process of query process is: query parsing, then it optimize through paranthesis algo that which join it should do first, so you can do it manually and give proper straight join in place of (A join B join C). some time it will make ur query time greater if the manual manipulation is not right.
5. Use mostly this syntax
"A JOin B ON AND n.cid='1' " in place of "A JOin B ON n.cid=n1.cid AND n.cid='1' ". If you can.
6. make temporary database table whereever the data is used many times and table is too haeavy. and cnaged that temporary data when data in parent table is updated or inserted.
7. Use TRUNCATE(or Drop) + INSERT in place of UPDATE.
8. Use slow query log to know which queries are taking time.
9. Use Apache Bench to know the concurrency level of any static page. It will help you a lot.
so if you need any more help, can contact me any time. :)
Post a Comment