web-dev-qa-db-ja.com

EBSボリュームを備えたAmazonEC2MySQLインスタンスでの高iowait

ストレージにext3ファイルシステムを使用する単一のEBSボリュームに依存するAmazonEC2c1.mediumインスタンスで実行されているMySQLサーバーがあります。

このMySQLサーバーは、AmazonEC2にもあるいくつかのWebサーバーで実行されているいくつかのアプリケーションによって最大500/psでクエリされます。

以下に示すように、サーバーの平均負荷とプロセッサのアイドル時間は問題ないように見えますが、現在、私を不安にさせ、心配していることがあります。これは、サーバーが経験している高いiowaitです。

私が非常に心配したもう1つの数値は、1秒あたりのiostatの転送数(tps)であり、ほとんどの場合450を超えています。このトピックについて調査した後、EBSボリュームの質問が多すぎると言う人がいました: https://forums.aws.Amazon.com/thread.jspa?threadID=30769

ちなみに、以下に表示されるコマンド出力は、ピーク時にキャプチャされませんでした。これが、サーバーがほとんどの場合に動作/実行する方法です。

さて、すべてが言った、ここに私の質問があります:

1- RAIDアーキテクチャ(RAID 0と言います)への移行を検討する時期ですか?

2- MySQL Clusterなどのクラスタリングソリューションに時間を費やす必要がありますか?

3-そのようなシナリオが私たちのアプリに大きな影響を与えていると思いますか? RAID 0やクラスターソリューションに移行した場合、パフォーマンスは大幅に向上しますか? (これまでのところ、アプリは満足しているようですが、もっと満足できるでしょうか?)

さらに詳しい情報が必要な場合はお知らせください。

~ # uptime 
 12:34:14 up 2 days,  4:06,  1 user,  load average: 2.24, 1.90, **1.84**

########################################################

~ # vmstat 5

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------

 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id **wa** st

 0  1     52  11168  16420 1498728    0    0  4586   231   11   81  6  3 52 39  0

 2  1     52  10460  16320 1499588    0    0 11631   397 3194 4319 10  4 47 39  0

 4  1     52  11448  16064 1499156    0    0 12231   592 2301 3331  9  5 50 36  0

 4  0     52  10328  16068 1500176    0    0  8578   392 2131 2745  8  6 49 37  0

 0  1     52  11164  15732 1499928    0    0  9604   578 2609 3510  7  4 49 40  0

 0  1     52  10824  15768 1499836    0    0  5038   634 1912 2509  8  3 47 42  0

 3  1     52  12040  15888 1498096    0    0  5068   204 1927 2531 10  8 45 37  0

 8  2     52  11252  15784 1499272    0    0  8521   390 2437 3100 14 15 39 31  0

 1  2     52  11436  15724 1499748    0    0  8287   401 2159 3113 11 10 42 36  1

 0  1     52  12016  15704 1498752    0    0 11576   499 3324 3984 16 17 31 36  0

 1  1     52  10536  15664 1500508    0    0  8430   718 2686 3265 15 14 37 34  0

 1  1     52  10300  15676 1500744    0    0 10186   720 2488 3488 16  5 45 34  0

########################################################

~ # iostat -dm 5 /dev/sdf 
Linux 2.6.21.7-2.fc8xen (database-new)  01/20/12

Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn

sdf             464.81         8.84         0.33    1658860      61390

Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn

sdf             402.20         7.39         0.43         36          2

Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn

sdf             431.40         7.74         0.32         38          1

Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn

sdf             461.40         8.26         0.39         41          1

Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn

sdf             475.65         9.20         0.29         46          1

Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn

sdf             534.80         9.82         0.52         49          2

Device:            tps    MB_read/s    MB_wrtn/s    MB_read    MB_wrtn

sdf             526.60         9.97         0.52         49          2

########################################################

~ # iostat -mdx 5 /dev/sdf 

Device:         rrqm/s   wrqm/s   r/s   w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await  svctm  %util

sdf              22.21    46.28 427.47 37.54     8.84     0.33    40.38     1.78    3.82   1.72  79.87

Device:         rrqm/s   wrqm/s   r/s   w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await  svctm  %util

sdf              22.36    80.04 450.30 60.48     9.29     0.55    39.44     1.45    2.85   1.58  80.48

Device:         rrqm/s   wrqm/s   r/s   w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await  svctm  %util

sdf              23.40    43.60 370.60 47.00     7.75     0.35    39.76     1.45    3.47   1.97  82.08

Device:         rrqm/s   wrqm/s   r/s   w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await  svctm  %util

sdf              20.20    33.20 382.60 29.60     8.02     0.25    41.05     1.31    3.17   2.11  87.12

Device:         rrqm/s   wrqm/s   r/s   w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await  svctm  %util

sdf              28.80    35.20 422.40 33.40     9.04     0.27    41.80     1.45    3.19   1.95  88.96

Device:         rrqm/s   wrqm/s   r/s   w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await  svctm  %util

sdf              14.20    45.00 291.80 51.40     5.97     0.38    37.86     1.45    4.22   2.50  85.68

Device:         rrqm/s   wrqm/s   r/s   w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await  svctm  %util

sdf              19.16    56.89 535.33 41.32    11.44     0.38    42.00     1.49    2.59   1.53  88.46

Device:         rrqm/s   wrqm/s   r/s   w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await  svctm  %util

sdf              20.40    81.40 233.00 64.40     4.86     0.57    37.39     1.74    5.84   3.18  94.72
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
long_query_time=1
key_buffer = 64M
thread_cache_size = 30
table_cache = 1024
table_definition_cache = 512
query_cache_type = 1
query_cache_size = 64M
tmp_table_size = 64M
max_heap_table_size = 64M
innodb_buffer_pool_size = 512M
old_passwords=1
max_connections=400
wait_timeout=30

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[ndbd]
connect-string="nodeid=2;Host=localhost:1186"

[ndb_mgm]
connect-string="Host=localhost:1186"
~ # ./tuning-primer.sh 

    -- MYSQL PERFORMANCE TUNING PRIMER --
         - By: Matthew Montgomery -

MySQL Version 5.1.52 i686

Uptime = 0 days 1 hrs 1 min 1 sec
Avg. qps = 517
Total Questions = 1894942
Threads Connected = 94

Warning: Server has not been running for at least 48hrs.
It may not be safe to use these recommendations

To find out more information on how each of these
runtime variables effects performance visit:
http://dev.mysql.com/doc/refman/5.1/en/server-system-variables.html
Visit http://www.mysql.com/products/enterprise/advisors.html
for info about MySQL's Enterprise Monitoring and Advisory Service

SLOW QUERIES
The slow query log is NOT enabled.
Current long_query_time = 1.000000 sec.
You have 207 out of 1894981 that take longer than 1.000000 sec. to complete
Your long_query_time seems to be fine

BINARY UPDATE LOG
The binary update log is NOT enabled.
You will not be able to do point in time recovery
See http://dev.mysql.com/doc/refman/5.1/en/point-in-time-recovery.html

WORKER THREADS
Current thread_cache_size = 30
Current threads_cached = 8
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine

MAX CONNECTIONS
Current max_connections = 400
Current threads_connected = 93
Historic max_used_connections = 195
The number of used connections is 48% of the configured maximum.
Your max_connections variable seems to be fine.

INNODB STATUS
Current InnoDB index space = 1.33 G
Current InnoDB data space = 5.04 G
Current InnoDB buffer pool free = 0 %
Current innodb_buffer_pool_size = 512 M
Depending on how much space your innodb indexes take up it may be safe
to increase this value to up to 2 / 3 of total system memory

MEMORY USAGE
Max Memory Ever Allocated : 1.13 G
Configured Max Per-thread Buffers : 1.04 G
Configured Max Global Buffers : 642 M
Configured Max Memory Limit : 1.67 G
Physical Memory : 1.70 G

Max memory limit exceeds 90% of physical memory

KEY BUFFER
Current MyISAM index space = 379 M
Current key_buffer_size = 64 M
Key cache miss rate is 1 : 162
Key buffer free ratio = 80 %
Your key_buffer_size seems to be fine

QUERY CACHE
Query cache is enabled
Current query_cache_size = 64 M
Current query_cache_used = 43 M
Current query_cache_limit = 1 M
Current Query cache Memory fill ratio = 67.44 %
Current query_cache_min_res_unit = 4 K
MySQL won't cache query results that are larger than query_cache_limit in size

SORT OPERATIONS
Current sort_buffer_size = 2 M
Current read_rnd_buffer_size = 256 K
Sort buffer seems to be fine

JOINS
Current join_buffer_size = 132.00 K
You have had 4013 queries where a join could not use an index properly
You should enable "log-queries-not-using-indexes"
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 accommodate larger joins in one pass.

Note! This script will still suggest raising the join_buffer_size when
ANY joins not using indexes are found.

OPEN FILES LIMIT
Current open_files_limit = 2458 files
The open_files_limit should typically be set to at least 2x-3x
that of table_cache if you have heavy MyISAM usage.
Your open_files_limit value seems to be fine

TABLE CACHE
Current table_open_cache = 1024 tables
Current table_definition_cache = 512 tables
You have a total of 45237 tables
You have 1024 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
You should probably increase your table_definition_cache value.

TEMP TABLES
Current max_heap_table_size = 64 M
Current tmp_table_size = 64 M
Of 38723 temp tables, 44% were created on disk
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.

TABLE SCANS
Current read_buffer_size = 128 K
Current table scan ratio = 537 : 1
read_buffer_size seems to be fine

TABLE LOCKING
Current Lock Wait ratio = 1 : 954
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'
If you have a high concurrency of inserts on Dynamic row-length tables
consider setting 'concurrent_insert=2'.
5

My.cnfを投稿し、InnoDBテーブルとMyISAMテーブルのどちらを使用しているか、および読み取りと書き込みが多いワークロードであるかどうかを確認すると役立ちます。それ以外の場合は、推測を行っているだけです。これが私のものです:

まず、クエリが適切にインデックス付けされていることを確認します。 MySQLデータベースのI/Oが高いのは、同時実行性が非常に高いか、サーバーの調整が不十分であるか、テーブルまたはインデックスの完全スキャンを実行する必要があるクエリの実行が不十分であることが原因です。パフォーマンスの低いクエリを見つける方法に関するヒントは、私の Ideeliの技術ブログへの投稿 にあります。

My.cnfを確認してください。 InnoDBを使用している場合は、innodb_buffer_pool_sizeとinnodb_log_file_sizeが十分に大きいことを確認してください。 EBSにはこのような可変レイテンシーがあるため、innodb_log_file_sizeを最大化すると、パフォーマンスが大幅に向上する可能性があります。 MyISAMを使用している場合(使用すべきではありません)、key_bufferのサイズが十分に大きいことを確認してください。

クエリが適切に最適化されており、サーバーが適切に調整されていると確信できる場合は、次の項目に進むことができます。 ext3はデータベースには理想的とは言えません。これの主な理由の1つは、ext3では一度に1つのスレッドのみがiノードを更新できることです(このためのドキュメントを見つけようとします)。 innodb-file-per-tableを使用して実行していない場合、これはibdataファイルで大量のファイルシステムの競合があることを意味します。 xfsにはこの制限がなく、データベースワークロードに対してはるかに優れたパフォーマンス(ソースが必要)であることが示されています。

Xfsに変更できない場合は、innodb-file-per-tableを使用していることを確認し、少なくとも、マウントにnoatime、nodiratimeがあることを確認してください。

次に、インスタンスサイズについて説明します。 c1.mediumは、データセットが小さい場合を除いて、ほとんどのデータベースにとって理想的なインスタンスサイズではありません。 MySQLは通常、計算能力よりもメモリの恩恵を受けます。 c1.mediumには1.7GBのRAMしかありません!データセットの大きさはどれくらいですか?一般に、非常にまれなケースを除いて、m1.large(7.5GBのRAMを搭載)はc1.mediumよりもパフォーマンスが優れています。また、1時間あたり0.34ドルで、2倍の費用がかかります。

次に、EBSボリュームのRAIDに移ります。はい、RAIDはIOPSを大幅に向上させます。 (インスタンスサイズが大きくなるように)。 RAID0をしないでください...少なくともデータに関心がある場合は。 私のブログ2011年のPercona Live NYCここではserverfault の講演者として、これについて多くの場所で説明しました。短いバージョンでは、EBSボリュームは異常な方法で失敗し、セットからボリュームを削除できることは、サーバーの機会、特に一部のサイトが数日間オフラインであった2011年の大規模なEBS停止中に価値があることが証明されています... EBSの問題の影響を受けたインスタンスが数十あるにもかかわらず、午前4時に45分間オフラインでした。

ここにいくつかのベンチマークがあります MySQLを使用するRAIDEBSボリュームの場合。

最後に、 Percona Server には膨大な数のスケーラビリティの最適化があります。 ここにホワイトペーパーがあります MySQLからPerconaServerに切り替えたときの私の会社の経験について。私たちは毎日データベースのストールと停止を経験していました。 MySQLからPerconaServerに切り替えるだけで、スケーラビリティが大幅に向上したため、文字通り一晩でこの問題が解決しました。

だから、要約すると...

  • クエリを調整する
  • サーバーを調整する
  • より良い「ハードウェア」を手に入れよう
  • Ext3ではなくxfsを使用する
  • RAID0ではなくRAID10
  • MySQLからPerconaサーバーに切り替えます

MySQL Clusterに関しては、MySQLとはまったく異なる動物であり、一般的にほとんどのOLTPアプリケーションには適していません。 Galera / Percona XtraDB Cluster 新しくて興味深いクラスタリング製品もあります。ただし、これに到達する前に、たくさんのオプションがあります。ピーク時に24kqpsを提供しました。 EC2のRAID10を備えた単一のm2.4xlarge。

幸運を!

13
Aaron Brown

これは多くの企業が遭遇した問題であり、その解決策はさまざまなオンラインフォーラムでかなりよく議論されています。

通常、潜在的なIOPSを増やすために、2つ以上のEBSボリュームがRAID0アレイで結合されます。ただし、これにはリスクが伴います。ご存知のように、RAID0では、メンバーのEBSボリュームの1つに問題が発生し、データがトーストされるだけです。そのため、より回復力のあるRAIDレベル、たとえばRAID10の使用を検討することもできます。

2
EEAA

500gpsはSQLサーバーへの負荷がかなり軽いため、ディスク上に作成された一時テーブルの割合を調べて、クエリとMySQLサーバー設定の最適化を開始することをお勧めします。

1、Raid0アプローチを実行しないでください。最終的に失敗し、後悔します。

2、いいえ、1秒あたりのクエリ数が少ないため、MySQLClusterは必要ありません。

3、はい、それは確かにアプリのパフォーマンスに影響を与えます。遅いログを有効にして自分で確認できる量を測定します。

Mysqlは現在どのくらいのメモリを使用していますか?ヘッドルームは残っていますか?
そうでない場合は、より大きなインスタンスへの切り替えを検討し、sundryのmysqlチューニングスクリプトを使用して設定の最適化を開始する必要があります。
http://www.day32.com/MySQL/tuning-primer.sh

1
Niko S P

3-そのようなシナリオが私たちのアプリに大きな影響を与えていると思いますか? RAID 0やクラスターソリューションに移行した場合、パフォーマンスは大幅に向上しますか?

SQLサーバーを実行しているので、クエリが迅速に処理されるかどうかを知る代わりに、SQLサーバーのメトリックを確認する方が理にかなっています。 1桁の平均リクエスト待機時間(待機)を見ると、I/Oはまだそれほど問題にはならないと思います。

また、主に表示されるのは読み取り負荷であるため、キャッシュを大きくするか、RAM)の量を増やし、MySQLインスタンスのキャッシュパラメータを調整することで、負荷を減らすことができます。より多くのI/Oを処理するためにストレージを変更するよりも、パフォーマンスへの影響が大幅に大きくなります。

1
the-wabbit