Skip to content

Commit 789824f

Browse files
chore(spanner): multi use transaction benchmarking (#3075)
* chore(spanner): add multi use RO benchmarking for mutiplexed session * chore(spanner): code refactor * chore(spanner): 3 read operation per multi use txn * chore(spanner): code refactor * chore(spanner): code refactor * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * chore(spanner): update dependency version --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 5394139 commit 789824f

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ implementation 'com.google.cloud:google-cloud-spanner'
5757
If you are using Gradle without BOM, add this to your dependencies:
5858

5959
```Groovy
60-
implementation 'com.google.cloud:google-cloud-spanner:6.65.1'
60+
implementation 'com.google.cloud:google-cloud-spanner:6.66.0'
6161
```
6262

6363
If you are using SBT, add this to your dependencies:
6464

6565
```Scala
66-
libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.65.1"
66+
libraryDependencies += "com.google.cloud" % "google-cloud-spanner" % "6.66.0"
6767
```
6868
<!-- {x-version-update-end} -->
6969

@@ -651,7 +651,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
651651
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-spanner/java11.html
652652
[stability-image]: https://img.shields.io/badge/stability-stable-green
653653
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-spanner.svg
654-
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner/6.65.1
654+
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-spanner/6.66.0
655655
[authentication]: https://github.com/googleapis/google-cloud-java#authentication
656656
[auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes
657657
[predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles

benchmarks/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
<dependency>
9393
<groupId>com.google.cloud</groupId>
9494
<artifactId>google-cloud-spanner</artifactId>
95-
<version>6.65.1</version>
95+
<version>6.66.0</version>
9696
</dependency>
9797
<dependency>
9898
<groupId>commons-cli</groupId>

benchmarks/src/main/java/com/google/cloud/spanner/benchmark/BenchmarkRunner.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
public interface BenchmarkRunner {
2323
enum TransactionType {
2424
READ_ONLY_SINGLE_USE,
25+
READ_ONLY_MULTI_USE,
2526
READ_WRITE
2627
}
2728

benchmarks/src/main/java/com/google/cloud/spanner/benchmark/JavaClientRunner.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.cloud.opentelemetry.trace.TraceExporter;
2121
import com.google.cloud.spanner.DatabaseClient;
2222
import com.google.cloud.spanner.DatabaseId;
23+
import com.google.cloud.spanner.ReadOnlyTransaction;
2324
import com.google.cloud.spanner.ResultSet;
2425
import com.google.cloud.spanner.SessionPoolOptions;
2526
import com.google.cloud.spanner.SessionPoolOptionsHelper;
@@ -161,7 +162,10 @@ private Duration executeTransaction(
161162
Stopwatch watch = Stopwatch.createStarted();
162163
switch (transactionType) {
163164
case READ_ONLY_SINGLE_USE:
164-
executeReadOnlyTransaction(client);
165+
executeSingleUseReadOnlyTransaction(client);
166+
break;
167+
case READ_ONLY_MULTI_USE:
168+
executeMultiUseReadOnlyTransaction(client);
165169
break;
166170
case READ_WRITE:
167171
executeReadWriteTransaction(client);
@@ -172,7 +176,7 @@ private Duration executeTransaction(
172176
return elapsedTime;
173177
}
174178

175-
private void executeReadOnlyTransaction(DatabaseClient client) {
179+
private void executeSingleUseReadOnlyTransaction(DatabaseClient client) {
176180
try (ResultSet resultSet = client.singleUse().executeQuery(getRandomisedReadStatement())) {
177181
while (resultSet.next()) {
178182
for (int i = 0; i < resultSet.getColumnCount(); i++) {
@@ -186,6 +190,34 @@ private void executeReadOnlyTransaction(DatabaseClient client) {
186190
}
187191
}
188192

193+
private void executeMultiUseReadOnlyTransaction(DatabaseClient client) {
194+
try (ReadOnlyTransaction transaction = client.readOnlyTransaction()) {
195+
ResultSet resultSet = transaction.executeQuery(getRandomisedReadStatement());
196+
iterateResultSet(resultSet);
197+
198+
ResultSet resultSet1 = transaction.executeQuery(getRandomisedReadStatement());
199+
iterateResultSet(resultSet1);
200+
201+
ResultSet resultSet2 = transaction.executeQuery(getRandomisedReadStatement());
202+
iterateResultSet(resultSet2);
203+
204+
ResultSet resultSet3 = transaction.executeQuery(getRandomisedReadStatement());
205+
iterateResultSet(resultSet3);
206+
}
207+
}
208+
209+
private void iterateResultSet(ResultSet resultSet) {
210+
while (resultSet.next()) {
211+
for (int i = 0; i < resultSet.getColumnCount(); i++) {
212+
if (resultSet.isNull(i)) {
213+
numNullValues++;
214+
} else {
215+
numNonNullValues++;
216+
}
217+
}
218+
}
219+
}
220+
189221
private void executeReadWriteTransaction(DatabaseClient client) {
190222
client
191223
.readWriteTransaction()

0 commit comments

Comments
 (0)