LoginSignup
4
5

More than 5 years have passed since last update.

MariaDB ColumnStoreクラスタ構築メモ

Last updated at Posted at 2018-08-17

チューニングレスのDWH特化型のMariaDB ColumnStoreが気になったので、環境構築してみよと思ってやってみた自分用のメモです。

[ColumnStoreの特長]

  • 分析/集計処理に最適なカラムストアエンジン
  • MySQLとの互換性
  • リニアにスケール

なお、ColumnStoreには以下の制約があります。

[ColumnStoreの制約]

  • primary keyの指定ができない
  • Indexの作成ができない

アーキテクチャの紹介については、このスライドが分かりやすかったです。
https://www.slideshare.net/KAWANOKAZUYUKI/mariadb-columnstore-80198443

環境全体像

検証用に以下の構成として、Vagrant/VirtualBox上に構築してみました。
UMとPMをそれぞれスケールアウトできるように構築します。

また、pm-2はPM増設用としています。増設手順は後ほど記載します。

  • UM(UserModule): 1台、CentOS7
  • PM(PerformanceModule): 2台、CentOS7
  • ColumnStoreバージョン: mariadb-columnstore-1.1.5-1

columnstore.png

Vagrantfileを記載しておきます。

# *- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

  # User Moudle#2
  config.vm.define "um-1" do |node|
    node.vm.provider "virtualbox" do |vm|
      vm.name = "um-1"
      vm.customize ["modifyvm", :id, "--memory", "2048"]
    end
    node.vm.box = "centos/7"
    node.vm.hostname = "um-1"
    node.vm.network "private_network", ip: "192.168.33.51"
  end

  # Performance Moudle#1
  config.vm.define "pm-1" do |node|
    node.vm.provider "virtualbox" do |vm|
      vm.name = "pm-1"
      vm.customize ["modifyvm", :id, "--memory", "2048"]
    end
    node.vm.box = "centos/7"
    node.vm.hostname = "pm-1"
    node.vm.network "private_network", ip: "192.168.33.52"
  end

  # 増設用のPerformance Moudle#2
  config.vm.define "pm-2" do |node|
    node.vm.provider "virtualbox" do |vm|
      vm.name = "pm-2"
      vm.customize ["modifyvm", :id, "--memory", "2048"]
    end
    node.vm.box = "centos/7"
    node.vm.hostname = "pm-2"
    node.vm.network "private_network", ip: "192.168.33.53"
  end

end

VMを起動します。

vagrant up
vagrant ssh-config pm-1 pm-2 um-1 >> ~/.ssh\config

1. 事前準備

すべてのサーバ(um-1/pm-1/pm-2)でrootユーザで実施します。

/etc/hostsの設定

ホスト名で通信できるようにしておいてください。

127.0.0.1 localhost
192.168.33.51 um-1
192.168.33.52 pm-1
192.168.33.53 pm-2

SSHサーバ設定

/etc/ssh/sshd_configPasswordAuthenticationyesに変更してください。

PasswordAuthentication yes

変更後、再起動てください。

systemctl restart sshd

SELinuxの無効化

SELinuxを無効化しておきます。

setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

sshの設定

rootユーザーでそれぞれのサーバーにパスフレーズ無しでログインできるように設定する必要があります。

すべてのサーバで実行してください。

ssh-keygen
ssh-copy-id -i ~/.ssh/id_rsa.pub um-1
ssh-copy-id -i ~/.ssh/id_rsa.pub pm-1
ssh-copy-id -i ~/.ssh/id_rsa.pub pm-2

2. MariaDB ColumnStoreインストール

依存パッケージインストール

ColumStoreをインストールするために依存パッケージをインストールします。

以下のコマンドをすべてのサーバ(um-1/pm-1/pm-2)で実行してください。

yum -y install boost expect perl perl-DBI openssl zlib file sudo  libaio rsync snappy net-tools perl-DBD-MySQL

ColumnStoreインストール

インストールは、必ずpm-1で実行してください

cd /root

curl -O https://downloads.mariadb.com/ColumnStore/latest/centos/x86_64/7/mariadb-columnstore-1.1.5-1-centos7.x86_64.rpm.tar.gz
tar zxvf mariadb-columnstore-1.1.5-1-centos7.x86_64.rpm.tar.gz
rpm -ivh mariadb-columnstore*.rpm

