From b3fbfcc9654bc63bf0d8f3025641d8c50a24ef97 Mon Sep 17 00:00:00 2001 From: Cindy Peng <148148319+cindy-peng@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:17:28 -0800 Subject: [PATCH] Docs: Update gapic upgrade installation instructions (#1677) * Update user guide * chore: generate libraries at Wed Dec 4 18:25:42 UTC 2024 * Formatting code block * chore: generate libraries at Wed Dec 4 19:22:29 UTC 2024 * Remove client-side metrics suggestions --------- Co-authored-by: cloud-java-bot --- .readme-partials.yaml | 82 +++++++++++++++++++++++++++++++------------ README.md | 82 +++++++++++++++++++++++++++++++------------ 2 files changed, 120 insertions(+), 44 deletions(-) diff --git a/.readme-partials.yaml b/.readme-partials.yaml index ced21e49f..3e8d3a465 100644 --- a/.readme-partials.yaml +++ b/.readme-partials.yaml @@ -110,28 +110,33 @@ custom_content: | ------- In this feature launch, the [Java Datastore client](https://github.com/googleapis/java-datastore) now offers gRPC as a transport layer option with experimental support. Using [gRPC connection pooling](https://grpc.io/docs/guides/performance/) enables distributing RPCs over multiple connections which may improve performance. - #### Download Instructions - Instructions: - 1. Clone the grpc-experimental branch from GitHub: - ```python - git clone -b grpc-experimental https://github.com/googleapis/java-datastore.git - ``` - 2. Run the following commands to build the library: - ```python - # Go to the directory the code was downloaded to - cd java-datastore/ - - # Build the library - mvn clean install -DskipTests=true - ``` - 3. Add the following dependency to your project: - ```xml - + #### Installation Instructions + The client can be built from the `grpc-experimental` branch on GitHub. For private preview, you can also download the artifact with the instructions provided below. + + 1. Download the datastore private preview package with dependencies: + ``` + curl -o https://datastore-sdk-feature-release.web.app/google-cloud-datastore-2.20.0-grpc-experimental-1-SNAPSHOT-jar-with-dependencies.jar + ``` + 2. Run the following commands to install JDK locally: + ``` + mvn install:install-file -Dfile= -DgroupId=com.google.cloud -DartifactId=google-cloud-datastore -Dversion=2.20.0-grpc + ``` + 3. Edit your pom.xml to add above package to `` section: + ```xml + com.google.cloud google-cloud-datastore 2.20.0-grpc-experimental-1-SNAPSHOT - - ``` + + ``` + + And if you have not yet, add below to `` section: + ```xml + + local-repo + file://${user.home}/.m2/repository + + ``` #### How to Use To opt-in to the gRPC transport behavior, simply add the below line of code (`setTransportOptions`) to your Datastore client instantiation. @@ -181,11 +186,44 @@ custom_content: | #### New Features There are new gRPC specific features available to use in this update. - ##### Channel Pooling - To customize the number of channels your client uses, you can update the channel provider in the DatastoreOptions. + ##### Connection Pool + A connection pool, also known as a channel pool, is a cache of database connections that are shared and reused to improve connection latency and performance. With this update, now you will be able to configure the channel pool to improve application performance. This section guides you in determining the optimal connection pool size and configuring it within the Java datastore client. + To customize the number of channels your client uses, you can update the channel provider in the DatastoreOptions. + ###### Determine the best connection pool size + The default connection pool size is right for most applications, and in most cases there's no need to change it. + + However sometimes you may want to change your connection pool size due to high throughput or buffered requests. Ideally, to leave room for traffic fluctuations, a connection pool has about twice the number of connections it takes for maximum saturation. Because a connection can handle a maximum of 100 concurrent requests, between 10 and 50 outstanding requests per connection is optimal. The limit of 100 concurrent streams per gRPC connection is enforced in Google's middleware layer, and you are not able to reconfigure this number. + + The following steps help you calculate the optimal number of connections in your channel pool using estimate per-client QPS and average latency numbers. + + To calculate the optimal connections, gather the following information: + + 1. The maximum number of queries per second (QPS) per client when your application is running a typical workload. + 2. The average latency (the response time for a single request) in ms. + 3. Determine the number of requests that you can send serially per second by dividing 1,000 by the average latency value. + 4. Divide the QPS in seconds by the number of serial requests per second. + 5. Divide the result by 50 requests per channel to determine the minimum optimal channel pool size. (If your calculation is less than 2, use at least 2 channels anyway, to ensure redundancy.) + 6. Divide the same result by 10 requests per channel to determine the maximum optimal channel pool size. + + These steps are expressed in the following equations: + ```java + (QPS ÷ (1,000 ÷ latency ms)) ÷ 50 streams = Minimum optimal number of connections + (QPS ÷ (1,000 ÷ latency ms)) ÷ 10 streams = Maximum optimal number of connections + ``` + + ###### Example + Your application typically sends 50,000 requests per second, and the average latency is 10 ms. Divide 1,000 by 10 ms to determine that you can send 100 requests serially per second. + Divide that number into 50,000 to get the parallelism needed to send 50,000 QPS: 500. Each channel can have at most 100 requests out concurrently, and your target channel utilization + is between 10 and 50 concurrent streams. Therefore, to calculate the minimum, divide 500 by 50 to get 10. To find the maximum, divide 500 by 10 to get 50. This means that your channel + pool size for this example should be between 10 and 50 connections. + + It is also important to monitor your traffic after making changes and adjust the number of connections in your pool if necessary. + + ###### Set the pool size + The following code sample demonstrates how to configure the channel pool in the client libraries using `DatastoreOptions`. See [ChannelPoolSettings](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.grpc.ChannelPoolSettings) and [Performance Best Practices](https://grpc.io/docs/guides/performance/) for more information on channel pools and best practices for performance. - Example: + Code Example ```java InstantiatingGrpcChannelProvider channelProvider = DatastoreSettings.defaultGrpcTransportProviderBuilder() diff --git a/README.md b/README.md index f059e75ed..4dc14a97f 100644 --- a/README.md +++ b/README.md @@ -208,28 +208,33 @@ gRPC Java Datastore Client User Guide ------- In this feature launch, the [Java Datastore client](https://github.com/googleapis/java-datastore) now offers gRPC as a transport layer option with experimental support. Using [gRPC connection pooling](https://grpc.io/docs/guides/performance/) enables distributing RPCs over multiple connections which may improve performance. -#### Download Instructions -Instructions: -1. Clone the grpc-experimental branch from GitHub: -```python -git clone -b grpc-experimental https://github.com/googleapis/java-datastore.git -``` -2. Run the following commands to build the library: -```python -# Go to the directory the code was downloaded to -cd java-datastore/ - -# Build the library -mvn clean install -DskipTests=true -``` -3. Add the following dependency to your project: -```xml - +#### Installation Instructions +The client can be built from the `grpc-experimental` branch on GitHub. For private preview, you can also download the artifact with the instructions provided below. + +1. Download the datastore private preview package with dependencies: + ``` + curl -o https://datastore-sdk-feature-release.web.app/google-cloud-datastore-2.20.0-grpc-experimental-1-SNAPSHOT-jar-with-dependencies.jar + ``` +2. Run the following commands to install JDK locally: + ``` + mvn install:install-file -Dfile= -DgroupId=com.google.cloud -DartifactId=google-cloud-datastore -Dversion=2.20.0-grpc + ``` +3. Edit your pom.xml to add above package to `` section: + ```xml + com.google.cloud google-cloud-datastore 2.20.0-grpc-experimental-1-SNAPSHOT - -``` + + ``` + +And if you have not yet, add below to `` section: + ```xml + + local-repo + file://${user.home}/.m2/repository + + ``` #### How to Use To opt-in to the gRPC transport behavior, simply add the below line of code (`setTransportOptions`) to your Datastore client instantiation. @@ -279,11 +284,44 @@ boolean isHTTP = datastore.getOptions().getTransportOptions() instanceof HTTPTra #### New Features There are new gRPC specific features available to use in this update. -##### Channel Pooling -To customize the number of channels your client uses, you can update the channel provider in the DatastoreOptions. +##### Connection Pool +A connection pool, also known as a channel pool, is a cache of database connections that are shared and reused to improve connection latency and performance. With this update, now you will be able to configure the channel pool to improve application performance. This section guides you in determining the optimal connection pool size and configuring it within the Java datastore client. +To customize the number of channels your client uses, you can update the channel provider in the DatastoreOptions. +###### Determine the best connection pool size +The default connection pool size is right for most applications, and in most cases there's no need to change it. + +However sometimes you may want to change your connection pool size due to high throughput or buffered requests. Ideally, to leave room for traffic fluctuations, a connection pool has about twice the number of connections it takes for maximum saturation. Because a connection can handle a maximum of 100 concurrent requests, between 10 and 50 outstanding requests per connection is optimal. The limit of 100 concurrent streams per gRPC connection is enforced in Google's middleware layer, and you are not able to reconfigure this number. + +The following steps help you calculate the optimal number of connections in your channel pool using estimate per-client QPS and average latency numbers. + +To calculate the optimal connections, gather the following information: + +1. The maximum number of queries per second (QPS) per client when your application is running a typical workload. +2. The average latency (the response time for a single request) in ms. +3. Determine the number of requests that you can send serially per second by dividing 1,000 by the average latency value. +4. Divide the QPS in seconds by the number of serial requests per second. +5. Divide the result by 50 requests per channel to determine the minimum optimal channel pool size. (If your calculation is less than 2, use at least 2 channels anyway, to ensure redundancy.) +6. Divide the same result by 10 requests per channel to determine the maximum optimal channel pool size. + +These steps are expressed in the following equations: +```java +(QPS ÷ (1,000 ÷ latency ms)) ÷ 50 streams = Minimum optimal number of connections +(QPS ÷ (1,000 ÷ latency ms)) ÷ 10 streams = Maximum optimal number of connections +``` + +###### Example +Your application typically sends 50,000 requests per second, and the average latency is 10 ms. Divide 1,000 by 10 ms to determine that you can send 100 requests serially per second. +Divide that number into 50,000 to get the parallelism needed to send 50,000 QPS: 500. Each channel can have at most 100 requests out concurrently, and your target channel utilization +is between 10 and 50 concurrent streams. Therefore, to calculate the minimum, divide 500 by 50 to get 10. To find the maximum, divide 500 by 10 to get 50. This means that your channel +pool size for this example should be between 10 and 50 connections. + +It is also important to monitor your traffic after making changes and adjust the number of connections in your pool if necessary. + +###### Set the pool size +The following code sample demonstrates how to configure the channel pool in the client libraries using `DatastoreOptions`. See [ChannelPoolSettings](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.grpc.ChannelPoolSettings) and [Performance Best Practices](https://grpc.io/docs/guides/performance/) for more information on channel pools and best practices for performance. -Example: +Code Example ```java InstantiatingGrpcChannelProvider channelProvider = DatastoreSettings.defaultGrpcTransportProviderBuilder()