19.12.2017 Views

ADMIN+Magazine+Sample+PDF

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

MySQL Forks and Patches<br />

Features<br />

this evaluation) shows that read access<br />

to the images table is particularly<br />

frequent. The next step would be for<br />

the database user to experiment with<br />

code optimization or other changes to<br />

the table format to reduce access incidence<br />

and save time. The relatively<br />

write-intensive movies table has a<br />

suspiciously high write-access count<br />

and, at the same time, a large number<br />

of index updates.<br />

Because the statistics can be reset<br />

easily with FLUSH TABLE_STATISTICS,<br />

interval-based evaluation by means of<br />

a Munin plugin that you write yourself,<br />

or some similar method, would<br />

be your best bet. Retrospectively, you<br />

could investigate load peaks in relation<br />

to table access and modification.<br />

New Functions<br />

New functions in the MySQL kernel<br />

give administrators additional options<br />

so that maintenance of the MySQL<br />

server is more secure and convenient.<br />

A typical task is to stop MySQL<br />

processes with the KILL command.<br />

Under load, you might see a process<br />

listed as Idle by SHOW PROCESSLIST<br />

start to handle a new query just at the<br />

moment you kill it. The “Kill if Idle”<br />

patch adds an option to kill a process<br />

only if it is doing nothing: KILL IF_<br />

IDLE Process_Id. This saves you the<br />

embarrassment of accidentally killing<br />

a process while it is handling a query.<br />

LVM and ZFS snapshots are commonly<br />

regarded as the simplest<br />

methods for backing up an InnoDB<br />

database on the fly without interrupting<br />

operations. If this method is<br />

not an option for you and you are<br />

forced to rely on a legacy dump file,<br />

you need to make sure that the data<br />

on your MySQL server do not change<br />

while a file is being dumped. The<br />

legacy approach to doing this is FLUSH<br />

TABLES WITH READ LOCK. However, this<br />

might not be sufficient in the InnoDB<br />

case because background processes<br />

also write to the database. The InnoDB<br />

Freeze patch executes SET<br />

GLOBAL innodb_disallow_writes = 1<br />

and then freezes all processes that<br />

write InnoDB data so you can create<br />

a backup. Afterward, SET GLOBAL in‐<br />

nodb_disallow_writes = 0 disables<br />

the freeze.<br />

Performance Enhancements<br />

Thanks to its support for transactions<br />

and line-based locking, InnoDB has<br />

developed into a modern alternative<br />

for the now fairly ancient MyISAM<br />

engine. Despite performance gains<br />

in write access thanks to line-based<br />

locking, the overhead for supporting<br />

transactions, foreign keys, and<br />

other functions (even if you don’t<br />

use them) costs valuable CPU cycles<br />

and hardware I/​O resources. MySQL<br />

systems under heavy load thus need<br />

a perfectly configured and powerful<br />

InnoDB engine.<br />

A variety of performance-boosting<br />

patches are available for the version<br />

of InnoDB that ships with MySQLM;<br />

some of them are included in the<br />

OurDelta version. One that is worthy<br />

of mention is a reworked RW lock<br />

that improves locking behavior on<br />

multi-processor systems in particular.<br />

A description of all the improvements<br />

is beyond the scope of this article, but<br />

one thing is clear; patches for InnoDB<br />

exist that retain compatibility and<br />

offer transparent optimization of the<br />

engine. Typically, it is difficult to measure<br />

the performance gain in an objective<br />

way because the performance<br />

of the MySQL server will depend to<br />

a great extent on the hardware, configuration,<br />

and data it uses. The most<br />

exhaustive and reliable source is the<br />

MySQL Performance Blog [4], which<br />

regularly publishes test results.<br />

Improvements by selectively installing<br />

patches for the legacy InnoDB engine<br />

are regarded as a fairly conservative<br />

approach. The use of an alternative<br />

Listing 1: Userstats Patch in Action<br />

database engine holds more promise.<br />

The InnoDB plug in and Percona<br />

XtraDB engines are becoming increasingly<br />

widespread.<br />

The InnoDB Plugin<br />

The InnoBase InnoDB plugin is an<br />

ongoing development of the InnoDB<br />

engine that ships with MySQL [6].<br />

Improvements include general optimization<br />

of CPU load and I/​O access, a<br />

faster locking mechanism, extended<br />

configuration and reporting options,<br />

and optional table compression.<br />

MySQL 5.1 introduced the option of<br />

unloading the standard engine and<br />

replacing it with a different version.<br />

Starting with MySQL 5.1.38, MySQL<br />

additionally supplies the InnoDB<br />

plugin. As MySQL describes this as<br />

a release candidate, administrators<br />

do need to enable it manually. The<br />

official MySQL documentation describes<br />

the steps required to do so<br />

[7]. To benefit from the combination<br />

of distribution updates for the MySQL<br />

kernel and the latest functions and<br />

optimizations of the InnoDB plugin, it<br />

is a good idea to install the latest InnoDB<br />

plugin version from the InnoDB<br />

website.<br />

Ubuntu 10.04 comes with MySQL<br />

server version 5.1.41. The /usr/lib/<br />

mysql/plugin/ houses an InnoDB plugin<br />

version 1.0.4 that is disabled by<br />

default. The InnoDB website has the<br />

current version, 1.0.6, which you can<br />

download and unpack. Then copy<br />

ha_innodb.so to the /usr/lib/mysql/<br />

plugin/ directory. Because Ubuntu<br />

uses AppArmor to protect services by<br />

default, you need to disable or modify<br />

AppArmor to let you load content<br />

from the plugin directory by adding<br />

mysql> select * from information_schema.TABLE_STATISTICS ORDER BY ROWS_READ DESC LIMIT 0,5;<br />

+‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+<br />

| TABLE_SCHEMA | TABLE_NAME | ROWS_READ | ROWS_CHANGED | ROWS_CHANGED_X_INDEXES |<br />

+‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+<br />

| moviepilot | images | 13138219791 | 14778 | 118224 |<br />

| moviepilot | events | 3957858216 | 59964 | 359784 |<br />

| moviepilot | comments | 2650553183 | 3408 | 20448 |<br />

| moviepilot | movies | 2013076357 | 598505 | 7780565 |<br />

| omdb | log_entries | 1106683022 | 2737 | 5474 |<br />

+‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐‐+‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐+<br />

www.admin-magazine.com<br />

Admin 01<br />

21

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!