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.md
+24-17Lines changed: 24 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,9 @@ So if you're asking "How can I improve my database performance?" consider the fo
30
30
31
31
* Gateway Mode
32
32
33
-
Gateway Mode is supported on all SDK platforms and is the configured default for [SDK V2](sql-api-sdk-dotnet.md). If your application runs within a corporate network with strict firewall restrictions, Gateway Mode is the best choice since it uses the standard HTTPS port and a single endpoint. The performance tradeoff, however, is that Gateway Mode involves an additional network hop every time data is read or written to Azure Cosmos DB. Because of this, Direct Mode offers better performance due to fewer network hops. Gateway connection mode is also recommended when you run applications in environments with limited number of socket connections, for example when using Azure Functions or if you are on a consumption plan.
33
+
Gateway Mode is supported on all SDK platforms and is the configured default for [SDK V2](sql-api-sdk-dotnet.md). If your application runs within a corporate network with strict firewall restrictions, Gateway Mode is the best choice since it uses the standard HTTPS port and a single endpoint. The performance tradeoff, however, is that Gateway Mode involves an additional network hop every time data is read or written to Azure Cosmos DB. Because of this, Direct Mode offers better performance due to fewer network hops. Gateway connection mode is also recommended when you run applications in environments with limited number of socket connections.
34
+
35
+
When using the SDK in Azure Functions, particularly in Consumption Plan, be mindful of the current [limits in connections](../azure-functions/manage-connections.md). In that case, Gateway Mode might be recommended if you are also working with other HTTP based clients within your Azure Functions application.
34
36
35
37
* Direct Mode
36
38
@@ -46,26 +48,26 @@ So if you're asking "How can I improve my database performance?" consider the fo
46
48
47
49
Azure Cosmos DB offers a simple and open RESTful programming model over HTTPS. Additionally, it offers an efficient TCP protocol, which is also RESTful in its communication model and is available through the .NET client SDK. Both Direct TCP and HTTPS use SSL for initial authentication and encrypting traffic. For best performance, use the TCP protocol when possible.
48
50
49
-
For the SDK V2, the Connectivity Mode is configured during the construction of the DocumentClient instance with the ConnectionPolicy parameter. If Direct Mode is used, the Protocol can also be set within the ConnectionPolicy parameter.
51
+
For SDK V3, the Connectivity Mode is configured during the construction of the CosmosClient instance, as part of the CosmosClientOptions.
EachDocumentClientinstanceisthread-safeandperformsefficientconnectionmanagementandaddresscaching when operating in Direct Mode. To allow efficient connection management and better performance by the SDK client, it is recommended to use a single instance per AppDomain for the lifetime of the application.
AzureCosmosDBrequestsaremadeoverHTTPS/RESTwhenusingGatewaymode, andaresubjectedtothedefaultconnectionlimitperhostnameorIPaddress. YoumayneedtosettheMaxConnectionstoahighervalue (100-1000) sothattheclientlibrarycanutilizemultiplesimultaneousconnectionstoAzureCosmosDB. Inthe .NETSDK1.8.0andabove, thedefaultvaluefor [ServicePointManager.DefaultConnectionLimit](https://msdn.microsoft.com/library/system.net.servicepointmanager.defaultconnectionlimit.aspx) is 50 and to change the value, you can set the [Documents.Client.ConnectionPolicy.MaxConnectionLimit](https://msdn.microsoft.com/library/azure/microsoft.azure.documents.client.connectionpolicy.maxconnectionlimit.aspx) to a higher value.
SQL .NETSDKversion1.9.0andabovesupportparallelqueries, whichenableyoutoqueryapartitionedcollectioninparallel. Formoreinformation, see [codesamples](https://github.com/Azure/azure-documentdb-dotnet/blob/master/samples/code-samples/Queries/Program.cs) related to working with the SDKs. Parallel queries are designed to improve query latency and throughput over their serial counterpart. Parallel queries provide two parameters that users can tune to custom-fit their requirements, (a) MaxDegreeOfParallelism: to control the maximum number of partitions then can be queried in parallel, and (b) MaxBufferedItemCount: to control the number of pre-fetched results.
119
126
@@ -126,10 +133,10 @@ So if you're asking "How can I improve my database performance?" consider the fo
@@ -164,11 +171,11 @@ So if you're asking "How can I improve my database performance?" consider the fo
164
171
165
172
Whenaqueryisexecuted, theresultingdataissentwithinaTCPpacket. Ifyouspecifytoolowvaluefor `maxItemCount`, thenumberoftripsrequiredtosendthedatawithintheTCPpacketarehigh, whichimpactstheperformance. Soifyouarenotsurewhatvaluetosetfor `maxItemCount` property, it's best to set it to -1 and let the SDK choose the default value.
166
173
167
-
10. **Increasenumberofthreads/tasks**
174
+
11. **Increasenumberofthreads/tasks**
168
175
169
176
See [Increasenumberofthreads/tasks](#increase-threads) intheNetworkingsection.
170
177
171
-
11. **Use64-bithostprocessing**
178
+
12. **Use64-bithostprocessing**
172
179
173
180
TheSQLSDKworksina32-bithostprocesswhenyouareusingSQL .NETSDKversion1.11.4andabove. However, ifyouareusingcrosspartitionqueries, 64-bithostprocessingisrecommendedforimprovedperformance. Thefollowingtypesofapplicationshave 32-bithostprocessasthedefault, soinordertochangethatto64-bit, followthesestepsbasedonthetypeofyourapplication:
0 commit comments