準備が整ったので、インストールします。

# /usr/local/mariadb/columnstore/bin/postConfigure

This is the MariaDB ColumnStore System Configuration and Installation tool.
It will Configure the MariaDB ColumnStore System and will perform a Package
Installation of all of the Servers within the System that is being configured.

IMPORTANT: This tool should only be run on the Parent OAM Module
           which is a Performance Module, preferred Module #1

Prompting instructions:

    Press 'enter' to accept a value in (), if available or
    Enter one of the options within [], if available, or
    Enter a new value


===== Setup System Server Type Configuration =====

There are 2 options when configuring the System Server Type: single and multi

  'single'  - Single-Server install is used when there will only be 1 server configured
              on the system. It can also be used for production systems, if the plan is
              to stay single-server.

  'multi'   - Multi-Server install is used when you want to configure multiple servers now or
              in the future. With Multi-Server install, you can still configure just 1 server
              now and add on addition servers/modules in the future.

Select the type of System Server install [1=single, 2=multi] (2) > 2


===== Setup System Module Type Configuration =====

There are 2 options when configuring the System Module Type: separate and combined

  'separate' - User and Performance functionality on separate servers.

  'combined' - User and Performance functionality on the same server

Select the type of System Module Install [1=separate, 2=combined] (2) > 1

Seperate Server Installation will be performed.

NOTE: Local Query Feature allows the ability to query data from a single Performance
      Module. Check MariaDB ColumnStore Admin Guide for additional information.

Enable Local Query feature? [y,n] (n) >

NOTE: The MariaDB ColumnStore Schema Sync feature will replicate all of the
      schemas and InnoDB tables across the User Module nodes. This feature can be enabled
      or disabled, for example, if you wish to configure your own replication post installation.

MariaDB ColumnStore Schema Sync feature, do you want to enable? [y,n] (y) >


NOTE: MariaDB ColumnStore Replication Feature is enabled

Enter System Name (columnstore-1) > mycluster


===== Setup Storage Configuration =====


----- Setup Performance Module DBRoot Data Storage Mount Configuration -----

There are 2 options when configuring the storage: internal or external

  'internal' -    This is specified when a local disk is used for the DBRoot storage.
                  High Availability Server Failover is not Supported in this mode

  'external' -    This is specified when the DBRoot directories are mounted.
                  High Availability Server Failover is Supported in this mode.

Select the type of Data Storage [1=internal, 2=external] (1) > 1

===== Setup Memory Configuration =====

NOTE: Setting 'NumBlocksPct' to 70%
      Setting 'TotalUmMemory' to 50%

===== Setup the Module Configuration =====


----- User Module Configuration -----

Enter number of User Modules [1,1024] (1) >

*** User Module #1 Configuration ***

Enter Nic Interface #1 Host Name (unassigned) > um-1
Enter Nic Interface #1 IP Address of um-1 (192.168.33.51) >
Enter Nic Interface #2 Host Name (unassigned) >

----- Performance Module Configuration -----

Enter number of Performance Modules [1,1024] (1) > 1

*** Parent OAM Module Performance Module #1 Configuration ***

Enter Nic Interface #1 Host Name (pm-1) >
Enter Nic Interface #1 IP Address of pm-1 (192.168.33.52) >
Enter Nic Interface #2 Host Name (unassigned) >
Enter the list (Nx,Ny,Nz) or range (Nx-Nz) of DBRoot IDs assigned to module 'pm1' (1) >

===== System Installation =====

System Configuration is complete.
Performing System Installation.

Performing a MariaDB ColumnStore System install using RPM packages
located in the /root directory.


Next step is to enter the password to access the other Servers.
This is either your password or you can default to using a ssh key
If using a password, the password needs to be the same on all Servers.

Enter password, hit 'enter' to default to using a ssh key, or 'exit' >


----- Performing Install on 'um1 / um-1' -----

Install log file is located here: /tmp/um1_rpm_install.log


MariaDB ColumnStore Package being installed, please wait ...  DONE

===== Checking MariaDB ColumnStore System Logging Functionality =====

The MariaDB ColumnStore system logging is setup and working on local server

===== MariaDB ColumnStore System Startup =====

System Configuration is complete.
Performing System Installation.

----- Starting MariaDB ColumnStore on local server -----

MariaDB ColumnStore successfully started

