You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cosmos-db/performance-tips-java-sdk-v4-sql.md
+14-23Lines changed: 14 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -91,7 +91,15 @@ So if you're asking "How can I improve my database performance?" consider the fo
91
91
92
92
An app that interacts with a multi-region Azure Cosmos DB account needs to configure [preferred locations]() to ensure that requests are going to a collocated region.
93
93
94
-
***Enable [Accelerated Networking](https://www.360visibility.com/azure-accelerated-networking-and-how-to-enable-it/) for lower latency.**
94
+
***Enable Accelerated Networking on your Azure VM for lower latency.**
95
+
96
+
It is recommended that you follow the instructions to enable Accelerated Networking in your [Windows (click for instructions)](https://docs.microsoft.com/en-us/azure/virtual-network/create-vm-accelerated-networking-powershell) or [Linux (click for instructions)](https://docs.microsoft.com/en-us/azure/virtual-network/create-vm-accelerated-networking-cli) Azure VM, in order to maximize performance.
97
+
98
+
Without accelerated networking, IO that transits between your Azure VM and other Azure resources may be unnecessarily routed through a host and virtual switch situated between the VM and its network card. Having the host and virtual switch inline in the datapath not only increases latency and jitter in the communication channel, it also steals CPU cycles from the VM. With accelerated networking, the VM interfaces directly with the NIC without intermediaries; any network policy details which were being handled by the host and virtual switch are now handled in hardware at the NIC; the host and virtual switch are bypassed. Generally you can expect lower latency and higher throughput, as well as more *consistent* latency and decreased CPU utilization when you enable accelerated networking.
99
+
100
+
Limitations: accelerated networking must be supported on the VM OS, and can only be enabled when the VM is stopped and deallocated. The VM cannot be deployed with Azure Resource Manager.
101
+
102
+
Please see the [Windows](https://docs.microsoft.com/en-us/azure/virtual-network/create-vm-accelerated-networking-powershell) and [Linux](https://docs.microsoft.com/en-us/azure/virtual-network/create-vm-accelerated-networking-cli) instructions for more details.
95
103
96
104
## SDK Usage
97
105
***Install the most recent SDK**
@@ -106,7 +114,7 @@ So if you're asking "How can I improve my database performance?" consider the fo
106
114
107
115
***Use the lowest consistency level required for your application**
108
116
109
-
When you create a *CosmosClient*, the default consistency used if not explicitly set is *Session*. If *Session* consistency is not required by your application logic set the *Consistency* to *Eventual*. Note: it is recommended to use at least *Session* consistency in applications employing the Azure Cosmos DB Change Feed.
117
+
When you create a *CosmosClient*, the default consistency used if not explicitly set is *Session*. If *Session* consistency is not required by your application logic set the *Consistency* to *Eventual*. Note: it is recommended to use at least *Session* consistency in applications employing the Azure Cosmos DB Change Feed processor.
110
118
111
119
***Use Async API to max out provisioned throughput**
112
120
@@ -168,7 +176,9 @@ So if you're asking "How can I improve my database performance?" consider the fo
168
176
169
177
* ***ConnectionPolicy Configuration options for Direct mode***
170
178
171
-
As a first step, use the following recommended configuration settings below. Please contact the [Azure Cosmos DB team](mailto:[email protected]) if you run into issues on this particular topic.
179
+
These configuration settings control the behavior of the RNTBD architecture which governs Direct mode SDK behavior.
180
+
181
+
As a first step, use the following recommended configuration settings below. These *ConnectionPolicy* options are advanced configuration settings which can affect SDK performance in unexpected ways; we recommend users avoid modifying them unless they feel very comfortable in understanding the tradeoffs and it is absolutely necessary. Please contact the [Azure Cosmos DB team](mailto:[email protected]) if you run into issues on this particular topic.
172
182
173
183
If you are using Azure Cosmos DB as a reference database (that is, the database is used for many point read operations and few write operations), it may be acceptable to set *idleEndpointTimeout* to 0 (that is, no timeout).
174
184
@@ -189,21 +199,6 @@ So if you're asking "How can I improve my database performance?" consider the fo
189
199
| sendHangDetectionTime | "PT10S" |
190
200
| shutdownTimeout | "PT15S" |
191
201
192
-
* ***Programming tips for Direct mode***
193
-
194
-
Review the Azure Cosmos DB [Java SDK v4 Troubleshooting](troubleshoot-java-sdk-v4-sql.md) article as a baseline for resolving any Java SDK v4 issues.
195
-
196
-
Some important programming tips when using Direct mode:
197
-
198
-
+ **Use multithreading in your application for efficient TCP data transfer** - After making a request, your application should subscribe to receive data on another thread. Not doing so forces unintended "half-duplex" operation and the subsequent requests are blocked waiting for the previous request's reply.
199
-
200
-
+**Carry out compute-intensive workloads on a dedicated thread**-For similar reasons to the previous tip, operations such as complex data processing are best placed in a separate thread. A request that pulls in data from another data store (for example if the thread utilizes AzureCosmosDB and Spark data stores simultaneously) may experience increased latency and it is recommended to spawn an additional thread that awaits a response from the other data store.
201
-
202
-
+The underlying network IO in JavaSDK v4 is managed by Netty, see these [tips for avoiding coding patterns that block NettyIO threads](troubleshoot-java-sdk-v4-sql.md#invalid-coding-pattern-blocking-netty-io-thread).
203
-
204
-
+**Data modeling**-TheAzureCosmosDBSLA assumes document size to be less than 1KB. Optimizing your data model and programming to favor smaller document size will generally lead to decreased latency. If you are going to need storage and retrieval of docs larger than 1KB, the recommended approach is for documents to link to data in AzureBlobStorage.
205
-
206
-
207
202
* **Tuning parallel queries for partitioned collections**
208
203
209
204
Azure Cosmos DB SQL Java SDK v4 supports parallel queries, which enable you to query a partitioned collection in parallel. For more information, see [code samples](https://github.com/Azure-Samples/azure-cosmos-java-sql-api-samples) related to working with Java SDK v4. Parallel queries are designed to improve query latency and throughput over their serial counterpart.
@@ -220,10 +215,6 @@ So if you're asking "How can I improve my database performance?" consider the fo
220
215
221
216
Pre-fetching works the same way irrespective of the MaxDegreeOfParallelism, and there is a single buffer for the data from all partitions.
222
217
223
-
* **Implement backoff at getRetryAfterInMilliseconds intervals**
224
-
225
-
During performance testing, you should increase load until a small rate of requests get throttled. If throttled, the client application should backoff for the server-specified retry interval. Respecting the backoff ensures that you spend minimal amount of time waiting between retries.
226
-
227
218
***Scale out your client-workload**
228
219
229
220
If you are testing at high throughput levels, the client application may become the bottleneck due to the machine capping out on CPU or network utilization. If you reach this point, you can continue to push the AzureCosmosDB account further by scaling out your client applications across multiple servers.
@@ -244,7 +235,7 @@ So if you're asking "How can I improve my database performance?" consider the fo
244
235
245
236
In some applications, you may not require the full set of query results. In cases where you need to display only a few results, for example, if your user interfaceor application API returns only 10 results at a time, you can also decrease the page size to 10 to reduce the throughput consumed for reads and queries.
246
237
247
-
You may also set the page size using the setMaxItemCount method.
238
+
You may also set the preferred page size argument of the *byPage* method, rather than modifying the REST header field directly. Keep in mind that [x-ms-max-item-count](/rest/api/cosmos-db/common-cosmosdb-rest-request-headers) or the preferred page size argument of *byPage* are only setting an upper limit on page size, not an absolute requirement; so for a variety of reason you may see Azure Cosmos DB return pages which are smaller than your preferred page size.
0 commit comments