Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
MariaDB High Performance
MariaDB High Performance

MariaDB High Performance: Familiarize yourself with the MariaDB system and build high-performance applications

eBook
$9.99 $28.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

MariaDB High Performance

Chapter 2. Performance Analysis

In this chapter, you'll get recommendations for how to achieve good performance, what tools to use, and MariaDB internal presentations for analyses purposes. The goal of this chapter is to help you find where a performance issue comes from.

The performance goal takes time and requires a lot of tests to make things as performant as possible. There are many situations, many possibilities, and different architectures, and all these complex things need to be answered with many tools. These tools will help you diagnose performance issues as fast as possible to find complex issues.

Tools are not the only solutions. You can do many other things to optimize your databases:

  • Use good index types when it's necessary. Too many indexes will slow down your databases.
  • Set the best column data type. For example, do not use a char column data type if it stores only integers.
  • Avoid duplicated keys.
  • Optimize your SQL queries as much as possible.

If these points...

Slow queries

The slow query log feature gives the possibility to log queries that take more than x seconds to be executed. This is the first step when investigating a performance issue. To look at the current status, connect to your MariaDB instance and launch it:

MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE '%SLOW_QUERY%';
+---------------------+---------------------------------+
| Variable_name       | Value                           |
+---------------------+---------------------------------+
| slow_query_log      | OFF                             |
| slow_query_log_file | /var/log/mysql/mariadb-slow.log |
+---------------------+---------------------------------+
2 rows in set (0.00 sec)

Here, we can see the path of the slow query logs. To activate this on the fly, run that SQL command:

MariaDB [(none)]> SET GLOBAL SLOW_QUERY_LOG=1;
Query OK, 0 rows affected (0.00 sec)

The other option is to set in seconds the query delay to mark it as a long query. These long queries will...

The explain command

The explain SQL command provides information for a specific request. Most of the time, we get a query from the slow query logs to analyze the request. The explain command won't return the classical output of the query but will provide some information concerning the related SQL query.

The explain command can only be applied on a SELECT query. UPDATE and DELETE are supported in Version 10.0.5!

Let's take a query that you can have in your slow query logs. Here is an example with a working version of MediaWiki:

MariaDB [mediawiki]> explain select page_id, page_title, page_namespace, page_is_redirect, old_id, old_text from wiki_page, wiki_revision, wiki_text where rev_id=page_latest and old_id=rev_text_id\g;
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: wiki_page
         type: ALL
possible_keys: NULL
          key: NULL
      key_len: NULL
          ref: NULL
         rows: 2005
        Extra...

Slow query logs

Since you can directly have the query log the output of the explain command in MariaDB 10.0.5, this will help you save time. To make it active, you need to add this line in your MariaDB configuration file (/etc/mysql/my.cnf):

[mysqld]
log_slow_verbosity      = query_plan,explain

Then, restart MariaDB. To test it, simply force the creation of a long query. Here is a SQL script with a loop. Adapt the first line if the default time is not enough:

-- Change this value to a higher one if you need more time
-- This will insert x lines number in your database
SET @MAX_INSERT = 100000;

-- Vars
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";

-- Create database
DROP DATABASE IF EXISTS chapter2;
CREATE DATABASE chapter2;
USE chapter2;