MariaDB ColumnStore Database Platform Starting, please wait ........... DONE

System Catalog Successfully Created

Run MariaDB ColumnStore Replication Setup..  DONE

MariaDB ColumnStore Install Successfully Completed, System is Active

Enter the following command to define MariaDB ColumnStore Alias Commands

. /usr/local/mariadb/columnstore/bin/columnstoreAlias

Enter 'mcsmysql' to access the MariaDB ColumnStore SQL console
Enter 'mcsadmin' to access the MariaDB ColumnStore Admin console

NOTE: The MariaDB ColumnStore Alias Commands are in /etc/profile.d/columnstoreAlias.sh

各コマンドへのエイリアスを作成

この設定はum-1, pm-1で実施します。
helpが表示されればOK

$ . /usr/local/mariadb/columnstore/bin/columnstoreAlias
$ mcsadmin help
echo ". /usr/local/mariadb/columnstore/bin/columnstoreAlias" | sudo tee  /etc/profile.d/mariadb.sh
sudo chmod 755 /etc/profile.d/mariadb.sh > /dev/null
source /etc/profile

この設定によって、超大事なコマンドmcsadminmcsmysqlを実行できるようになります。

おもに、mcsadminコマンドはpmノードから実行し、mcsmysqlコマンドはumノードから実行することになります。

(参考) mcsmysqlでのクライアント接続

[vagrant@um-1 ~]$ mcsmysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 26
Server version: 10.2.15-MariaDB-log Columnstore 1.1.5-1

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+---------------------+
| Database            |
+---------------------+
| calpontsys          |
| columnstore_info    |
| infinidb_querystats |
| infinidb_vtable     |
| information_schema  |
| mysql               |
| performance_schema  |
| test                |
+---------------------+
8 rows in set (0.00 sec)

MariaDB [(none)]>

(参考) mcsadminコマンドの利用例

  • システムステータスの取得
[vagrant@pm-1 ~]$ mcsadmin getSystemStatus
getsystemstatus   Thu Aug 16 16:20:59 2018

System mycluster

System and Module statuses

Component     Status                       Last Status Change
------------  --------------------------   ------------------------
System        ACTIVE                       Thu Aug 16 15:50:50 2018

Module um1    ACTIVE                       Thu Aug 16 15:50:42 2018
Module pm1    ACTIVE                       Thu Aug 16 15:50:24 2018

Active Parent OAM Performance Module is 'pm1'
MariaDB ColumnStore Replication Feature is enabled
  • プロセスステータスの取得
[vagrant@pm-1 ~]$ mcsadmin getProcessStatus
getprocessstatus   Thu Aug 16 16:22:00 2018

MariaDB ColumnStore Process statuses

Process             Module    Status            Last Status Change        Process ID
------------------  ------    ---------------   ------------------------  ----------
ProcessMonitor      um1       ACTIVE            Thu Aug 16 15:50:13 2018        4719
ServerMonitor       um1       ACTIVE            Thu Aug 16 15:50:27 2018        5095
DBRMWorkerNode      um1       ACTIVE            Thu Aug 16 15:50:27 2018        5108
ExeMgr              um1       ACTIVE            Thu Aug 16 15:50:35 2018        5529
DDLProc             um1       ACTIVE            Thu Aug 16 15:50:40 2018        6166
DMLProc             um1       ACTIVE            Thu Aug 16 15:50:50 2018        6392
mysqld              um1       ACTIVE            Thu Aug 16 15:50:45 2018        5054

ProcessMonitor      pm1       ACTIVE            Thu Aug 16 15:49:32 2018        4312
ProcessManager      pm1       ACTIVE            Thu Aug 16 15:49:39 2018        4365
DBRMControllerNode  pm1       ACTIVE            Thu Aug 16 15:50:18 2018        4896
ServerMonitor       pm1       ACTIVE            Thu Aug 16 15:50:21 2018        4928
DBRMWorkerNode      pm1       ACTIVE            Thu Aug 16 15:50:21 2018        4943
DecomSvr            pm1       ACTIVE            Thu Aug 16 15:50:22 2018        5030
PrimProc            pm1       ACTIVE            Thu Aug 16 15:50:28 2018        5084
WriteEngineServer   pm1       ACTIVE            Thu Aug 16 15:50:31 2018        5115
[vagrant@pm-1 ~]$
  • 停止
