threads 表包含每个服务器线程的一行。每行包含有关线程的信息,并指示是否为其启用监控。要让 Performance Schema 监控线程,必须满足以下条件:The threads table contains a row
for each server thread. Each row contains information about a
thread and indicates whether monitoring is enabled for it. For
the Performance Schema to monitor a thread, these things must be
true:
该
thread_instrumentationconsumer in thesetup_consumerstable must beYES.Thethread_instrumentationconsumer in thesetup_consumerstable must beYES.threads.INSTRUMENTED列必须为YES。Thethreads.INSTRUMENTEDcolumn must beYES.监控仅针对那些由在
setup_instruments表中启用的仪器产生的线程事件进行。Monitoring occurs only for those thread events produced from instruments that are enabled in thesetup_instrumentstable.
threads 表还指示每个服务器线程是否执行历史事件记录。这包括等待、阶段、语句和事务事件,并影响对这些表的记录:The threads table also indicates
for each server thread whether to perform historical event
logging. This includes wait, stage, statement, and transaction
events and affects logging to these tables:
events_waits_history events_waits_history_long events_stages_history events_stages_history_long events_statements_history events_statements_history_long events_transactions_history events_transactions_history_long
要进行历史事件记录,以下条件必须为真:For historical event logging to occur, these things must be true:
必须启用
setup_consumers表中与历史相关的适当消费者。例如,在events_waits_history和events_waits_history_long表中记录等待事件,需要相应的events_waits_history和events_waits_history_long消费者为YES。The appropriate history-related consumers in thesetup_consumerstable must be enabled. For example, wait event logging in theevents_waits_historyandevents_waits_history_longtables requires the correspondingevents_waits_historyandevents_waits_history_longconsumers to beYES.threads.HISTORY列必须为YES。Thethreads.HISTORYcolumn must beYES.只有来自在
setup_instruments表中启用的工具的线程事件才会记录日志。Logging occurs only for those thread events produced from instruments that are enabled in thesetup_instrumentstable.
对于前台线程(由客户端连接产生的线程),threads 表中 INSTRUMENTED 和 HISTORY 列的初始值取决于与线程关联的用户帐户是否与 setup_actors 表中的任何行匹配。值来自匹配的 setup_actors 表行的 ENABLED 和 HISTORY 列。For foreground threads (resulting from client connections), the
initial values of the INSTRUMENTED and
HISTORY columns in
threads table rows are determined
by whether the user account associated with a thread matches any
row in the setup_actors table. The
values come from the ENABLED and
HISTORY columns of the matching
setup_actors table row.
对于后台线程,没有关联的用户。INSTRUMENTED 和 HISTORY 默认都是 YES,并且不参考 setup_actors。For background threads, there is no associated user.
INSTRUMENTED and HISTORY
are YES by default and
setup_actors is not consulted.
初始的 setup_actors 内容如下:The initial setup_actors contents
look like this:
mysql> SELECT * FROM performance_schema.setup_actors;
+------+------+------+---------+---------+
| HOST | USER | ROLE | ENABLED | HISTORY |
+------+------+------+---------+---------+
| % | % | % | YES | YES |
+------+------+------+---------+---------+
HOST 和 USER 列应包含字面意义的主机名或用户名,或者使用 '%' 来匹配任意名称。The HOST and USER columns
should contain a literal host or user name, or
'%' to match any name.
ENABLED 和 HISTORY 列表示是否为匹配的线程启用检测和历史事件记录,这取决于之前描述的其他条件。The ENABLED and HISTORY
columns indicate whether to enable instrumentation and
historical event logging for matching threads, subject to the
other conditions described previously.
当性能模式在 setup_actors 中为每个新的前台线程检查匹配时,它会先尝试找到更具体的匹配,使用 USER 和 HOST 列(ROLE 未使用):When the Performance Schema checks for a match for each new
foreground thread in setup_actors, it tries
to find more specific matches first, using the
USER and HOST columns
(ROLE is unused):
具有
USER='和literal'HOST='的行。Rows withliteral'USER='andliteral'HOST='.literal'具有
USER='和literal'HOST='%'的行。Rows withUSER='andliteral'HOST='%'.行的
USER='%'和HOST='。Rows withliteral'USER='%'andHOST='.literal'行的
USER='%'和HOST='%'。Rows withUSER='%'andHOST='%'.
匹配的顺序很重要,因为不同匹配的 setup_actors 行可能具有不同的 USER 和 HOST 值。这使得可以根据 ENABLED 和 HISTORY 列的值,对每个主机、用户或账户(用户和主机组合)选择性地应用仪器和历史事件记录:The order in which matching occurs matters because different
matching setup_actors rows can have
different USER and HOST
values. This enables instrumenting and historical event logging
to be applied selectively per host, user, or account (user and
host combination), based on the ENABLED and
HISTORY column values:
当最佳匹配是一行
ENABLED=YES时,该线程的INSTRUMENTED值变为YES。当最佳匹配是一行HISTORY=YES时,该线程的HISTORY值变为YES。When the best match is a row withENABLED=YES, theINSTRUMENTEDvalue for the thread becomesYES. When the best match is a row withHISTORY=YES, theHISTORYvalue for the thread becomesYES.当最佳匹配是一行
ENABLED=NO时,该线程的INSTRUMENTED值变为NO。当最佳匹配是一行HISTORY=NO时,该线程的HISTORY值变为NO。When the best match is a row withENABLED=NO, theINSTRUMENTEDvalue for the thread becomesNO. When the best match is a row withHISTORY=NO, theHISTORYvalue for the thread becomesNO.当未找到匹配时,该线程的
INSTRUMENTED和HISTORY值均变为NO。When no match is found, theINSTRUMENTEDandHISTORYvalues for the thread becomeNO.
setup_actors 行中的 ENABLED 和 HISTORY 列可以独立设置为 YES 或 NO。这意味着您可以单独启用监控,而不必与是否收集历史事件绑定在一起。The ENABLED and HISTORY
columns in setup_actors rows can be
set to YES or NO
independent of one another. This means you can enable
instrumentation separately from whether you collect historical
events.
默认情况下,监控和历史事件收集会针对所有新的前台线程启用,因为 setup_actors 表最初包含一行,其 HOST 和 USER 都为 '%'。要执行更有限的匹配,例如仅为某些前台线程启用监控,必须修改此行,因为它匹配任何连接,并为更具体的 HOST/USER 组合添加行。By default, monitoring and historical event collection are
enabled for all new foreground threads because the
setup_actors table initially
contains a row with '%' for both
HOST and USER. To perform
more limited matching such as to enable monitoring only for some
foreground threads, you must change this row because it matches
any connection, and add rows for more specific
HOST/USER combinations.
假设你将 setup_actors 修改如下:Suppose that you modify
setup_actors as follows:
UPDATE performance_schema.setup_actors
SET ENABLED = 'NO', HISTORY = 'NO'
WHERE HOST = '%' AND USER = '%';
INSERT INTO performance_schema.setup_actors
(HOST,USER,ROLE,ENABLED,HISTORY)
VALUES('localhost','joe','%','YES','YES');
INSERT INTO performance_schema.setup_actors
(HOST,USER,ROLE,ENABLED,HISTORY)
VALUES('hosta.example.com','joe','%','YES','NO');
INSERT INTO performance_schema.setup_actors
(HOST,USER,ROLE,ENABLED,HISTORY)
VALUES('%','sam','%','NO','YES');
UPDATE 语句将默认匹配更改为禁用仪器化和历史事件收集。INSERT 语句为更具体的匹配添加行。The UPDATE statement changes the
default match to disable instrumentation and historical event
collection. The INSERT statements
add rows for more specific matches.
现在性能模式(Performance Schema)决定如何为新连接线程设置 INSTRUMENTED 和 HISTORY 值,如下所示:Now the Performance Schema determines how to set the
INSTRUMENTED and HISTORY
values for new connection threads as follows:
如果
joe从本地主机连接,则该连接匹配第一个插入的行。该线程的INSTRUMENTED和HISTORY值将变为YES。Ifjoeconnects from the local host, the connection matches the first inserted row. TheINSTRUMENTEDandHISTORYvalues for the thread becomeYES.如果
joe从hosta.example.com连接,则连接匹配第二个插入的行。线程的INSTRUMENTED值变为YES,HISTORY值变为NO。Ifjoeconnects fromhosta.example.com, the connection matches the second inserted row. TheINSTRUMENTEDvalue for the thread becomesYESand theHISTORYvalue becomesNO.如果
joe从任何其他主机连接,则没有匹配。线程的INSTRUMENTED和HISTORY值变为NO。Ifjoeconnects from any other host, there is no match. TheINSTRUMENTEDandHISTORYvalues for the thread becomeNO.如果
sam从任何主机连接,则连接匹配第三个插入的行。线程的INSTRUMENTED值变为NO,HISTORY值变为YES。Ifsamconnects from any host, the connection matches the third inserted row. TheINSTRUMENTEDvalue for the thread becomesNOand theHISTORYvalue becomesYES.对于任何其他连接,
HOST和USER设置为'%'的行会匹配。现在此行的ENABLED和HISTORY设置为NO,因此线程的INSTRUMENTED和HISTORY值将变为NO。For any other connection, the row withHOSTandUSERset to'%'matches. This row now hasENABLEDandHISTORYset toNO, so theINSTRUMENTEDandHISTORYvalues for the thread becomeNO.
对 setup_actors 表的修改仅影响修改后创建的前台线程,而不会影响现有线程。要影响现有线程,请修改 threads 表行的 INSTRUMENTED 和 HISTORY 列。Modifications to the setup_actors
table affect only foreground threads created subsequent to the
modification, not existing threads. To affect existing threads,
modify the INSTRUMENTED and
HISTORY columns of
threads table rows.