Skip to content

Instantly share code, notes, and snippets.

@afscrome
Created October 23, 2019 17:28
Show Gist options
  • Save afscrome/0b8073b748a0da8185b9d93770d0e26e to your computer and use it in GitHub Desktop.
Save afscrome/0b8073b748a0da8185b9d93770d0e26e to your computer and use it in GitHub Desktop.
Cosmos Slow Opening
// 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