[vagrant@pm-1 ~]$ mcsadmin stopSystem
stopsystem   Thu Aug 16 16:30:45 2018

This command stops the processing of applications on all Modules within the MariaDB ColumnStore System

   Checking for active transactions
           Do you want to proceed: (y or n) [n]: y

   System being stopped now...
   Successful stop of System
  • 起動
[vagrant@pm-1 ~]$ mcsadmin startSystem
startsystem   Thu Aug 16 16:31:55 2018

   System being started, please wait...

   Successful start of System

3. 設定ファイル

設定ファイルは/usr/local/mariadb/columnstore/mysql/my.cnfにあるので必要に応じて編集する。

$ sudo vi /usr/local/mariadb/columnstore/mysql/my.cnf

4. PM1台での簡易的なパフォーマンス確認

以下の記事を丸パクリしました。
https://www.s-style.co.jp/blog/2017/07/621/

テストデータの用意

ファイル取得
Pagecount files for 2016-05
https://dumps.wikimedia.org/other/pagecounts-raw/2016/2016-05/

curl -O https://dumps.wikimedia.org/other/pagecounts-raw/2016/2016-05/pagecounts-20160501-000000.gz
curl -O https://dumps.wikimedia.org/other/pagecounts-raw/2016/2016-05/pagecounts-20160502-000000.gz
curl -O https://dumps.wikimedia.org/other/pagecounts-raw/2016/2016-05/pagecounts-20160503-000000.gz
curl -O https://dumps.wikimedia.org/other/pagecounts-raw/2016/2016-05/pagecounts-20160504-000000.gz
curl -O https://dumps.wikimedia.org/other/pagecounts-raw/2016/2016-05/pagecounts-20160505-000000.gz

解凍します。

gunzip -r pagecounts-2016050*

一応、中身を確認します。

head pagecounts-20160501-000000

aa Category:Language_user_templates 1 6020
aa File:Hitchhicking_on_the_road_132_-_Gasp%C3%A9sie_Canada.jpg 1 8520

スペースをタブに変換します。

cat ./pagecounts-20160501-000000 | tr ' ' '\t' > ./pagecounts-20160501-000000_convert
cat ./pagecounts-20160502-000000 | tr ' ' '\t' > ./pagecounts-20160502-000000_convert
cat ./pagecounts-20160503-000000 | tr ' ' '\t' > ./pagecounts-20160503-000000_convert
cat ./pagecounts-20160504-000000 | tr ' ' '\t' > ./pagecounts-20160504-000000_convert
cat ./pagecounts-20160505-000000 | tr ' ' '\t' > ./pagecounts-20160505-000000_convert

データベース名をwiki_test、テーブル名をpage_counts_1として作成します。

# mcsmysql

MariaDB [(none)]> create database wiki_test;
MariaDB [(none)]> use wiki_test;
MariaDB [wiki_test]> create table page_counts_1 (domain_code varchar(10), page_title varchar(500), count_views int unsigned, total_response_size int unsigned) engine=columnstore;
MariaDB [wiki_test]> exit

作成したデータベース(wiki_test)のテーブル(page_counts_1)にcpimportコマンドを使ってた試しにロードします。

# time cpimport wiki_test page_counts_1 ./pagecounts-20160501-000000_convert -s "\t"
Locale is : C
Column delimiter : \t
...
2017-05-25 10:28:47 (22197) WARN : Column wiki_test.page_counts_1.total_response_size; Number of rows inserted with saturated values: 8
2017-05-25 10:28:48 (22197) INFO : Bulk load completed, total run time : 15.3101 seconds

real    0m16.529s
user    0m6.575s
sys     0m2.127s

データが入っていることを確認します。

# time mcsmysql -e "select count(*) FROM wiki_test.page_counts_1"
+----------+
| count(*) |
+----------+
|  6296217 |
+----------+

real    0m0.313s
user    0m0.006s
sys     0m0.002s

同様に、残りの4ファイルもロードします。

# cpimport wiki_test page_counts_1 ./pagecounts-20160502-000000_convert -s "\t"
# cpimport wiki_test page_counts_1 ./pagecounts-20160503-000000_convert -s "\t"
# cpimport wiki_test page_counts_1 ./pagecounts-20160504-000000_convert -s "\t"
# cpimport wiki_test page_counts_1 ./pagecounts-20160505-000000_convert -s "\t"

