### 23.6.13 NDB API 统计计数器和变量

[](<>)[](<>)[](<>)

与执行或影响的操作有关的多种类型的统计计数器[`钕铁硼`](https://dev.mysql.com/doc/ndbapi/en/ndb-ndb.html)对象可用。此类操作包括启动和关闭（或中止）交易；主键和唯一键操作；表、范围和修剪扫描；线程在等待各种操作完成时被阻塞；以及发送和接收的数据和事件`NDBCLUSTER`.每当进行 NDB API 调用或数据节点发送或接收数据时，计数器都会在 NDB 内核内部递增。[**mysqld**](mysqld.html)将这些计数器公开为系统状态变量；它们的值可以在输出中读取[`显示状态`](show-status.html)，或通过查询性能模式[`会话状态`](performance-schema-status-variable-tables.html)要么[`全局状态`](performance-schema-status-variable-tables.html)桌子。通过比较语句操作之前和之后的值[`新开发银行`](mysql-cluster.html)表，您可以观察在 API 级别上采取的相应操作，以及执行语句的成本。

您可以使用以下命令列出所有这些状态变量[`显示状态`](show-status.html)陈述：

```
mysql> SHOW STATUS LIKE 'ndb_api%';
+----------------------------------------------+-----------+
| Variable_name                                | Value     |
+----------------------------------------------+-----------+
| Ndb_api_wait_exec_complete_count             | 297       |
| Ndb_api_wait_scan_result_count               | 0         |
| Ndb_api_wait_meta_request_count              | 321       |
| Ndb_api_wait_nanos_count                     | 228438645 |
| Ndb_api_bytes_sent_count                     | 33988     |
| Ndb_api_bytes_received_count                 | 66236     |
| Ndb_api_trans_start_count                    | 148       |
| Ndb_api_trans_commit_count                   | 148       |
| Ndb_api_trans_abort_count                    | 0         |
| Ndb_api_trans_close_count                    | 148       |
| Ndb_api_pk_op_count                          | 151       |
| Ndb_api_uk_op_count                          | 0         |
| Ndb_api_table_scan_count                     | 0         |
| Ndb_api_range_scan_count                     | 0         |
| Ndb_api_pruned_scan_count                    | 0         |
| Ndb_api_scan_batch_count                     | 0         |
| Ndb_api_read_row_count                       | 147       |
| Ndb_api_trans_local_read_row_count           | 37        |
| Ndb_api_adaptive_send_forced_count           | 3         |
| Ndb_api_adaptive_send_unforced_count         | 294       |
| Ndb_api_adaptive_send_deferred_count         | 0         |
| Ndb_api_event_data_count                     | 0         |
| Ndb_api_event_nondata_count                  | 0         |
| Ndb_api_event_bytes_count                    | 0         |
| Ndb_api_wait_exec_complete_count_slave       | 0         |
| Ndb_api_wait_scan_result_count_slave         | 0         |
| Ndb_api_wait_meta_request_count_slave        | 0         |
| Ndb_api_wait_nanos_count_slave               | 0         |
| Ndb_api_bytes_sent_count_slave               | 0         |
| Ndb_api_bytes_received_count_slave           | 0         |
| Ndb_api_trans_start_count_slave              | 0         |
| Ndb_api_trans_commit_count_slave             | 0         |
| Ndb_api_trans_abort_count_slave              | 0         |
| Ndb_api_trans_close_count_slave              | 0         |
| Ndb_api_pk_op_count_slave                    | 0         |
| Ndb_api_uk_op_count_slave                    | 0         |
| Ndb_api_table_scan_count_slave               | 0         |
| Ndb_api_range_scan_count_slave               | 0         |
| Ndb_api_pruned_scan_count_slave              | 0         |
| Ndb_api_scan_batch_count_slave               | 0         |
| Ndb_api_read_row_count_slave                 | 0         |
| Ndb_api_trans_local_read_row_count_slave     | 0         |
| Ndb_api_adaptive_send_forced_count_slave     | 0         |
| Ndb_api_adaptive_send_unforced_count_slave   | 0         |
| Ndb_api_adaptive_send_deferred_count_slave   | 0         |
| Ndb_api_wait_exec_complete_count_replica     | 0         |
| Ndb_api_wait_scan_result_count_replica       | 0         |
| Ndb_api_wait_meta_request_count_replica      | 0         |
| Ndb_api_wait_nanos_count_replica             | 0         |
| Ndb_api_bytes_sent_count_replica             | 0         |
| Ndb_api_bytes_received_count_replica         | 0         |
| Ndb_api_trans_start_count_replica            | 0         |
| Ndb_api_trans_commit_count_replica           | 0         |
| Ndb_api_trans_abort_count_replica            | 0         |
| Ndb_api_trans_close_count_replica            | 0         |
| Ndb_api_pk_op_count_replica                  | 0         |
| Ndb_api_uk_op_count_replica                  | 0         |
| Ndb_api_table_scan_count_replica             | 0         |
| Ndb_api_range_scan_count_replica             | 0         |
| Ndb_api_pruned_scan_count_replica            | 0         |
| Ndb_api_scan_batch_count_replica             | 0         |
| Ndb_api_read_row_count_replica               | 0         |
| Ndb_api_trans_local_read_row_count_replica   | 0         |
| Ndb_api_adaptive_send_forced_count_replica   | 0         |
| Ndb_api_adaptive_send_unforced_count_replica | 0         |
| Ndb_api_adaptive_send_deferred_count_replica | 0         |
| Ndb_api_event_data_count_injector            | 0         |
| Ndb_api_event_nondata_count_injector         | 0         |
| Ndb_api_event_bytes_count_injector           | 0         |
| Ndb_api_wait_exec_complete_count_session     | 0         |
| Ndb_api_wait_scan_result_count_session       | 0         |
| Ndb_api_wait_meta_request_count_session      | 0         |
| Ndb_api_wait_nanos_count_session             | 0         |
| Ndb_api_bytes_sent_count_session             | 0         |
| Ndb_api_bytes_received_count_session         | 0         |
| Ndb_api_trans_start_count_session            | 0         |
| Ndb_api_trans_commit_count_session           | 0         |
| Ndb_api_trans_abort_count_session            | 0         |
| Ndb_api_trans_close_count_session            | 0         |
| Ndb_api_pk_op_count_session                  | 0         |
| Ndb_api_uk_op_count_session                  | 0         |
| Ndb_api_table_scan_count_session             | 0         |
| Ndb_api_range_scan_count_session             | 0         |
| Ndb_api_pruned_scan_count_session            | 0         |
| Ndb_api_scan_batch_count_session             | 0         |
| Ndb_api_read_row_count_session               | 0         |
| Ndb_api_trans_local_read_row_count_session   | 0         |
| Ndb_api_adaptive_send_forced_count_session   | 0         |
| Ndb_api_adaptive_send_unforced_count_session | 0         |
| Ndb_api_adaptive_send_deferred_count_session | 0         |
+----------------------------------------------+-----------+
90 rows in set (0.01 sec)
```

这些状态变量也可从性能模式中获得[`会话状态`](performance-schema-status-variable-tables.html)和[`全局状态`](performance-schema-status-variable-tables.html)表，如下所示：

```
mysql> SELECT * FROM performance_schema.session_status
    ->   WHERE VARIABLE_NAME LIKE 'ndb_api%';
+----------------------------------------------+----------------+
| VARIABLE_NAME                                | VARIABLE_VALUE |
+----------------------------------------------+----------------+
| Ndb_api_wait_exec_complete_count             | 617            |
| Ndb_api_wait_scan_result_count               | 0              |
| Ndb_api_wait_meta_request_count              | 649            |
| Ndb_api_wait_nanos_count                     | 335663491      |
| Ndb_api_bytes_sent_count                     | 65764          |
| Ndb_api_bytes_received_count                 | 86940          |
| Ndb_api_trans_start_count                    | 308            |
| Ndb_api_trans_commit_count                   | 308            |
| Ndb_api_trans_abort_count                    | 0              |
| Ndb_api_trans_close_count                    | 308            |
| Ndb_api_pk_op_count                          | 311            |
| Ndb_api_uk_op_count                          | 0              |
| Ndb_api_table_scan_count                     | 0              |
| Ndb_api_range_scan_count                     | 0              |
| Ndb_api_pruned_scan_count                    | 0              |
| Ndb_api_scan_batch_count                     | 0              |
| Ndb_api_read_row_count                       | 307            |
| Ndb_api_trans_local_read_row_count           | 77             |
| Ndb_api_adaptive_send_forced_count           | 3              |
| Ndb_api_adaptive_send_unforced_count         | 614            |
| Ndb_api_adaptive_send_deferred_count         | 0              |
| Ndb_api_event_data_count                     | 0              |
| Ndb_api_event_nondata_count                  | 0              |
| Ndb_api_event_bytes_count                    | 0              |
| Ndb_api_wait_exec_complete_count_slave       | 0              |
| Ndb_api_wait_scan_result_count_slave         | 0              |
| Ndb_api_wait_meta_request_count_slave        | 0              |
| Ndb_api_wait_nanos_count_slave               | 0              |
| Ndb_api_bytes_sent_count_slave               | 0              |
| Ndb_api_bytes_received_count_slave           | 0              |
| Ndb_api_trans_start_count_slave              | 0              |
| Ndb_api_trans_commit_count_slave             | 0              |
| Ndb_api_trans_abort_count_slave              | 0              |
| Ndb_api_trans_close_count_slave              | 0              |
| Ndb_api_pk_op_count_slave                    | 0              |
| Ndb_api_uk_op_count_slave                    | 0              |
| Ndb_api_table_scan_count_slave               | 0              |
| Ndb_api_range_scan_count_slave               | 0              |
| Ndb_api_pruned_scan_count_slave              | 0              |
| Ndb_api_scan_batch_count_slave               | 0              |
| Ndb_api_read_row_count_slave                 | 0              |
| Ndb_api_trans_local_read_row_count_slave     | 0              |
| Ndb_api_adaptive_send_forced_count_slave     | 0              |
| Ndb_api_adaptive_send_unforced_count_slave   | 0              |
| Ndb_api_adaptive_send_deferred_count_slave   | 0              |
| Ndb_api_wait_exec_complete_count_replica     | 0              |
| Ndb_api_wait_scan_result_count_replica       | 0              |
| Ndb_api_wait_meta_request_count_replica      | 0              |
| Ndb_api_wait_nanos_count_replica             | 0              |
| Ndb_api_bytes_sent_count_replica             | 0              |
| Ndb_api_bytes_received_count_replica         | 0              |
| Ndb_api_trans_start_count_replica            | 0              |
| Ndb_api_trans_commit_count_replica           | 0              |
| Ndb_api_trans_abort_count_replica            | 0              |
| Ndb_api_trans_close_count_replica            | 0              |
| Ndb_api_pk_op_count_replica                  | 0              |
| Ndb_api_uk_op_count_replica                  | 0              |
| Ndb_api_table_scan_count_replica             | 0              |
| Ndb_api_range_scan_count_replica             | 0              |
| Ndb_api_pruned_scan_count_replica            | 0              |
| Ndb_api_scan_batch_count_replica             | 0              |
| Ndb_api_read_row_count_replica               | 0              |
| Ndb_api_trans_local_read_row_count_replica   | 0              |
| Ndb_api_adaptive_send_forced_count_replica   | 0              |
| Ndb_api_adaptive_send_unforced_count_replica | 0              |
| Ndb_api_adaptive_send_deferred_count_replica | 0              |
| Ndb_api_event_data_count_injector            | 0              |
| Ndb_api_event_nondata_count_injector         | 0              |
| Ndb_api_event_bytes_count_injector           | 0              |
| Ndb_api_wait_exec_complete_count_session     | 0              |
| Ndb_api_wait_scan_result_count_session       | 0              |
| Ndb_api_wait_meta_request_count_session      | 0              |
| Ndb_api_wait_nanos_count_session             | 0              |
| Ndb_api_bytes_sent_count_session             | 0              |
| Ndb_api_bytes_received_count_session         | 0              |
| Ndb_api_trans_start_count_session            | 0              |
| Ndb_api_trans_commit_count_session           | 0              |
| Ndb_api_trans_abort_count_session            | 0              |
| Ndb_api_trans_close_count_session            | 0              |
| Ndb_api_pk_op_count_session                  | 0              |
| Ndb_api_uk_op_count_session                  | 0              |
| Ndb_api_table_scan_count_session             | 0              |
| Ndb_api_range_scan_count_session             | 0              |
| Ndb_api_pruned_scan_count_session            | 0              |
| Ndb_api_scan_batch_count_session             | 0              |
| Ndb_api_read_row_count_session               | 0              |
| Ndb_api_trans_local_read_row_count_session   | 0              |
| Ndb_api_adaptive_send_forced_count_session   | 0              |
| Ndb_api_adaptive_send_unforced_count_session | 0              |
| Ndb_api_adaptive_send_deferred_count_session | 0              |
+----------------------------------------------+----------------+
90 rows in set (0.01 sec)

mysql> SELECT * FROM performance_schema.global_status
    ->     WHERE VARIABLE_NAME LIKE 'ndb_api%';
+----------------------------------------------+----------------+
| VARIABLE_NAME                                | VARIABLE_VALUE |
+----------------------------------------------+----------------+
| Ndb_api_wait_exec_complete_count             | 741            |
| Ndb_api_wait_scan_result_count               | 0              |
| Ndb_api_wait_meta_request_count              | 777            |
| Ndb_api_wait_nanos_count                     | 373888309      |
| Ndb_api_bytes_sent_count                     | 78124          |
| Ndb_api_bytes_received_count                 | 94988          |
| Ndb_api_trans_start_count                    | 370            |
| Ndb_api_trans_commit_count                   | 370            |
| Ndb_api_trans_abort_count                    | 0              |
| Ndb_api_trans_close_count                    | 370            |
| Ndb_api_pk_op_count                          | 373            |
| Ndb_api_uk_op_count                          | 0              |
| Ndb_api_table_scan_count                     | 0              |
| Ndb_api_range_scan_count                     | 0              |
| Ndb_api_pruned_scan_count                    | 0              |
| Ndb_api_scan_batch_count                     | 0              |
| Ndb_api_read_row_count                       | 369            |
| Ndb_api_trans_local_read_row_count           | 93             |
| Ndb_api_adaptive_send_forced_count           | 3              |
| Ndb_api_adaptive_send_unforced_count         | 738            |
| Ndb_api_adaptive_send_deferred_count         | 0              |
| Ndb_api_event_data_count                     | 0              |
| Ndb_api_event_nondata_count                  | 0              |
| Ndb_api_event_bytes_count                    | 0              |
| Ndb_api_wait_exec_complete_count_slave       | 0              |
| Ndb_api_wait_scan_result_count_slave         | 0              |
| Ndb_api_wait_meta_request_count_slave        | 0              |
| Ndb_api_wait_nanos_count_slave               | 0              |
| Ndb_api_bytes_sent_count_slave               | 0              |
| Ndb_api_bytes_received_count_slave           | 0              |
| Ndb_api_trans_start_count_slave              | 0              |
| Ndb_api_trans_commit_count_slave             | 0              |
| Ndb_api_trans_abort_count_slave              | 0              |
| Ndb_api_trans_close_count_slave              | 0              |
| Ndb_api_pk_op_count_slave                    | 0              |
| Ndb_api_uk_op_count_slave                    | 0              |
| Ndb_api_table_scan_count_slave               | 0              |
| Ndb_api_range_scan_count_slave               | 0              |
| Ndb_api_pruned_scan_count_slave              | 0              |
| Ndb_api_scan_batch_count_slave               | 0              |
| Ndb_api_read_row_count_slave                 | 0              |
| Ndb_api_trans_local_read_row_count_slave     | 0              |
| Ndb_api_adaptive_send_forced_count_slave     | 0              |
| Ndb_api_adaptive_send_unforced_count_slave   | 0              |
| Ndb_api_adaptive_send_deferred_count_slave   | 0              |
| Ndb_api_wait_exec_complete_count_replica     | 0              |
| Ndb_api_wait_scan_result_count_replica       | 0              |
| Ndb_api_wait_meta_request_count_replica      | 0              |
| Ndb_api_wait_nanos_count_replica             | 0              |
| Ndb_api_bytes_sent_count_replica             | 0              |
| Ndb_api_bytes_received_count_replica         | 0              |
| Ndb_api_trans_start_count_replica            | 0              |
| Ndb_api_trans_commit_count_replica           | 0              |
| Ndb_api_trans_abort_count_replica            | 0              |
| Ndb_api_trans_close_count_replica            | 0              |
| Ndb_api_pk_op_count_replica                  | 0              |
| Ndb_api_uk_op_count_replica                  | 0              |
| Ndb_api_table_scan_count_replica             | 0              |
| Ndb_api_range_scan_count_replica             | 0              |
| Ndb_api_pruned_scan_count_replica            | 0              |
| Ndb_api_scan_batch_count_replica             | 0              |
| Ndb_api_read_row_count_replica               | 0              |
| Ndb_api_trans_local_read_row_count_replica   | 0              |
| Ndb_api_adaptive_send_forced_count_replica   | 0              |
| Ndb_api_adaptive_send_unforced_count_replica | 0              |
| Ndb_api_adaptive_send_deferred_count_replica | 0              |
| Ndb_api_event_data_count_injector            | 0              |
| Ndb_api_event_nondata_count_injector         | 0              |
| Ndb_api_event_bytes_count_injector           | 0              |
| Ndb_api_wait_exec_complete_count_session     | 0              |
| Ndb_api_wait_scan_result_count_session       | 0              |
| Ndb_api_wait_meta_request_count_session      | 0              |
| Ndb_api_wait_nanos_count_session             | 0              |
| Ndb_api_bytes_sent_count_session             | 0              |
| Ndb_api_bytes_received_count_session         | 0              |
| Ndb_api_trans_start_count_session            | 0              |
| Ndb_api_trans_commit_count_session           | 0              |
| Ndb_api_trans_abort_count_session            | 0              |
| Ndb_api_trans_close_count_session            | 0              |
| Ndb_api_pk_op_count_session                  | 0              |
| Ndb_api_uk_op_count_session                  | 0              |
| Ndb_api_table_scan_count_session             | 0              |
| Ndb_api_range_scan_count_session             | 0              |
| Ndb_api_pruned_scan_count_session            | 0              |
| Ndb_api_scan_batch_count_session             | 0              |
| Ndb_api_read_row_count_session               | 0              |
| Ndb_api_trans_local_read_row_count_session   | 0              |
| Ndb_api_adaptive_send_forced_count_session   | 0              |
| Ndb_api_adaptive_send_unforced_count_session | 0              |
| Ndb_api_adaptive_send_deferred_count_session | 0              |
+----------------------------------------------+----------------+
90 rows in set (0.01 sec)
```

[](<>)[](<>)

每个[`钕铁硼`](https://dev.mysql.com/doc/ndbapi/en/ndb-ndb.html)对象有自己的计数器。NDB API 应用程序可以读取计数器的值以用于优化或监控。对于使用多个线程的多线程客户端[`钕铁硼`](https://dev.mysql.com/doc/ndbapi/en/ndb-ndb.html)对象同时，也可以从所有对象中获取计数器的总和视图[`钕铁硼`](https://dev.mysql.com/doc/ndbapi/en/ndb-ndb.html)属于给定的对象[`Ndb_cluster_connection`](https://dev.mysql.com/doc/ndbapi/en/ndb-ndb-cluster-connection.html).

暴露了四组这些计数器。一组仅适用于当前会话；其他 3 个是全球性的。*尽管它们的值可以作为会话或全局状态变量在[**mysql**](mysql.html)客户*.这意味着指定`会议`要么`全球的`关键字[`显示状态`](show-status.html)对 NDB API 统计状态变量报告的值没有影响，并且这些变量中的每一个的值是相同的，无论该值是从等效列中获得的[`会话状态`](performance-schema-status-variable-tables.html)或者[`全局状态`](performance-schema-status-variable-tables.html)桌子。

[](<>)[](<>)

-   *会话计数器（特定于会话）*

    会话计数器与[`钕铁硼`](https://dev.mysql.com/doc/ndbapi/en/ndb-ndb.html)（仅）当前会话使用的对象。其他 MySQL 客户端使用此类对象不会影响这些计数。

    为了尽量减少与标准 MySQL 会话变量的混淆，我们将与这些 NDB API 会话计数器对应的变量称为“`_会议`变量”，带有前导下划线。

-   *副本计数器（全局）*

    这组计数器涉及[`钕铁硼`](https://dev.mysql.com/doc/ndbapi/en/ndb-ndb.html)副本 SQL 线程使用的对象（如果有）。如果这[**mysqld**](mysqld.html)不作为复制品，或不使用[`新开发银行`](mysql-cluster.html)表，那么所有这些计数都是 0。

    我们将相关的状态变量称为“`_奴隶`变量”（带有前导下划线）。

-   *喷油器计数器（全局）*

    喷油器计数器与[`钕铁硼`](https://dev.mysql.com/doc/ndbapi/en/ndb-ndb.html)用于通过二进制日志注入线程监听集群事件的对象。即使不写二进制日志，[**mysqld**](mysqld.html)附加到 NDB Cluster 的进程继续侦听某些事件，例如架构更改。

    我们将与 NDB API 注入器计数器对应的状态变量称为“`_注射器`变量”（带有前导下划线）。

-   *服务器（全局）计数器（全局）*

    这组计数器涉及所有[`钕铁硼`](https://dev.mysql.com/doc/ndbapi/en/ndb-ndb.html)当前使用的对象[**mysqld**](mysqld.html).这包括所有 MySQL 客户端应用程序、副本 SQL 线程（如果有）、二进制日志注入器和[`新开发银行`](mysql-cluster.html)实用线程。

    我们将与这些计数器对应的状态变量称为“全局变量”或“[**mysqld**](mysqld.html)级变量”。

    您可以通过额外过滤子字符串来获取特定变量集的值`会议`,`奴隶`， 要么`注射器`在变量名中（连同公共前缀`Ndb_api`）。为了`_会议`变量，这可以如下所示完成：


```
mysql> SHOW STATUS LIKE 'ndb_api%session';
+--------------------------------------------+---------+
| Variable_name                              | Value   |
+--------------------------------------------+---------+
| Ndb_api_wait_exec_complete_count_session   | 2       |
| Ndb_api_wait_scan_result_count_session     | 0       |
| Ndb_api_wait_meta_request_count_session    | 1       |
| Ndb_api_wait_nanos_count_session           | 8144375 |
| Ndb_api_bytes_sent_count_session           | 68      |
| Ndb_api_bytes_received_count_session       | 84      |
| Ndb_api_trans_start_count_session          | 1       |
| Ndb_api_trans_commit_count_session         | 1       |
| Ndb_api_trans_abort_count_session          | 0       |
| Ndb_api_trans_close_count_session          | 1       |
| Ndb_api_pk_op_count_session                | 1       |
| Ndb_api_uk_op_count_session                | 0       |
| Ndb_api_table_scan_count_session           | 0       |
| Ndb_api_range_scan_count_session           | 0       |
| Ndb_api_pruned_scan_count_session          | 0       |
| Ndb_api_scan_batch_count_session           | 0       |
| Ndb_api_read_row_count_session             | 1       |
| Ndb_api_trans_local_read_row_count_session | 1       |
+--------------------------------------------+---------+
18 rows in set (0.50 sec)
```

获取 NDB API 的列表[**mysqld**](mysqld.html)-level 状态变量，过滤以开头的变量名`ndb_api`并以`_数数`， 像这样：

```
mysql> SELECT * FROM performance_schema.session_status
    ->     WHERE VARIABLE_NAME LIKE 'ndb_api%count';
+------------------------------------+----------------+
| VARIABLE_NAME                      | VARIABLE_VALUE |
+------------------------------------+----------------+
| NDB_API_WAIT_EXEC_COMPLETE_COUNT   | 4              |
| NDB_API_WAIT_SCAN_RESULT_COUNT     | 3              |
| NDB_API_WAIT_META_REQUEST_COUNT    | 28             |
| NDB_API_WAIT_NANOS_COUNT           | 53756398       |
| NDB_API_BYTES_SENT_COUNT           | 1060           |
| NDB_API_BYTES_RECEIVED_COUNT       | 9724           |
| NDB_API_TRANS_START_COUNT          | 3              |
| NDB_API_TRANS_COMMIT_COUNT         | 2              |
| NDB_API_TRANS_ABORT_COUNT          | 0              |
| NDB_API_TRANS_CLOSE_COUNT          | 3              |
| NDB_API_PK_OP_COUNT                | 2              |
| NDB_API_UK_OP_COUNT                | 0              |
| NDB_API_TABLE_SCAN_COUNT           | 1              |
| NDB_API_RANGE_SCAN_COUNT           | 0              |
| NDB_API_PRUNED_SCAN_COUNT          | 0              |
| NDB_API_SCAN_BATCH_COUNT           | 0              |
| NDB_API_READ_ROW_COUNT             | 2              |
| NDB_API_TRANS_LOCAL_READ_ROW_COUNT | 2              |
| NDB_API_EVENT_DATA_COUNT           | 0              |
| NDB_API_EVENT_NONDATA_COUNT        | 0              |
| NDB_API_EVENT_BYTES_COUNT          | 0              |
+------------------------------------+----------------+
21 rows in set (0.09 sec)
```

并非所有计数器都反映在所有 4 组状态变量中。对于事件计数器`DataEventsRecvdCount`,`NondataEventsRecvdCount`， 和`EventBytesRecvdCount`， 只要`_注射器`和[**mysqld**](mysqld.html)-level NDB API 状态变量可用：

```
mysql> SHOW STATUS LIKE 'ndb_api%event%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| Ndb_api_event_data_count_injector    | 0     |
| Ndb_api_event_nondata_count_injector | 0     |
| Ndb_api_event_bytes_count_injector   | 0     |
| Ndb_api_event_data_count             | 0     |
| Ndb_api_event_nondata_count          | 0     |
| Ndb_api_event_bytes_count            | 0     |
+--------------------------------------+-------+
6 rows in set (0.00 sec)
```

`_注射器`没有为任何其他 NDB API 计数器实现状态变量，如下所示：

```
mysql> SHOW STATUS LIKE 'ndb_api%injector%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| Ndb_api_event_data_count_injector    | 0     |
| Ndb_api_event_nondata_count_injector | 0     |
| Ndb_api_event_bytes_count_injector   | 0     |
+--------------------------------------+-------+
3 rows in set (0.00 sec)
```

[](<>)[](<>)

状态变量的名称可以很容易地与相应计数器的名称相关联。每个 NDB API 统计计数器都列在下表中，并带有描述以及与此计数器对应的任何 MySQL 服务器状态变量的名称。

[](<>)

**表 23.66 NDB API 统计计数器**

| 柜台名称 | 描述 | 状态变量（按统计类型）：<br/><br/>*会议<br/><br/>*奴隶（复制品）<br/><br/>*注射器<br/><br/>*服务器 |
| ---- | --- | ----------------------------------------------------------------------- |
| `等待执行完成计数` | 线程在等待操作执行完成时被阻塞的次数。包括所有[`执行（）`](https://dev.mysql.com/doc/ndbapi/en/ndb-ndbtransaction.html#ndb-ndbtransaction-execute)调用以及对客户端不可见的 blob 操作和自动增量的隐式执行。 | * [`Ndb_api_wait_exec_complete_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_wait_exec_complete_count_session)<br/><br/>* [`Ndb_api_wait_exec_complete_count_slave`](mysql-cluster-options-variables.html#statvar_Ndb_api_wait_exec_complete_count_slave)<br/><br/>* [没有]<br/><br/>* [`Ndb_api_wait_exec_complete_count`](mysql-cluster-options-variables.html#statvar_Ndb_api_wait_exec_complete_count) |
| `等待扫描结果计数` | 线程在等待基于扫描的信号时被阻塞的次数，例如等待其他结果或扫描关闭。 | * [`Ndb_api_wait_scan_result_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_wait_scan_result_count_session)<br/><br/>* [`Ndb_api_wait_scan_result_count_slave`](mysql-cluster-options-variables.html#statvar_Ndb_api_wait_scan_result_count_slave)<br/><br/>* [没有]<br/><br/>* [`Ndb_api_wait_scan_result_count`](mysql-cluster-options-variables.html#statvar_Ndb_api_wait_scan_result_count) |
| `WaitMetaRequestCount` | 线程被阻塞等待基于元数据的信号的次数；这可能在等待 DDL 操作或开始（或结束）一个纪元时发生。 | * [`Ndb_api_wait_meta_request_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_wait_meta_request_count_session)<br/><br/>* [`Ndb_api_wait_meta_request_count_slave`](mysql-cluster-options-variables.html#statvar_Ndb_api_wait_meta_request_count_slave)<br/><br/>* [没有]<br/><br/>* [`Ndb_api_wait_meta_request_count`](mysql-cluster-options-variables.html#statvar_Ndb_api_wait_meta_request_count) |
| `等待纳米计数` | 等待来自数据节点的某种类型的信号所花费的总时间（以纳秒为单位）。 | * [`Ndb_api_wait_nanos_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_wait_nanos_count_session)<br/><br/>* [`Ndb_api_wait_nanos_count_slave`](mysql-cluster-options-variables.html#statvar_Ndb_api_wait_nanos_count_slave)<br/><br/>* [没有]<br/><br/>* [`Ndb_api_wait_nanos_count`](mysql-cluster-options-variables.html#statvar_Ndb_api_wait_nanos_count) |
| `字节发送计数` | 发送到数据节点的数据量（以字节为单位） | * [`Ndb_api_bytes_sent_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_bytes_sent_count_session)<br/><br/>* [`Ndb_api_bytes_sent_count_slave`](mysql-cluster-options-variables.html#statvar_Ndb_api_bytes_sent_count_slave)<br/><br/>* [没有]<br/><br/>* [`Ndb_api_bytes_sent_count`](mysql-cluster-options-variables.html#statvar_Ndb_api_bytes_sent_count) |
| `BytesRecvdCount` | 从数据节点接收的数据量（以字节为单位） | * [`Ndb_api_bytes_received_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_bytes_received_count_session)<br/><br/>* [`Ndb_api_bytes_received_count_slave`](mysql-cluster-options-variables.html#statvar_Ndb_api_bytes_received_count_slave)<br/><br/>* [没有]<br/><br/>* [`Ndb_api_bytes_received_count`](mysql-cluster-options-variables.html#statvar_Ndb_api_bytes_received_count) |
| `TransStartCount` | 开始的事务数。 | * [`Ndb_api_trans_start_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_trans_start_count_session)<br/><br/>* [`Ndb_api_trans_start_count_slave`](mysql-cluster-options-variables.html#statvar_Ndb_api_trans_start_count_slave)<br/><br/>* [没有]<br/><br/>* [`Ndb_api_trans_start_count`](mysql-cluster-options-variables.html#statvar_Ndb_api_trans_start_count) |
| `TransCommitCount` | 提交的事务数。 | * [`Ndb_api_trans_commit_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_trans_commit_count_session)<br/><br/>* [`Ndb_api_trans_commit_count_slave`](mysql-cluster-options-variables.html#statvar_Ndb_api_trans_commit_count_slave)<br/><br/>* [没有]<br/><br/>* [`Ndb_api_trans_commit_count`](mysql-cluster-options-variables.html#statvar_Ndb_api_trans_commit_count) |
| `TransAbortCount` | 中止的事务数。 | * [`Ndb_api_trans_abort_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_trans_abort_count_session)<br/><br/>* [`Ndb_api_trans_abort_count_slave`](mysql-cluster-options-variables.html#statvar_Ndb_api_trans_abort_count_slave)<br/><br/>* [没有]<br/><br/>* [`Ndb_api_trans_abort_count`](mysql-cluster-options-variables.html#statvar_Ndb_api_trans_abort_count) |
| `TransClo​​seCount` | 中止的事务数。（这个值可能大于总和`TransCommitCount`和`TransAbortCount`.) | * [`Ndb_api_trans_close_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_trans_close_count_session)<br/><br/>* [`Ndb_api_trans_close_count_slave`](mysql-cluster-options-variables.html#statvar_Ndb_api_trans_close_count_slave)<br/><br/>* [没有]<br/><br/>* [`Ndb_api_trans_close_count`](mysql-cluster-options-variables.html#statvar_Ndb_api_trans_close_count) |
| `PkOpCount` | 基于或使用主键的操作数。此计数包括 blob 部分表操作、隐式解锁操作和自动增量操作，以及通常对 MySQL 客户端可见的主键操作。 | * [`Ndb_api_pk_op_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_pk_op_count_session)<br/><br/>* [`Ndb_api_pk_op_count_slave`](mysql-cluster-options-variables.html#statvar_Ndb_api_pk_op_count_slave)<br/><br/>* [没有]<br/><br/>* [`Ndb_api_pk_op_count`](mysql-cluster-options-variables.html#statvar_Ndb_api_pk_op_count) |
| `UkOpCount` | 基于或使用唯一键的操作数。 | * [`Ndb_api_uk_op_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_uk_op_count_session)<br/><br/>* [`Ndb_api_uk_op_count_slave`](mysql-cluster-options-variables.html#statvar_Ndb_api_uk_op_count_slave)<br/><br/>* [没有]<br/><br/>* [`Ndb_api_uk_op_count`](mysql-cluster-options-variables.html#statvar_Ndb_api_uk_op_count) |
| `表扫描计数` | 已启动的表扫描数。这包括扫描内部表。 | * [`Ndb_api_table_scan_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_table_scan_count_session)<br/><br/>* [`Ndb_api_table_scan_count_slave`](mysql-cluster-options-variables.html#statvar_Ndb_api_table_scan_count_slave)<br/><br/>* [没有]<br/><br/>* [`Ndb_api_table_scan_count`](mysql-cluster-options-variables.html#statvar_Ndb_api_table_scan_count) |
| `范围扫描计数` | 已开始的范围扫描数。 | * [`Ndb_api_range_scan_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_range_scan_count_session)<br/><br/>* [`Ndb_api_range_scan_count_slave`](mysql-cluster-options-variables.html#statvar_Ndb_api_range_scan_count_slave)<br/><br/>* [没有]<br/><br/>* [`Ndb_api_range_scan_count`](mysql-cluster-options-variables.html#statvar_Ndb_api_range_scan_count) |
| `修剪扫描计数` | 已修剪到单个分区的扫描数。 | * [`Ndb_api_pruned_scan_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_pruned_scan_count_session)<br/><br/>* [`Ndb_api_pruned_scan_count_slave`](mysql-cluster-options-variables.html#statvar_Ndb_api_pruned_scan_count_slave)<br/><br/>* [没有]<br/><br/>* [`Ndb_api_pruned_scan_count`](mysql-cluster-options-variables.html#statvar_Ndb_api_pruned_scan_count) |
| `扫描批量计数` | 收到的批次行数。（此上下文中的批次是来自单个片段的一组扫描结果。） | * [`Ndb_api_scan_batch_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_scan_batch_count_session)<br/><br/>* [`Ndb_api_scan_batch_count_slave`](mysql-cluster-options-variables.html#statvar_Ndb_api_scan_batch_count_slave)<br/><br/>* [没有]<br/><br/>* [`Ndb_api_scan_batch_count`](mysql-cluster-options-variables.html#statvar_Ndb_api_scan_batch_count) |
| `读取行数` | 已读取的总行数。包括使用主键、唯一键和扫描操作读取的行。 | * [`Ndb_api_read_row_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_read_row_count_session)<br/><br/>* [`Ndb_api_read_row_count_slave`](mysql-cluster-options-variables.html#statvar_Ndb_api_read_row_count_slave)<br/><br/>* [没有]<br/><br/>* [`Ndb_api_read_row_count`](mysql-cluster-options-variables.html#statvar_Ndb_api_read_row_count) |
| `TransLocalReadRowCount` | 从正在运行事务的数据相同节点读取的行数。 | * [`Ndb_api_trans_local_read_row_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_trans_local_read_row_count_session)<br/><br/>* [`Ndb_api_trans_local_read_row_count_slave`](mysql-cluster-options-variables.html#statvar_Ndb_api_trans_local_read_row_count_slave)<br/><br/>* [没有]<br/><br/>* [`Ndb_api_trans_local_read_row_count`](mysql-cluster-options-variables.html#statvar_Ndb_api_trans_local_read_row_count) |
| `DataEventsRecvdCount` | 收到的行更改事件数。 | * [没有]<br/><br/>* [没有]<br/><br/>* [`Ndb_api_event_data_count_injector`](mysql-cluster-options-variables.html#statvar_Ndb_api_event_data_count_injector)<br/><br/>* [`Ndb_api_event_data_count`](mysql-cluster-options-variables.html#statvar_Ndb_api_event_data_count) |
| `NondataEventsRecvdCount` | 收到的事件数，行更改事件除外。 | * [没有]<br/><br/>* [没有]<br/><br/>* [`Ndb_api_event_nondata_count_injector`](mysql-cluster-options-variables.html#statvar_Ndb_api_event_nondata_count_injector)<br/><br/>* [`Ndb_api_event_nondata_count`](mysql-cluster-options-variables.html#statvar_Ndb_api_event_nondata_count) |
| `EventBytesRecvdCount` | 接收到的事件字节数。 | * [没有]<br/><br/>* [没有]<br/><br/>* [`Ndb_api_event_bytes_count_injector`](mysql-cluster-options-variables.html#statvar_Ndb_api_event_bytes_count_injector)<br/><br/>* [`Ndb_api_event_bytes_count`](mysql-cluster-options-variables.html#statvar_Ndb_api_event_bytes_count) |

查看所有已提交事务的计数——即所有`TransCommitCount`计数器状态变量——你可以过滤结果[`显示状态`](show-status.html)对于子串`trans_commit_count`， 像这样：

```
mysql> SHOW STATUS LIKE '%trans_commit_count%';
+------------------------------------+-------+
| Variable_name                      | Value |
+------------------------------------+-------+
| Ndb_api_trans_commit_count_session | 1     |
| Ndb_api_trans_commit_count_slave   | 0     |
| Ndb_api_trans_commit_count         | 2     |
+------------------------------------+-------+
3 rows in set (0.00 sec)
```

从中可以确定当前已经提交了 1 个事务[**mysql**](mysql.html)客户端会话，并在此提交了 2 个事务[**mysqld**](mysqld.html)自上次重新启动以来。

您可以通过比较相应的值来查看给定 SQL 语句如何增加各种 NDB API 计数器`_会议`执行语句之前和之后的状态变量。在这个例子中，在从[`显示状态`](show-status.html)，我们在`测试`数据库[`新开发银行`](mysql-cluster.html)表，命名`吨`，只有一列：

```
mysql> SHOW STATUS LIKE 'ndb_api%session%';
+--------------------------------------------+--------+
| Variable_name                              | Value  |
+--------------------------------------------+--------+
| Ndb_api_wait_exec_complete_count_session   | 2      |
| Ndb_api_wait_scan_result_count_session     | 0      |
| Ndb_api_wait_meta_request_count_session    | 3      |
| Ndb_api_wait_nanos_count_session           | 820705 |
| Ndb_api_bytes_sent_count_session           | 132    |
| Ndb_api_bytes_received_count_session       | 372    |
| Ndb_api_trans_start_count_session          | 1      |
| Ndb_api_trans_commit_count_session         | 1      |
| Ndb_api_trans_abort_count_session          | 0      |
| Ndb_api_trans_close_count_session          | 1      |
| Ndb_api_pk_op_count_session                | 1      |
| Ndb_api_uk_op_count_session                | 0      |
| Ndb_api_table_scan_count_session           | 0      |
| Ndb_api_range_scan_count_session           | 0      |
| Ndb_api_pruned_scan_count_session          | 0      |
| Ndb_api_scan_batch_count_session           | 0      |
| Ndb_api_read_row_count_session             | 1      |
| Ndb_api_trans_local_read_row_count_session | 1      |
+--------------------------------------------+--------+
18 rows in set (0.00 sec)

mysql> USE test;
Database changed
mysql> CREATE TABLE t (c INT) ENGINE NDBCLUSTER;
Query OK, 0 rows affected (0.85 sec)
```

现在你可以执行一个新的[`显示状态`](show-status.html)语句并观察更改，如下所示（在输出中突出显示更改的行）：

```
mysql> SHOW STATUS LIKE 'ndb_api%session%';
+--------------------------------------------+-----------+
| Variable_name                              | Value     |
+--------------------------------------------+-----------+
| Ndb_api_wait_exec_complete_count_session   | 8         |
| Ndb_api_wait_scan_result_count_session     | 0         |
| Ndb_api_wait_meta_request_count_session    | 17        |
| Ndb_api_wait_nanos_count_session           | 706871709 |
| Ndb_api_bytes_sent_count_session           | 2376      |
| Ndb_api_bytes_received_count_session       | 3844      |
| Ndb_api_trans_start_count_session          | 4         |
| Ndb_api_trans_commit_count_session         | 4         |
| Ndb_api_trans_abort_count_session          | 0         |
| Ndb_api_trans_close_count_session          | 4         |
| Ndb_api_pk_op_count_session                | 6         |
| Ndb_api_uk_op_count_session                | 0         |
| Ndb_api_table_scan_count_session           | 0         |
| Ndb_api_range_scan_count_session           | 0         |
| Ndb_api_pruned_scan_count_session          | 0         |
| Ndb_api_scan_batch_count_session           | 0         |
| Ndb_api_read_row_count_session             | 2         |
| Ndb_api_trans_local_read_row_count_session | 1         |
+--------------------------------------------+-----------+
18 rows in set (0.00 sec)
```

同样，您可以看到在 NDB API 统计计数器中插入一行导致的变化`吨`：插入行，然后运行相同[`显示状态`](show-status.html)上一个示例中使用的语句，如下所示：

```
mysql> INSERT INTO t VALUES (100);
Query OK, 1 row affected (0.00 sec)

mysql> SHOW STATUS LIKE 'ndb_api%session%';
+--------------------------------------------+-----------+
| Variable_name                              | Value     |
+--------------------------------------------+-----------+
| Ndb_api_wait_exec_complete_count_session   | 11        |
| Ndb_api_wait_scan_result_count_session     | 6         |
| Ndb_api_wait_meta_request_count_session    | 20        |
| Ndb_api_wait_nanos_count_session           | 707370418 |
| Ndb_api_bytes_sent_count_session           | 2724      |
| Ndb_api_bytes_received_count_session       | 4116      |
| Ndb_api_trans_start_count_session          | 7         |
| Ndb_api_trans_commit_count_session         | 6         |
| Ndb_api_trans_abort_count_session          | 0         |
| Ndb_api_trans_close_count_session          | 7         |
| Ndb_api_pk_op_count_session                | 8         |
| Ndb_api_uk_op_count_session                | 0         |
| Ndb_api_table_scan_count_session           | 1         |
| Ndb_api_range_scan_count_session           | 0         |
| Ndb_api_pruned_scan_count_session          | 0         |
| Ndb_api_scan_batch_count_session           | 0         |
| Ndb_api_read_row_count_session             | 3         |
| Ndb_api_trans_local_read_row_count_session | 2         |
+--------------------------------------------+-----------+
18 rows in set (0.00 sec)
```

我们可以从这些结果中得出一些观察结果：

-   虽然我们创造了`吨`在没有显式主键的情况下，执行了 5 次主键操作（“之前”和“之后”值的差异[`Ndb_api_pk_op_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_pk_op_count_session), 或 6 减 1)。这反映了隐藏主键的创建，这是所有使用[`新开发银行`](mysql-cluster.html)存储引擎。

-   通过比较连续值[`Ndb_api_wait_nanos_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_wait_nanos_count_session)，我们可以看到 NDB API 操作实现了[`创建表`](create-table.html)语句等待数据节点响应的时间比[`插入`](insert.html)（707370418 - 706871709 = 498709 ns 或大约 0.0005 秒）。报告中这些语句的执行时间[**mysql**](mysql.html)客户与这些数字大致相关。

    在没有足够（纳秒）时间分辨率的平台上，`等待纳米计数`由于 SQL 语句执行速度非常快，NDB API 计数器可能并不总是在值中可见[`Ndb_api_wait_nanos_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_wait_nanos_count_session),[`Ndb_api_wait_nanos_count_slave`](mysql-cluster-options-variables.html#statvar_Ndb_api_wait_nanos_count_slave)， 要么[`Ndb_api_wait_nanos_count`](mysql-cluster-options-variables.html#statvar_Ndb_api_wait_nanos_count).

-   这[`插入`](insert.html)声明增加了两个`读取行数`和`TransLocalReadRowCount`NDB API 统计计数器，如增加的值所反映的[`Ndb_api_read_row_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_read_row_count_session)和[`Ndb_api_trans_local_read_row_count_session`](mysql-cluster-options-variables.html#statvar_Ndb_api_trans_local_read_row_count_session).
