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
There are three ways to connect to an Azure Cosmos DB account:
32
+
There are two [connectivity modes](./sql/sql-sdk-connection-modes.md) for Azure Cosmos DB, Direct mode and Gateway mode. With Gateway mode you can connect to either the standard gateway or the dedicated gateway depending on the endpoint you configure.
-[Gateway mode using the standard gateway](#connect-to-azure-cosmos-db-using-gateway-mode)
36
-
-[Gateway mode using the dedicated gateway](#connect-to-azure-cosmos-db-using-the-dedicated-gateway) (only available for SQL API accounts)
34
+
:::image type="content" source="./media/dedicated-gateway/connection-policy.png" alt-text="An image that shows how Cosmos DB connectivity modes work." border="false":::
37
35
38
36
### Connect to Azure Cosmos DB using direct mode
39
37
40
-
When you connect to Azure Cosmos DB using direct mode, your application connects directly to the Azure Cosmos DB backend. Even if you have many physical partitions, request routing is handled entirely client-side. Direct mode offers low latency because your application can communicate directly with the Azure Cosmos DB backend and doesn't need an intermediate network hop.
41
-
42
-
Graphical representation of direct mode connection:
43
-
44
-
:::image type="content" source="./media/dedicated-gateway/direct-mode.png" alt-text="An image that shows how Cosmos DB direct mode works" border="false":::
38
+
When you connect to Azure Cosmos DB using direct mode, your application connects directly to the Azure Cosmos DB backend. Even if you have many physical partitions, request routing is handled entirely client-side. Direct mode offers low latency because your application can communicate directly with the Azure Cosmos DB backend and doesn't need an intermediate network hop. If you choose to connect with direct mode your requests will not use the dedicated gateway or the integrated cache.
45
39
46
40
### Connect to Azure Cosmos DB using gateway mode
47
41
@@ -52,23 +46,21 @@ When connecting to Azure Cosmos DB with gateway mode, you can connect with eithe
52
46
***Standard gateway** - While the backend, which includes your provisioned throughput and storage, has dedicated capacity per container, the standard gateway is shared between many Azure Cosmos accounts. It is practical for many customers to share a standard gateway since the compute resources consumed by each individual customer is small.
53
47
***Dedicated gateway** - In this gateway, the backend and gateway both have dedicated capacity. The integrated cache requires a dedicated gateway because it requires significant CPU and memory that is specific to your Azure Cosmos account.
54
48
55
-
### Connect to Azure Cosmos DB using the dedicated gateway
56
-
57
-
You must connect to Azure Cosmos DB using the dedicated gateway in order to use the integrated cache. The dedicated gateway has a different endpoint from the standard one provided with your Azure Cosmos DB account. When you connect to your dedicated gateway endpoint, your application sends a request to the dedicated gateway, which then routes the request to different backend nodes. If possible, the integrated cache will serve the result.
49
+
You must connect to Azure Cosmos DB using the dedicated gateway in order to use the integrated cache. The dedicated gateway has a different endpoint from the standard one provided with your Azure Cosmos DB account, but requests are routed in the same way. When you connect to your dedicated gateway endpoint, your application sends a request to the dedicated gateway, which then routes the request to different backend nodes. If possible, the integrated cache will serve the result.
58
50
59
51
Diagram of gateway mode connection with a dedicated gateway:
60
52
61
-
:::image type="content" source="./media/dedicated-gateway/dedicated-gateway-mode.png" alt-text="An image that shows how the Cosmos DB dedicated gateway works" border="false":::
53
+
:::image type="content" source="./media/dedicated-gateway/dedicated-gateway-connection-policy.png" alt-text="An image that shows how the Cosmos DB dedicated gateway works." border="false":::
62
54
63
55
## Provisioning the dedicated gateway
64
56
65
57
A dedicated gateway cluster can be provisioned in Core (SQL) API accounts. A dedicated gateway cluster can have up to five nodes and you can add or remove nodes at any time. All dedicated gateway nodes within your account [share the same connection string](how-to-configure-integrated-cache.md#configuring-the-integrated-cache).
66
58
67
-
Dedicated gateway nodes are independent from one another. When you provision multiple dedicated gateway nodes, any single node can route any given request. In addition, each node has a separate integrated cache from the others. The cached data within each node depends on the data that was recently [written or read](integrated-cache.md#item-cache) through that specific node. In other words, if an item or query is cached on one node, it isn't necessarily cached on the others.
59
+
Dedicated gateway nodes are independent from one another. When you provision multiple dedicated gateway nodes, any single node can route any given request. In addition, each node has a separate integrated cache from the others. The cached data within each node depends on the data that was recently [written or read](integrated-cache.md#item-cache) through that specific node. If an item or query is cached on one node, it isn't necessarily cached on the others.
68
60
69
61
For development, we recommend starting with one node but for production, you should provision three or more nodes for high availability. [Learn how to provision a dedicated gateway cluster with an integrated cache](how-to-configure-integrated-cache.md). Provisioning multiple dedicated gateway nodes allows the dedicated gateway cluster to continue to route requests and serve cached data, even when one of the dedicated gateway nodes is unavailable.
70
62
71
-
The dedicated gateway is available in the following sizes:
63
+
The dedicated gateway is available in the following sizes. The integrated cache uses approximately 70% of the memory and the rest is reserved for routing requests to backend partitions.
72
64
73
65
|**Sku Name**|**vCPU**|**Memory**|
74
66
| ------------ | -------- | ----------- |
@@ -77,12 +69,12 @@ The dedicated gateway is available in the following sizes:
77
69
|**D16s**|**16**|**64 GB**|
78
70
79
71
> [!NOTE]
80
-
> Once created, you can add or remove dedicated gateway nodes, but you can't modify the size of the nodes. To change the size of your dedicated gateway nodes you can deprovision the cluster and provision it again in a different size.
72
+
> Once created, you can add or remove dedicated gateway nodes, but you can't modify the size of the nodes. To change the size of your dedicated gateway nodes you can deprovision the cluster and provision it again in a different size. This will result in a short period of downtime unless you change the connection string in your application to use the standard gateway during reprovisioning.
81
73
82
74
There are many different ways to provision a dedicated gateway:
83
75
84
76
-[Provision a dedicated gateway using the Azure Portal](how-to-configure-integrated-cache.md#provision-a-dedicated-gateway-cluster)
Copy file name to clipboardExpand all lines: articles/cosmos-db/how-to-configure-integrated-cache.md
+58-22Lines changed: 58 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ author: seesharprun
5
5
ms.service: cosmos-db
6
6
ms.subservice: cosmosdb-sql
7
7
ms.topic: conceptual
8
-
ms.date: 07/25/2022
8
+
ms.date: 08/02/2022
9
9
ms.author: sidandrews
10
10
ms.reviewer: jucocchi
11
11
---
@@ -21,7 +21,7 @@ This article describes how to provision a dedicated gateway, configure the integ
21
21
- An existing application that uses Azure Cosmos DB. If you don't have one, [here are some examples](https://github.com/AzureCosmosDB/labs).
22
22
- An existing [Azure Cosmos DB SQL (core) API account](create-cosmosdb-resources-portal.md).
23
23
24
-
## Provision a dedicated gateway cluster
24
+
## Provision the dedicated gateway
25
25
26
26
1. Navigate to an Azure Cosmos DB account in the Azure portal and select the **Dedicated Gateway** tab.
27
27
@@ -30,8 +30,8 @@ This article describes how to provision a dedicated gateway, configure the integ
30
30
2. Fill out the **Dedicated gateway** form with the following details:
31
31
32
32
***Dedicated Gateway** - Turn on the toggle to **Provisioned**.
33
-
***SKU** - Select a SKU with the required compute and memory size.
34
-
***Number of instances** - Number of nodes. For development purpose, we recommend starting with one node of the D4 size. Based on the amount of data you need to cache, you can increase the node size after initial testing.
33
+
***SKU** - Select a SKU with the required compute and memory size. The integrated cache will use approximately 70% of the memory, and the remaining 30% of memory is used for routing requests to the backend partitions.
34
+
***Number of instances** - Number of nodes. For development purpose, we recommend starting with one node of the D4 size. Based on the amount of data you need to cache and to achieve high availability, you can increase the node size after initial testing.
35
35
36
36
:::image type="content" source="./media/how-to-configure-integrated-cache/dedicated-gateway-input.png" alt-text="An image that shows sample input settings for creating a dedicated gateway cluster" lightbox="./media/how-to-configure-integrated-cache/dedicated-gateway-input.png" border="false":::
37
37
@@ -41,9 +41,9 @@ This article describes how to provision a dedicated gateway, configure the integ
41
41
42
42
## Configuring the integrated cache
43
43
44
-
1.When you create a dedicated gateway, an integrated cache is automatically provisioned. The integrated cache will use approximately 70% of the memory in the dedicated gateway. The remaining 30% of memory in the dedicated gateway is used for routing requests to the backend partitions.
44
+
When you create a dedicated gateway, an integrated cache is automatically provisioned.
45
45
46
-
2. Modify your application's connection string to use the new dedicated gateway endpoint.
46
+
1. Modify your application's connection string to use the new dedicated gateway endpoint.
47
47
48
48
The updated dedicated gateway connection string is in the **Keys** blade:
49
49
@@ -53,30 +53,36 @@ This article describes how to provision a dedicated gateway, configure the integ
53
53
54
54
You don’t need to modify the connection string in all applications using the same Azure Cosmos DB account. For example, you could have one `CosmosClient` connect using gateway mode and the dedicated gateway endpoint while another `CosmosClient` uses direct mode. In other words, adding a dedicated gateway doesn't impact the existing ways of connecting to Azure Cosmos DB.
55
55
56
-
3. If you're using the .NET or Java SDK, set the connection mode to [gateway mode](sql-sdk-connection-modes.md#available-connectivity-modes). This step isn't necessary for the Python and Node.js SDKs since they don't have additional options of connecting besides gateway mode.
56
+
2. If you're using the .NET or Java SDK, set the connection mode to [gateway mode](sql-sdk-connection-modes.md#available-connectivity-modes). This step isn't necessary for the Python and Node.js SDKs since they don't have additional options of connecting besides gateway mode.
57
57
58
58
> [!NOTE]
59
59
> If you are using the latest .NET or Java SDK version, the default connection mode is direct mode. In order to use the integrated cache, you must override this default.
60
60
61
-
4. If you're using the Java SDK, you must also manually set [contentResponseOnWriteEnabled](/java/api/com.azure.cosmos.cosmosclientbuilder.contentresponseonwriteenabled?view=azure-java-stable&preserve-view=true) to `true` within the `CosmosClientBuilder`. If you're using any other SDK, this value already defaults to `true`, so you don't need to make any changes.
62
-
63
61
## Adjust request consistency
64
62
65
-
You must adjust the request consistency to session or eventual. If not, the request will always bypass the integrated cache. The easiest way to configure a specific consistency for all read operations is to [set it at the account-level](consistency-levels.md#configure-the-default-consistency-level). You can also configure consistency at the [request-level](how-to-manage-consistency.md#override-the-default-consistency-level), which is recommended if you only want a subset of your reads to utilize the integrated cache.
63
+
You must ensure the request consistency is session or eventual. If not, the request will always bypass the integrated cache. The easiest way to configure a specific consistency for all read operations is to [set it at the account-level](consistency-levels.md#configure-the-default-consistency-level). You can also configure consistency at the [request-level](how-to-manage-consistency.md#override-the-default-consistency-level), which is recommended if you only want a subset of your reads to utilize the integrated cache.
66
64
67
65
> [!NOTE]
68
66
> If you are using the Python SDK, you **must** explicitly set the consistency level for each request. The default account-level setting will not automatically apply.
69
67
70
68
## Adjust MaxIntegratedCacheStaleness
71
69
72
-
Configure `MaxIntegratedCacheStaleness`, which is the maximum time in which you are willing to tolerate stale cached data. We recommend setting the `MaxIntegratedCacheStaleness` as high as possible because it will increase the likelihood that repeated point reads and queries can be cache hits. If you set `MaxIntegratedCacheStaleness` to 0, your read request will **never** use the integrated cache, regardless of the consistency level. When not configured, the default `MaxIntegratedCacheStaleness` is 5 minutes.
70
+
Configure `MaxIntegratedCacheStaleness`, which is the maximum time in which you are willing to tolerate stale cached data. It is recommended to set the `MaxIntegratedCacheStaleness` as high as possible because it will increase the likelihood that repeated point reads and queries can be cache hits. If you set `MaxIntegratedCacheStaleness` to 0, your read request will **never** use the integrated cache, regardless of the consistency level. When not configured, the default `MaxIntegratedCacheStaleness` is 5 minutes.
71
+
72
+
Adjusting the `MaxIntegratedCacheStaleness` is supported in these versions of each SDK:
73
+
74
+
| SDK | Supported versions | Comment |
75
+
| --- | ------------------ | ------- |
76
+
|**.NET SDK v3**|*>= 3.19.0-preview*| Currently supported in the preview SDK versions only. |
77
+
|**Java SDK v4**|*>= 4.16.0-beta*| Currently supported in the preview SDK versions only. |
78
+
|**Node.js SDK**|*>=3.16.0*| - |
79
+
|**Python SDK**|*>=4.3.0b3*| - |
73
80
74
-
**.NET**
81
+
### [.NET](#tab/dotnet)
75
82
76
83
```csharp
77
-
FeedIterator<Food>myQuery=container.GetItemQueryIterator<Food>(newQueryDefinition("SELECT * FROM c"), requestOptions: newQueryRequestOptions
84
+
FeedIterator<MyClass>myQuery=container.GetItemQueryIterator<MyClass>(newQueryDefinition("SELECT * FROM c"), requestOptions: newQueryRequestOptions
Finally, you can restart your application and verify integrated cache hits for repeated point reads or queries. Once you’ve modified your `CosmosClient` to use the dedicated gateway endpoint, all requests will be routed through the dedicated gateway.
134
+
Finally, you can restart your application and verify integrated cache hits for repeated point reads or queries by seeing if the request charge is 0. Once you’ve modified your `CosmosClient` to use the dedicated gateway endpoint, all requests will be routed through the dedicated gateway.
99
135
100
136
For a read request (point read or query) to utilize the integrated cache, **all** of the following criteria must be true:
0 commit comments