# time mcsmysql -e "select count(*) FROM wiki_test.page_counts_1"
+----------+
| count(*) |
+----------+
| 30375414 |
+----------+

real    0m1.087s
user    0m0.005s
sys 0m0.004s

クエリの時間を計測

参考記事のとおり、timeコマンドでクエリの時間を計測してみます。

# time ( mcsmysql -e "SELECT count(*) FROM wiki_test.page_counts_1 GROUP BY domain_code" > /dev/null )

real    0m7.250s
user    0m0.001s
sys 0m0.010s

# time ( mcsmysql -e "SELECT domain_code FROM wiki_test.page_counts_1 ORDER BY total_response_size" > /dev/null )

real    0m36.470s
user    0m3.118s
sys 0m0.814s

この時間はpm-2増設後の比較時の参考値とします。

5. PMノード追加

pm-2を追加します。
本手順はpm1で実行してください。

DBRootの追加

[root@pm-1 ~]# mcsadmin addDbroot 1
adddbroot   Thu Aug 16 18:15:02 2018

New DBRoot IDs added = 2

DBRootを追加してID:2が払いだされたことが確認できます。

ストレージ設定の確認

[root@pm-1 ~]# mcsadmin getStorageConfig
getstorageconfig   Thu Aug 16 18:16:00 2018

System Storage Configuration

Performance Module (DBRoot) Storage Type = internal
System Assigned DBRoot Count = 1
DBRoot IDs assigned to 'pm1' = 1

DBRoot IDs unassigned = 2

ID:2が未割当になっていることが確認できます。

PMノード追加

mcsadmin addModule [モジュールタイプ] [追加数] [ホスト名] [パスワード]
で追加し追加します。

[root@pm-1 ~]# mcsadmin addModule pm 1 pm-2
addmodule   Thu Aug 16 18:17:13 2018

Enter the 'User' Password or 'ssh' if configured with ssh-keys
           Please enter: ssh

Adding Modules pm2, please wait...
Add Module(s) successfully completed
addModule Command Successfully completed: Modules are Disabled, run alterSystem-enableModule command to enable them

追加後、システムステータスを確認します。

[root@pm-1 ~]# mcsadmin getSystemStatus
getsystemstatus   Thu Aug 16 18:21:24 2018

System mycluster

System and Module statuses

Component     Status                       Last Status Change
------------  --------------------------   ------------------------
System        ACTIVE                       Thu Aug 16 16:32:20 2018

Module um1    ACTIVE                       Thu Aug 16 16:32:17 2018
Module pm1    ACTIVE                       Thu Aug 16 16:32:08 2018
Module pm2    MAN_DISABLED                 Thu Aug 16 18:17:19 2018

Active Parent OAM Performance Module is 'pm1'
MariaDB ColumnStore Replication Feature is enabled

pm2のステータスがMAN_DISABLEDになっているので、有効化する必要があります。

pm2を有効化する

[root@pm-1 ~]# mcsadmin alterSystem-enableModule pm2
altersystem-enablemodule   Thu Aug 16 18:22:04 2018

This command starts the processing of applications on a Module within the MariaDB ColumnStore System
           Do you want to proceed: (y or n) [n]: y

   Enabling Modules
   Successful enable of Modules

   Performance Module(s) Enabled, run movePmDbrootConfig or assignDbrootPmConfig to assign dbroots, if needed

再度システムステータスを確認します。

[root@pm-1 ~]# mcsadmin getSystemStatus
getsystemstatus   Thu Aug 16 18:23:47 2018

System mycluster

System and Module statuses

Component     Status                       Last Status Change
------------  --------------------------   ------------------------
System        ACTIVE                       Thu Aug 16 18:23:05 2018

Module um1    ACTIVE                       Thu Aug 16 16:32:17 2018
Module pm1    ACTIVE                       Thu Aug 16 16:32:08 2018
Module pm2    MAN_OFFLINE                  Thu Aug 16 18:22:12 2018

Active Parent OAM Performance Module is 'pm1'
MariaDB ColumnStore Replication Feature is enabled

pm2のステータスがMAN_OFFLINEになっていることを確認できます。

新しいpm2に未割り当てのDBRootを割り当てる

pm2のステータスをアクティブにするためにはDBRootを割り当てる必要があります。

mcsadmin assignDbrootPmConfig [DBRootのID] pm2で割り当てます。

