Created
October 23, 2019 17:28
-
-
Save afscrome/0b8073b748a0da8185b9d93770d0e26e to your computer and use it in GitHub Desktop.
Cosmos Slow Opening
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If you run the following with the cosmos emulator disabled, it takes about 2 minutes before the OpenAsync call fails | |
// Comment out the SetLocation line, and it takes about 8. | |
using System; | |
using System.Diagnostics; | |
using System.Threading.Tasks; | |
using Microsoft.Azure.Documents.Client; | |
namespace CosmosTimeoutTest | |
{ | |
class Program | |
{ | |
static async Task Main(string[] args) | |
{ | |
var connectionPolicy = new ConnectionPolicy | |
{ | |
ConnectionMode = ConnectionMode.Direct, | |
ConnectionProtocol = Protocol.Tcp, | |
RequestTimeout = TimeSpan.FromMilliseconds(100), | |
EnableReadRequestsFallback = true, | |
EnableEndpointDiscovery = true, | |
RetryOptions = new RetryOptions | |
{ | |
MaxRetryAttemptsOnThrottledRequests = 0, | |
MaxRetryWaitTimeInSeconds = 0 | |
} | |
}; | |
//COMMENT THE FOLLOWING LINE OUT | |
connectionPolicy.SetCurrentLocation("North Europe"); | |
var client = new DocumentClient( | |
new Uri("https://localhost:8081"), | |
"C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==", | |
connectionPolicy); | |
var stopwatch = new Stopwatch(); | |
stopwatch.Start(); | |
try | |
{ | |
await client.OpenAsync(); | |
} | |
finally | |
{ | |
Console.WriteLine($"Elapsed: {stopwatch.Elapsed}"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment