MySQLのスレッドとか接続数とか ============================= {{tag: mysql, performance}} オーバーヘッドをなくしてパフォーマンスを向上する ------------------------------------------------ {{TOC 3-}} ### 最大接続数設定 mysql> show global variables like 'max_connections'; +-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | max_connections | 150 | +-----------------+-------+ 1 row in set (0.00 sec) ### 起動してからの累積接続数 mysql> show global status like 'Connections'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | Connections | 11862 | +---------------+-------+ 1 row in set (0.00 sec) ### 起動してからこれまでの最大同時接続数 mysql> show global status like 'Max_used_connections'; +----------------------+-------+ | Variable_name | Value | +----------------------+-------+ | Max_used_connections | 94 | +----------------------+-------+ 1 row in set (0.00 sec) ### threads 関連ステータス mysql> show global status like 'Thread_%'; +-------------------+-------+ | Variable_name | Value | +-------------------+-------+ | Threads_cached | 1 | | Threads_connected | 1 | | Threads_created | 2 | | Threads_running | 1 | +-------------------+-------+ 4 rows in set (0.00 sec) * Threads_cached キャッシュされているスレッド数(スレッドは使いまわされる) * Threads_connected 現在の接続数 * Threads_created 接続を処理するために生成されたスレッド数(この値が増えまくるなら、cached が足りていない) * Threads_running スリープ状態になっていないスレッドの数 Threads_cached + Threads_connected が 以下の値より小さければ想定内なので問題なし。 mysql> show global variables like 'thread_cache_size'; +-------------------+-------+ | Variable_name | Value | +-------------------+-------+ | thread_cache_size | 5 | +-------------------+-------+ 1 row in set (0.00 sec) {{amazon: MySQL}}