diff --git a/src/Microsoft.Health.Fhir.CosmosDb.Core/Configs/CosmosDataStoreConfiguration.cs b/src/Microsoft.Health.Fhir.CosmosDb.Core/Configs/CosmosDataStoreConfiguration.cs index d0aab0076b..7c89638c3e 100644 --- a/src/Microsoft.Health.Fhir.CosmosDb.Core/Configs/CosmosDataStoreConfiguration.cs +++ b/src/Microsoft.Health.Fhir.CosmosDb.Core/Configs/CosmosDataStoreConfiguration.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------------------------------------------- +using System; using System.Collections.Generic; using Microsoft.Azure.Cosmos; @@ -30,6 +31,24 @@ public class CosmosDataStoreConfiguration public ConnectionMode ConnectionMode { get; set; } = ConnectionMode.Direct; + // Default value is indefinate, recommended value is 20m - 24 hours. Setting to 1 hour. + public TimeSpan? IdleTcpConnectionTimeout { get; set; } = TimeSpan.FromHours(1); + + // Default value is 5 seconds, recommended value is 1 second. + public TimeSpan? OpenTcpConnectionTimeout { get; set; } = TimeSpan.FromSeconds(1); + + // Default value is 30, recommended value is 30. Leaving null to use the SDK default. + public int? MaxRequestsPerTcpConnection { get; set; } + + // Default value is 65535, recommended value is 65535. Leaving null to use the SDK default. + public int? MaxTcpConnectionsPerEndpoint { get; set; } + + // Default value is PortReuseMode.ReuseUnicastPort, recommended value is PortReuseMode.ReuseUnicastPort. Leaving null to use the SDK default. + public PortReuseMode? PortReuseMode { get; set; } + + // Default value is true, recommended value is true. Leaving null to use the SDK default. + public bool EnableTcpConnectionEndpointRediscovery { get; set; } + public ConsistencyLevel? DefaultConsistencyLevel { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "This is a configuration class")] diff --git a/src/Microsoft.Health.Fhir.CosmosDb/Features/Storage/FhirCosmosClientInitializer.cs b/src/Microsoft.Health.Fhir.CosmosDb/Features/Storage/FhirCosmosClientInitializer.cs index edd3458885..1cf92bfce2 100644 --- a/src/Microsoft.Health.Fhir.CosmosDb/Features/Storage/FhirCosmosClientInitializer.cs +++ b/src/Microsoft.Health.Fhir.CosmosDb/Features/Storage/FhirCosmosClientInitializer.cs @@ -137,7 +137,13 @@ private CosmosClient CreateCosmosClientInternal(CosmosDataStoreConfiguration con } else { - builder.WithConnectionModeDirect(enableTcpConnectionEndpointRediscovery: true); + builder.WithConnectionModeDirect( + idleTcpConnectionTimeout: configuration.IdleTcpConnectionTimeout, + openTcpConnectionTimeout: configuration.OpenTcpConnectionTimeout, + maxRequestsPerTcpConnection: configuration.MaxRequestsPerTcpConnection, + maxTcpConnectionsPerEndpoint: configuration.MaxTcpConnectionsPerEndpoint, + portReuseMode: configuration.PortReuseMode, + enableTcpConnectionEndpointRediscovery: configuration.EnableTcpConnectionEndpointRediscovery); } builder