[root@pm-1 ~]# mcsadmin assignDbrootPmConfig 2 pm2
assigndbrootpmconfig   Thu Aug 16 18:24:18 2018

DBRoot IDs assigned to 'pm2' =

Changes being applied

DBRoot IDs assigned to 'pm2' = 2

   Successfully Assigned DBRoots

pm2にDBRootID:2がわりあたったことを確認します。

[root@pm-1 ~]# mcsadmin getStorageConfig
getstorageconfig   Thu Aug 16 18:25:16 2018

System Storage Configuration

Performance Module (DBRoot) Storage Type = internal
System Assigned DBRoot Count = 2
DBRoot IDs assigned to 'pm1' = 1
DBRoot IDs assigned to 'pm2' = 2

pm2を起動する

pm2を起動します。

[root@pm-1 ~]# mcsadmin startSystem
startsystem   Thu Aug 16 18:25:41 2018

   System being started, please wait...
   Successful start of System

起動後、システムステータスを確認します。ACTIVEになったことを確認してください。

[root@pm-1 ~]# mcsadmin getSystemStatus
getsystemstatus   Thu Aug 16 18:26:20 2018

System mycluster

System and Module statuses

Component     Status                       Last Status Change
------------  --------------------------   ------------------------
System        ACTIVE                       Thu Aug 16 18:25:56 2018

Module um1    ACTIVE                       Thu Aug 16 16:32:17 2018
Module pm1    ACTIVE                       Thu Aug 16 16:32:08 2018
Module pm2    ACTIVE                       Thu Aug 16 18:25:55 2018

Active Parent OAM Performance Module is 'pm1'
MariaDB ColumnStore Replication Feature is enabled

PMノード追加後の性能測定

データベースwiki_test2にテーブルpage_counts_1を新規に作成します。

[vagrant@um-1 ~]$ mcsmysql

MariaDB [(none)]> create database wiki_test2;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> use wiki_test2;
Database changed

MariaDB [wiki_test2]> create table page_counts_1 (domain_code varchar(10), page_title varchar(500), count_views int unsigned, total_response_size int unsigned) engine=columnstore;

データをインポートします。

[vagrant@um-1 ~]$ cpimport -m 1 wiki_test2 page_counts_1 ./pagecounts-20160501-000000_convert -s "\t"
[vagrant@um-1 ~]$ cpimport -m 1 wiki_test2 page_counts_1 ./pagecounts-20160502-000000_convert -s "\t"
[vagrant@um-1 ~]$ cpimport -m 1 wiki_test2 page_counts_1 ./pagecounts-20160503-000000_convert -s "\t"
[vagrant@um-1 ~]$ cpimport -m 1 wiki_test2 page_counts_1 ./pagecounts-20160504-000000_convert -s "\t"
[vagrant@um-1 ~]$ cpimport -m 1 wiki_test2 page_counts_1 ./pagecounts-20160505-000000_convert -s "\t"

データが入ったことを確認します。

[vagrant@um-1 ~]$ mcsmysql -e "select count(*) FROM wiki_test2.page_counts_1"
+----------+
| count(*) |
+----------+
| 30375414 |
+----------+

PMノード増設後のクエリの時間を計測

[vagrant@um-1 ~]$ time ( mcsmysql -e "SELECT count(*) FROM wiki_test2.page_counts_1 GROUP BY domain_code" > /dev/null )

real    0m4.546s
user    0m0.003s
sys 0m0.005s

[vagrant@um-1 ~]$ time ( mcsmysql -e "SELECT domain_code FROM wiki_test2.page_counts_1 ORDER BY total_response_size" > /dev/null )

real    0m38.117s
user    0m3.287s
sys 0m0.615s

増設前後の比較

ついでに、MySQL5.7シングルサーバでの比較も載せておきます。

  1. SELECT count(*) FROM wiki_testX.page_counts_1 GROUP BY domain_code;
    • MySQL(1台):
      real 0m23.406s user 0m0.001s sys 0m0.012s
    • 増設前(PM1台):
      real 0m7.250s user 0m0.001s sys 0m0.010s
    • 増設後(PM2台):
      real 0m4.546s user 0m0.003s sys 0m0.005s
  2. SELECT domain_code FROM wiki_testX.page_counts_1 ORDER BY total_response_size;
    • MySQL(1台):
      real 0m50.386s user 0m3.127s sys 0m0.848s
    • 増設前(PM1台):
      real 0m36.470s user 0m3.118s sys 0m0.814s
    • 増設後(PM2台):
      real 0m38.117s user 0m3.287s sys 0m0.615s

