-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: minor optimizations to the standard query path (#3101)
* perf: minor optimizations to the standard query path Optimizes the standard query path slightly by adding some caching and removing regex matching that happened on the critical path of each query that was executed. * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
cc3352b
commit ec820a1
Showing
10 changed files
with
245 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
google-cloud-spanner/src/main/java/com/google/cloud/spanner/LatencyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.cloud.spanner; | ||
|
||
import com.google.auth.oauth2.GoogleCredentials; | ||
import com.google.cloud.spanner.SpannerOptions.FixedCloseableExecutorProvider; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.ThreadFactory; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
import org.threeten.bp.Duration; | ||
|
||
public class LatencyTest { | ||
|
||
public static void main(String[] args) throws Exception { | ||
ThreadFactory threadFactory = | ||
ThreadFactoryUtil.tryCreateVirtualThreadFactory("spanner-async-worker"); | ||
if (threadFactory == null) { | ||
return; | ||
} | ||
ScheduledExecutorService service = Executors.newScheduledThreadPool(0, threadFactory); | ||
Spanner spanner = | ||
SpannerOptions.newBuilder() | ||
.setCredentials( | ||
GoogleCredentials.fromStream( | ||
Files.newInputStream( | ||
Paths.get("/Users/loite/Downloads/appdev-soda-spanner-staging.json")))) | ||
.setSessionPoolOption( | ||
SessionPoolOptions.newBuilder() | ||
.setWaitForMinSessions(Duration.ofSeconds(5L)) | ||
// .setUseMultiplexedSession(true) | ||
.build()) | ||
.setUseVirtualThreads(true) | ||
.setAsyncExecutorProvider(FixedCloseableExecutorProvider.create(service)) | ||
.build() | ||
.getService(); | ||
DatabaseClient client = | ||
spanner.getDatabaseClient( | ||
DatabaseId.of("appdev-soda-spanner-staging", "knut-test-ycsb", "latencytest")); | ||
for (int i = 0; i < 1000000; i++) { | ||
try (AsyncResultSet resultSet = | ||
client | ||
.singleUse() | ||
.executeQueryAsync( | ||
Statement.newBuilder("select col_varchar from latency_test where col_bigint=$1") | ||
.bind("p1") | ||
.to(ThreadLocalRandom.current().nextLong(100000L)) | ||
.build())) { | ||
while (resultSet.next()) { | ||
for (int col = 0; col < resultSet.getColumnCount(); col++) { | ||
if (resultSet.getValue(col) == null) { | ||
throw new IllegalStateException(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.