-- Create table and add index
CREATE TABLE IF NOT EXISTS `s_explain` (
  `id` int(11) DEFAULT NULL,
  `ts` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT...

The show explain command

The show explain feature is only available in MariaDB 10. It allows you to get an explanation directly from a running process, for example, if you use the loop.sql script once again. At the time of insertion, execute a show processlist command:

MariaDB [chapter2]> SHOW PROCESSLIST\G;
[...]
*************************** 2. row ***************************
      Id: 81
    User: root
    Host: localhost
      db: chapter2
 Command: Query
    Time: 0
   State: query end
    Info: INSERT INTO `s_explain`(`id`, `ts`) VALUES (FLOOR(RAND() * @MAX_INSERT), NOW())
Progress: 0.000
2 rows in set (0.00 sec)

We can see here the 81 ID, which is the INSERT command in the loop.sql script. We're going to analyze it with the show explain command:

MariaDB [chapter2]> SHOW EXPLAIN FOR 81\G;
*************************** 1. row ***************************
           id: 1
  select_type: INSERT
        table: s_explain
         type: ALL
possible_keys: NULL
          key: NULL
 ...

Profiling

Profiling permits you to benchmark information that indicates resource usages during a session. This is used when we want to get information on a specified query. Here are the types of information:

  • Block I/O
  • Context switches
  • CPU
  • IPC
  • Memory
  • Page faults
  • Source
  • Swaps
  • All

First of all, you need to know that profiling on a production server is not recommended because of the performance degradation it can cause.

To enable profiling, use the following command:

MariaDB [none]> SET PROFILING=1;

Perform all the query tasks you want to profile and then list them:

MariaDB [none]> SHOW PROFILES;
+----------+------------+-------------------------+
| Query_ID | Duration   | Query                   |
+----------+------------+-------------------------+
|        1 | 0.30798532 | select * from s_explain |
|        2 | 0.25341312 | select * from s_explain |
+----------+------------+-------------------------+

In the preceding command-line output, you can see that we've two query IDs. To get information...

Slow queries


The slow query log feature gives the possibility to log queries that take more than x seconds to be executed. This is the first step when investigating a performance issue. To look at the current status, connect to your MariaDB instance and launch it:

MariaDB [(none)]> SHOW GLOBAL VARIABLES LIKE '%SLOW_QUERY%';
+---------------------+---------------------------------+
| Variable_name       | Value                           |
+---------------------+---------------------------------+
| slow_query_log      | OFF                             |
| slow_query_log_file | /var/log/mysql/mariadb-slow.log |
+---------------------+---------------------------------+
2 rows in set (0.00 sec)

Here, we can see the path of the slow query logs. To activate this on the fly, run that SQL command:

MariaDB [(none)]> SET GLOBAL SLOW_QUERY_LOG=1;
Query OK, 0 rows affected (0.00 sec)

The other option is to set in seconds the query delay to mark it as a long query. These long queries will be logged...

The explain command


The explain SQL command provides information for a specific request. Most of the time, we get a query from the slow query logs to analyze the request. The explain command won't return the classical output of the query but will provide some information concerning the related SQL query.

The explain command can only be applied on a SELECT query. UPDATE and DELETE are supported in Version 10.0.5!

Let's take a query that you can have in your slow query logs. Here is an example with a working version of MediaWiki:

MariaDB [mediawiki]> explain select page_id, page_title, page_namespace, page_is_redirect, old_id, old_text from wiki_page, wiki_revision, wiki_text where rev_id=page_latest and old_id=rev_text_id\g;
*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: wiki_page
         type: ALL
possible_keys: NULL
          key: NULL
      key_len: NULL
          ref: NULL
         rows: 2005
        Extra:
*****...

Slow query logs


Since you can directly have the query log the output of the explain command in MariaDB 10.0.5, this will help you save time. To make it active, you need to add this line in your MariaDB configuration file (/etc/mysql/my.cnf):

[mysqld]
log_slow_verbosity      = query_plan,explain

Then, restart MariaDB. To test it, simply force the creation of a long query. Here is a SQL script with a loop. Adapt the first line if the default time is not enough:

-- Change this value to a higher one if you need more time
-- This will insert x lines number in your database
SET @MAX_INSERT = 100000;

-- Vars
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";

-- Create database
DROP DATABASE IF EXISTS chapter2;
CREATE DATABASE chapter2;
USE chapter2;

-- Create table and add index
CREATE TABLE IF NOT EXISTS `s_explain` (
  `id` int(11) DEFAULT NULL,
  `ts` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ALTER TABLE...

The show explain command


The show explain feature is only available in MariaDB 10. It allows you to get an explanation directly from a running process, for example, if you use the loop.sql script once again. At the time of insertion, execute a show processlist command:

MariaDB [chapter2]> SHOW PROCESSLIST\G;
[...]
*************************** 2. row ***************************
      Id: 81
    User: root
    Host: localhost
      db: chapter2
 Command: Query
    Time: 0
   State: query end
    Info: INSERT INTO `s_explain`(`id`, `ts`) VALUES (FLOOR(RAND() * @MAX_INSERT), NOW())
Progress: 0.000
2 rows in set (0.00 sec)

We can see here the 81 ID, which is the INSERT command in the loop.sql script. We're going to analyze it with the show explain command:

MariaDB [chapter2]> SHOW EXPLAIN FOR 81\G;
*************************** 1. row ***************************
           id: 1
  select_type: INSERT
        table: s_explain
         type: ALL
possible_keys: NULL
          key: NULL
     ...

Profiling


Profiling permits you to benchmark information that indicates resource usages during a session. This is used when we want to get information on a specified query. Here are the types of information:

  • Block I/O

  • Context switches

  • CPU

  • IPC

  • Memory

  • Page faults

  • Source

  • Swaps

  • All

First of all, you need to know that profiling on a production server is not recommended because of the performance degradation it can cause.

To enable profiling, use the following command:

MariaDB [none]> SET PROFILING=1;

Perform all the query tasks you want to profile and then list them:

MariaDB [none]> SHOW PROFILES;
+----------+------------+-------------------------+
| Query_ID | Duration   | Query                   |
+----------+------------+-------------------------+
|        1 | 0.30798532 | select * from s_explain |
|        2 | 0.25341312 | select * from s_explain |
+----------+------------+-------------------------+

In the preceding command-line output, you can see that we've two query IDs. To get information...

Performance schema


In Version 5.5.3, you can use the performance_schema monitoring feature of MariaDB to monitor performance. It has been implemented as an engine (that's why you can see it on a show engines command) with a database that stores data performance.

To activate the performance schema, add this line to your my.cnf configuration file:

performance_schema=on

You can then check whether it has been correctly activated:

MariaDB [(none)]> SHOW VARIABLES LIKE 'performance_schema';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| performance_schema | ON    |
+--------------------+-------+
1 row in set (0.00 sec)

You can now list the complete table list to see the available monitoring features:

MariaDB [(none)]> USE PERFORMANCE_SCHEMA;
MariaDB [performance_schema]> show tables;
+----------------------------------------------------+
| Tables_in_performance_schema                       |
+-----------------------------------------------...

User statistics


Since MariaDB 5.2, a patch from Google, Percona, and other companies has been implemented, which permits you to view the user statistics, client statistics, index statistics (and usage), and table statistics.

You can activate it on the fly using the following command:

MariaDB [(none)]> SET GLOBAL userstat=1;

Alternatively, you can make it persistent in the MariaDB configuration (my.cnf) using the following code:

[mysqld]
userstat = 1

You now have access to the new FLUSH and SHOW commands:

MariaDB [(none)]> FLUSH TABLE_STATISTICS
MariaDB [(none)]> FLUSH INDEX_STATISTICS
MariaDB [(none)]> FLUSH USER_STATISTICS
MariaDB [(none)]> FLUSH CLIENT_STATISTICS
MariaDB [(none)]> SHOW CLIENT_STATISTICS
MariaDB [(none)]> SHOW USER_STATISTICS
MariaDB [(none)]> SHOW INDEX_STATISTICS
MariaDB [(none)]> SHOW TABLE_STATISTICS

Here is an example of what the user statistics look like:

MariaDB [(none)]> SHOW USER_STATISTICS\G;
*************************** 1. row *****...

Sysbench


Sysbench is a benchmarking tool that has several modes to bench:

  • - fileio: This performs the file I/O test

  • - cpu: This performs the CPU performance test

  • - memory: This performs the memory functions speed test

  • - threads: This performs the thread subsystem performance test

  • - mutex: This performs the mutex performance test

  • - oltp: This performs the OLTP test

To install it, run this command:

> aptitude install sysbench

The common test is to use the Online Transaction Processing (OLTP) scenario with small transactions to hit an optimized database. We will pass arguments to the command to simulate application threads (the --num-threads argument).

You can run this OLTP test with two kinds of scenarios:

  • Read only (14 SELECT queries per transaction)

  • Read/Write (14 SELECT, 1 INSERT, 1 UPDATE, and 1 DELETE queries per transaction)

The available version in Debian Wheezy is 0.4. A newer version exists with more interesting results such as a reporting interval every x sec. In addition, you can...

Percona Toolkits


Percona Toolkits is a suite of tools for MySQL and MariaDB. They are very useful in many situations and well documented (the main website is http://www.percona.com/software/percona-toolkit). To install them, you can add the repository:

> aptitude install python-software-properties
> apt-key adv --keyserver keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A
> add-apt-repository 'deb http://repo.percona.com/apt wheezy main'

Then, configure APT-Pining to avoid the Percona repository overriding MariaDB's repository and conflict some packages. So, create this file at /etc/apt/preferences.d/00percona.pref and add the following content to it:

Package: *
Pin: release o=Percona Development Team
Pin-Priority: 100

You're now ready for the installation of the package:

> aptitude update
> aptitude install percona-toolkit

That's it! Several binaries starting with pt- are now available on your system.

pt-query-digest

The pt-query-digest tool will help you analyze the MariaDB slow queries...

Left arrow icon Right arrow icon

Description

This book is aimed at system administrators/architects or DBAs who want to learn more about how to grow their current infrastructure to support larger traffic. Before beginning with this book, we expect you to be well-practiced with MySQL/MariaDB for common usage. You will be able to get a grasp quickly if you are comfortable with learning and building large infrastructures for MariaDB using Linux.

What you will learn

  • Set up master/slave classical replications and make them scale easily, even over WAN
  • Create a dual master replication with load balancer and cluster software
  • Shard your data using the Spider engine
  • Grow your write infrastructure by setting up a Galera Cluster
  • Make your Galera Cluster and replication work together to build complex solutions
  • Optimize your engine and identify bottlenecks
  • Compare the Galera and MySQL Cluster
  • Graph your data and tools solution
  • Build a Galera disaster recovery solution

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 23, 2014
Length: 298 pages
Edition : 1st
Language : English
ISBN-13 : 9781783981618
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Sep 23, 2014
Length: 298 pages
Edition : 1st
Language : English
ISBN-13 : 9781783981618
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 158.97
MariaDB High Performance
$48.99
Mastering MariaDB
$54.99
MariaDB Cookbook
$54.99
Total $ 158.97 Stars icon
Banner background image

Table of Contents

12 Chapters
1. Performance Introduction Chevron down icon Chevron up icon
2. Performance Analysis Chevron down icon Chevron up icon
3. Performance Optimizations Chevron down icon Chevron up icon
4. MariaDB Replication Chevron down icon Chevron up icon
5. WAN Slave Architectures Chevron down icon Chevron up icon
6. Building a Dual Master Replication Chevron down icon Chevron up icon
7. MariaDB Multimaster Slaves Chevron down icon Chevron up icon
8. Galera Cluster – Multimaster Replication Chevron down icon Chevron up icon
9. Spider – Sharding Your Data Chevron down icon Chevron up icon
10. Monitoring Chevron down icon Chevron up icon
11. Backups Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3
(13 Ratings)
5 star 61.5%
4 star 23.1%
3 star 0%
2 star 15.4%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Vittorio Guglielmo Jun 05, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Great book !! After having read it, you will be able to build very easily any kind of complex architecture involving this powerful drop-in replacement of MySQL. It covers very well all needed arguments, form performance optimization to Dual Master/Multimaster replication, Galera Cluster, monitoring and a deep review of all the storage engines. For sure, a must have for all MySQL DBAs.
Amazon Verified review Amazon
arvind Jun 06, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
its vary good book.....written in very understandable way as well as technical so that we don't have to move any where. i would like also thanks to Packt Publishing because it has collected a lot of good book.i will tell u one thing more to PP plz provide the good book on SAN.
Amazon Verified review Amazon
Hector Louzao Jun 05, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Every chapter is very well crafted, with a precise balance between theory and practice, and full of invaluable nuggets, sometimes transcending, very solid foundations for the reading ahead.All over the text, author propose tools, examples of use and proven techniques, that will greatly improve your performance firefighter skills and enhance your knowledge of MariaDB internals, and don't forget to have a look to the code that compain this book.
Amazon Verified review Amazon
CS Jun 18, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
A good book for learning MariaDB, the new age of database servers. It cover all aspects which you need to learn about it. Great book overall, i highly recommend it.
Amazon Verified review Amazon
Brendon Jul 29, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Being involved in a project to migrate to MariaDB, we thought it would be prudent to buy a book to ensure we are getting the most out of the server. The book has been in constant use, along with Mastering MariaDB, so far!Well worth the purchase.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.