socket_instances 表提供对 MySQL 服务器活动连接的实时快照。该表包含每个 TCP/IP 或 Unix 套接字文件连接对应的一行。此表中提供的信息提供对服务器活动连接的实时快照。(其他信息可在套接字摘要表中找到,包括网络活动,如套接字操作以及传输和接收的字节数;请参见 第 29.12.20.9 节,“套接字摘要表”)。
mysql> SELECT * FROM performance_schema.socket_instances\G
*************************** 1. row ***************************
EVENT_NAME: wait/io/socket/sql/server_unix_socket
OBJECT_INSTANCE_BEGIN: 4316619408
THREAD_ID: 1
SOCKET_ID: 16
IP:
PORT: 0
STATE: ACTIVE
*************************** 2. row ***************************
EVENT_NAME: wait/io/socket/sql/client_connection
OBJECT_INSTANCE_BEGIN: 4316644608
THREAD_ID: 21
SOCKET_ID: 39
IP: 127.0.0.1
PORT: 55233
STATE: ACTIVE
*************************** 3. row ***************************
EVENT_NAME: wait/io/socket/sql/server_tcpip_socket
OBJECT_INSTANCE_BEGIN: 4316699040
THREAD_ID: 1
SOCKET_ID: 14
IP: 0.0.0.0
PORT: 50603
STATE: ACTIVE套接字仪器具有 wait/io/socket/sql/ 形式的名称,并按以下方式使用socket_type
服务器为其支持的每个网络协议都有一个监听套接字。与用于 TCP/IP 或 Unix 套接字文件连接的监听套接字关联的仪器具有
socket_type值server_tcpip_socket或server_unix_socket,分别表示。当监听套接字检测到连接时,服务器将连接传输到由单独线程管理的新套接字。新连接线程的仪器具有
socket_type值client_connection。当连接终止时,
socket_instances表中与其对应的行将被删除。
socket_instances 表具有以下列
EVENT_NAME生成事件的
wait/io/socket/*仪器的名称。这是setup_instruments表中的NAME值。仪器名称可能包含多个部分,并形成一个层次结构,如 第 29.6 节,“Performance Schema 仪器命名约定” 中所述。OBJECT_INSTANCE_BEGIN此列唯一标识套接字。该值是内存中对象的地址。
THREAD_ID服务器分配的内部线程标识符。每个套接字都由单个线程管理,因此每个套接字都可以映射到一个线程,该线程可以映射到一个服务器进程。
SOCKET_ID分配给套接字的内部文件句柄。
IP客户端 IP 地址。该值可以是 IPv4 或 IPv6 地址,或者为空白以表示 Unix 套接字文件连接。
PORTTCP/IP 端口号,介于 0 到 65535 之间。
STATE套接字状态,可以是
IDLE或ACTIVE。活动套接字的等待时间使用相应的套接字仪器跟踪。空闲套接字的等待时间使用idle仪器跟踪。如果套接字正在等待来自客户端的请求,则套接字处于空闲状态。当套接字变为空闲状态时,
socket_instances表中跟踪套接字的事件行将从状态ACTIVE切换到状态IDLE。EVENT_NAME值保持为wait/io/socket/*,但仪器计时将暂停。相反,将在events_waits_current表中生成一个事件,其EVENT_NAME值为idle。当收到下一个请求时,
idle事件将终止,套接字实例将从IDLE切换到ACTIVE,并且套接字仪器的计时将恢复。
The socket_instances table has these indexes
Primary key on (
OBJECT_INSTANCE_BEGIN)Index on (
THREAD_ID)Index on (
SOCKET_ID)Index on (
IP,PORT)
TRUNCATE TABLE is not permitted for the socket_instances table.
The IP:PORT column combination value identifies the connection. This combination value is used in the OBJECT_NAME column of the events_waits_ tables, to identify the connection from which socket events comexxx
For the Unix domain listener socket (
server_unix_socket), the port is 0, and the IP is''.For client connections via the Unix domain listener (
client_connection), the port is 0, and the IP is''.For the TCP/IP server listener socket (
server_tcpip_socket), the port is always the master port (for example, 3306), and the IP is always0.0.0.0.For client connections via the TCP/IP listener (
client_connection), the port is whatever the server assigns, but never 0. The IP is the IP of the originating host (127.0.0.1or::1for the local host)