1.のクエリについては早くなったが、2.のクエリについては、なぜか変わらなかった。// TODO 分かったら追記します。

その他 メモ

サイズ確認

MariaDB [(none)]> call columnstore_info.total_usage();
+-----------------+------------------+
| TOTAL_DATA_SIZE | TOTAL_DISK_USAGE |
+-----------------+------------------+
| 1.91 GB         | 1.90 GB          |
+-----------------+------------------+
1 row in set (0.46 sec)

Query OK, 0 rows affected (0.46 sec)

MariaDB [(none)]> call columnstore_info.table_usage( NULL, NULL);
+--------------+---------------+-----------------+-----------------+-------------+
| TABLE_SCHEMA | TABLE_NAME    | DATA_DISK_USAGE | DICT_DISK_USAGE | TOTAL_USAGE |
+--------------+---------------+-----------------+-----------------+-------------+
| wiki_test    | page_counts_1 | 407.78 MB       | 1.50 GB         | 1.90 GB     |
+--------------+---------------+-----------------+-----------------+-------------+
1 row in set (0.29 sec)

Query OK, 0 rows affected (0.29 sec)

MariaDB [(none)]>

検証前に設定しておいたほうがいいパラメータ

大量のレコードに対してOrderBy 等ソート処理を実行した場合、下記のようなエラーが出力されることがあります。

max_length_for_sort_dataを予め大きい値に変更しておいたほうがよい。

MariaDB [(none)]> set global max_length_for_sort_data = 8388608

実行計画の確認

explainを使っても意味のある情報を取得できない。

専用関数を使う必要がある。

MariaDB [wiki_test]> explain select * from page_counts_1 limit 100;
+------+-------------+---------------+------+---------------+------+---------+------+------+-------+
| id   | select_type | table         | type | possible_keys | key  | key_len | ref  | rows | Extra |
+------+-------------+---------------+------+---------------+------+---------+------+------+-------+
|    1 | SIMPLE      | page_counts_1 | ALL  | NULL          | NULL | NULL    | NULL | 2000 |       |
+------+-------------+---------------+------+---------------+------+---------+------+------+-------+
1 row in set (0.00 sec)

専用関数

  • select calFlushCache();
    • データベースキャッシュをクリアします
  • select calsettrace(1);
    • 実行計画取得モードをONにします
  • select calgettrace();
    • 直前に実行したクエリの実行計画を取得します
  • select calsettrace(0);
    • 実行計画取得モードをOFFにします
MariaDB [wiki_test]> select calFlushCache();
+-----------------+
| calFlushCache() |
+-----------------+
|               0 |
+-----------------+
1 row in set (0.01 sec)

MariaDB [wiki_test]> select calSetTrace(1);
+----------------+
| calSetTrace(1) |
+----------------+
|              0 |
+----------------+
1 row in set (0.00 sec)

MariaDB [wiki_test]> select * from page_counts_1 limit 100;

MariaDB [wiki_test]> select calgettrace();
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| calgettrace()                                                                                                                                                                                                                                                                                                                                                             |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
Desc Mode Table         TableOID ReferencedColumns                                        PIO  LIO  PBE Elapsed Rows
BPS  PM   page_counts_1 3000     (count_views,domain_code,page_title,total_response_size) 7168 2711 0   0.400   260096
TNS  UM   -             -        -                                                        -    -    -   0.005   100
 |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

MariaDB [wiki_test]> select calSetTrace(0);
+----------------+
| calSetTrace(0) |
+----------------+
|              1 |
+----------------+
1 row in set (0.00 sec)

最も重要な値はPBE

PBEの値は エクステントマップの活用により読み飛ばすことができたブロックサイズを示しています。

大量データに対する高速参照を実現するためにはエクステントマップを活用することが何よりも重要。

この値が0の場合、エクステントマップの恩恵を得られていないことを示している。

なお、以下のカラムに対しては、エクステントマップを利用できない。

  • DOUBLE / REAL
  • FLOAT
  • CHAR 8byte以上
  • VARCHAR 8byte以上
4
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5