如何测量 MySQL 服务器的当前负载?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1504608/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to measure current load of MySQL server?
提问by erotsppa
How to measure current load of MySQL server? I know I can measure different things like CPU usage, RAM usage, disk IO etc but is there a generic load measure for example the server is at 40% load etc?
如何测量 MySQL 服务器的当前负载?我知道我可以测量不同的东西,比如 CPU 使用率、RAM 使用率、磁盘 IO 等,但是否有通用的负载测量,例如服务器负载为 40% 等?
采纳答案by user87400
with top or htop you can follow the usage in Linux realtime
使用 top 或 htop 您可以实时跟踪 Linux 中的使用情况
回答by dcrosta
The notion of "40% load" is not really well-defined. Your particular application may react differently to constraints on different resources. Applications will typically be bound by one of three factors: available (physical) memory, available CPU time, and disk IO.
“40% 负载”的概念并不是很明确。您的特定应用程序可能会对不同资源的约束做出不同的反应。应用程序通常会受到以下三个因素之一的约束:可用(物理)内存、可用 CPU 时间和磁盘 IO。
On Linux (or possibly other *NIX) systems, you can get a snapshot of these with vmstat
, or iostat
(which provides more detail on disk IO).
在 Linux(或可能的其他 *NIX)系统上,您可以使用vmstat
, 或iostat
(提供有关磁盘 IO 的更多详细信息)获取这些快照。
However, to connect these to "40% load", you need to understand your database's performance characteristics under typical load. The best way to do this is to test with typical queries under varying amounts of load, until you observe response times increasing dramatically (this will mean you've hit a bottleneck in memory, CPU, or disk). This load should be considered your critical level, which you do not want to exceed.
但是,要将这些连接到“40% 负载”,您需要了解数据库在典型负载下的性能特征。执行此操作的最佳方法是在不同负载量下使用典型查询进行测试,直到您观察到响应时间急剧增加(这意味着您遇到了内存、CPU 或磁盘瓶颈)。此负载应视为您不想超过的临界水平。
回答by Playboy
is there a generic load measure for example the server is at 40% load ?
是否有通用的负载措施,例如服务器处于 40% 的负载?
Yes! there is:
是的!有:
SELECT LOAD_FILE("/proc/loadavg")
Works on a linux machine. It displays the system load averages for the past 1, 5, and 15 minutes.
在 linux 机器上工作。它显示过去 1、5 和 15 分钟的系统负载平均值。
System load averages is the average number of processes that are either in a runnable or uninterruptable state. A process in a runnable state is either using the CPU or waiting to use the CPU. A process in uninterruptable state is waiting for some I/O access, eg waiting for disk. The averages are taken over the three time intervals. Load averages are not normalized for the number of CPUs in a system, so a load average of 1 means a single CPU system is loaded all the time while on a 4 CPU system it means it was idle 75% of the time.
系统负载平均值是处于可运行或不可中断状态的平均进程数。处于可运行状态的进程要么正在使用 CPU,要么正在等待使用 CPU。处于不可中断状态的进程正在等待某些 I/O 访问,例如等待磁盘。取三个时间间隔的平均值。负载平均值并未针对系统中的 CPU 数量进行标准化,因此负载平均值为 1 意味着单个 CPU 系统始终处于加载状态,而在 4 个 CPU 系统上则意味着它有 75% 的时间处于空闲状态。
So if you want to normalize you need to count de number of cpu's also.
因此,如果您想标准化,您还需要计算 cpu 的数量。
you can do that too with
你也可以这样做
SELECT LOAD_FILE("/proc/cpuinfo")
see also 'man proc'
另见“man proc”
回答by whatnick
回答by Mohammad
aside from all the good answers on this page (SHOW GLOBAL STATUS, VMSTAT, TOP...) there is also a very simple to use tool written by Jeremy Zawodny, it is perfect for non-admin users. It is called "mytop". more info @ http://jeremy.zawodny.com/mysql/mytop/
除了此页面上的所有好答案(SHOW GLOBAL STATUS、VMSTAT、TOP...)之外,还有一个由 Jeremy Zawodny 编写的非常易于使用的工具,它非常适合非管理员用户。它被称为“mytop”。更多信息@ http://jeremy.zawodny.com/mysql/mytop/
回答by Rayyan
Hi friend as per my research we have some command like
嗨,朋友,根据我的研究,我们有一些命令,例如
MYTOP
: open source program written using PERL languageMTOP
: also an open source program written on PERL, It works same as MYTOP but it monitors the queries which are taking longer time and kills them after specific time.
MYTOP
: 使用PERL语言编写的开源程序MTOP
: 也是一个用 PERL 编写的开源程序,它的工作原理与 MYTOP 相同,但它监视需要更长时间的查询并在特定时间后终止它们。