Drupal: .htaccess Access Deny
August 21, 2014 – 7:59 am | No Comment

In this article I will tell how to forbid access to certain resources for some clients. The instructions will include descriptions of different directives.

Read the full story »
CSS Templates

Contain reviews and news about CSS Templates.

Freebies

Contain freebies such as icons, graphics, headers and images for your websites.

Fun Stuff

Contains other fun stuff for entertainment or interesting site showcase.

How-To

Contain technical elaborations on some specific workarounds or common tweak.

Joomla Templates

Contains reviews and news about Joomla templates.

Home » How-To

Drupal: How to Improve MySQL Database Performance

Submitted by on September 29, 2011 – 4:36 pmNo Comment

In this article, we will check parameters and configurations of database to get know how to improve its performance. Read the solution below.

Solution

To improve database performance, we should do analysis. Let’s start with simple ways to analyze database performance.

Enable full request log

Enable full log in my.cnf:

[mysqld]
log=/var/log/mysql_full.log

Standard Drupal means

Open “SQL” page in your browser
Drupal 6: admin/reports/status/sql
Drupal 5: admin/logs/status/sql

You will see three tables:

  • Commands counters – statistics of requests sent to database
  • Request performance – if some value differs from zero, you have evidently improve performance.
  • Info about cache requests – you can check if MySQL uses cache for their requests. It’s better than it does.

“tuning primer” script (Matt Mongomery)

Matt Mongomery from MySQL created a wonderful script – “tuning primer”. It is general settings for improving database performance. You can download the script here: http://www.day32.com/MySQL/
Before you run the script, MySQL database have to work at least 48 hours. This would provide the best settings offered for your database.

The scripts shows recommendations by the following questions:

  • 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

Run script

You need SSH access to the server to use this script;
Upload the script to your server
Set access rights: chmod u+x tuning-primer.sh
Run the script from a command line:  bash /path-to-script/tuning-primer.sh or sh /path-to-file/tuning-primer.sh

Example 1:

We have cut some recommendations to show them on the same 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
———– cut————–
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
———– cut————–

the code above shows that you should increase request cache. It was 8 mb but is cleared too often.

———– cut————–
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.
———– cut————–

Example 2:

[root@server1 root]# wget http://www.day32.com/MySQL/tuning-primer.sh
–20:41:15–  http://www.day32.com/MySQL/tuning-primer.sh
=> `tuning-primer.sh’
Resolving www.day32.com… 209.61.186.89
Connecting to www.day32.com|209.61.186.89|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 34,309 (34K) [application/x-sh]
100%[====================================>] 34,309        –.–K/s
20:41:15 (279.14 KB/s) – `tuning-primer.sh’ saved [34309/34309]
[root@server1 root]# bash tuning-primer.sh
— MYSQL PERFORMANCE TUNING PRIMER —
– By: Matthew Montgomery –
MySQL Version 3.23.58
Uptime = 23 days 21 hrs 28 min 54 sec
Avg. qps = 17
Total Questions = 36204146
Threads Connected = 5
Server has been running for over 48hrs.
It should be safe to follow these recommendations
To find out more information on how each of these
runtime variables effects performance visit:

http://dev.mysql.com/doc/refman/4.1/en/server-system-variables.html

SLOW QUERIES
Current long_query_time = 10 sec.
You have 526 out of 36204146 that take longer than 10 sec. to complete
The slow query log is NOT enabled.
Your long_query_time may be too high, I typically set this under 5 sec.
MAX CONNECTIONS
Current max_connections = 200
Current threads_connected = 5
Historic max_used_connections = 166
The number of used connections is 83% of the configured maximum.
Your max_connections variable seems to be fine.
WORKER THREADS
Current thread_cache_size = 0
Current threads_cached = 0
Current threads_per_sec = 1
Historic threads_per_sec = 0
Your thread_cache_size is fine
MEMORY USAGE
Max Memory Ever Allocated : 28 M
Configured Max Memory Limit : 30 M
Total System Memory : 2028 M
KEY BUFFER
Current MyISAM index space = 239 M
Current key_buffer_size = 7 M
Key cache miss rate is 1 / 126
Key buffer fill ratio = Unknown %
Your key_buffer_size seems to be fine
QUERY CACHE
You are using MySQL 3.23.58, no query cache is supported.
I recommend an upgrade to MySQL 4.0 or better
SORT OPERATIONS
Current sort_buffer_size = 2 M
Current record/read_rnd_buffer_size = 128.00 K
Sort buffer seems to be fine
JOINS
Current join_buffer_size = 128.00 K
You have had 108378 queries where a join could not use an index properly
You should enable “log-long-format”
Then look for non indexed joins in the slow query log.
If you are unable to optimize your queries you may want to increase your
join_buffer_size to accomidate larger joins in one pass.
TABLE CACHE
Current table_cache value = 64 tables
You have a total of 842 tables
You have 64 open tables.
Current table_cache hit rate is 0%, while 100% of your table cache is in use
You should probably increase your table_cache
TEMP TABLES
Current tmp_table_size = 32 M
48% of tmp tables created were disk based
Perhaps you should increase your tmp_table_size
TABLE SCANS
Current read_buffer_size = 128.00 K
Current table scan ratio = 43 : 1
read_buffer_size seems to be fine
TABLE LOCKING
Current Lock Wait ratio = 1 : 3294
You may benefit from selective use of InnoDB.
If you have long running SELECT’s against MyISAM tables and perform frequent updates consider setting ‘low_priority_updates=1′
[root@server1 root]# free -m
total       used       free     shared    buffers     cached
Mem:          1001        881        119          0         81        548
-/+ buffers/cache:        252        749
Swap:         1027         58        969

Making changes in my.cnf

  • Create a backup copy: cp -a /etc/my.cnf /etc/my.cnf.bak
  • Make your changes
  • Restart database server to enable the changes made. You can do this via control panel or command line (in some UNIX it is: /etc/rc.d/init.d/mysqld restart)
  • Run the script in a few days to make sure you didn’t miss anything.

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.