cloudspannerecosystem / spanner-cli

Interactive command line tool for Cloud Spanner
Apache License 2.0
230 stars 28 forks source link

Add support for Directed reads #163

Closed takabow closed 9 months ago

takabow commented 9 months ago

Spanner's Directed reads are currently in public preview. This PR adds support for Directed reads in spanner-cli.

Currently, Spanner does not expose metrics that easily indicate whether Directed reads are applied, other than CPU util% per location. The most straightforward indicator is to observe the latency added based on the distance to the leader region when performing a strong read with follower replicas specified in Directed reads.

For example, in an asia1 configuration, you can observe the latency added between Osaka and Tokyo when performing directed reads from asia-northeast1(Tokyo) to asia-northeast2(Osaka).

A query without directed read option:

$ ./spanner-cli -p data-db-demo -i test-instance -d test-db 
Connected.
spanner> select 1;
+---+
|   |
+---+
| 1 |
+---+
1 rows in set (1.74 msecs)

A query with directed read option:

$ ./spanner-cli -p data-db-demo -i test-instance -d test-db --directedread asia-northeast2
Connected.
spanner> select 1;
+---+
|   |
+---+
| 1 |
+---+
1 rows in set (9.8 msecs) <--- add network latency between Osaka-Tokyo

Please note that this latency is a metric included in the SELECT results, and it is the latency measured on the Spanner side, not on the application side.