Skip to content

Instantly share code, notes, and snippets.

@kevinkuszyk
Last active September 1, 2016 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinkuszyk/26189b4d6508a547133675e0bbfa5a31 to your computer and use it in GitHub Desktop.
Save kevinkuszyk/26189b4d6508a547133675e0bbfa5a31 to your computer and use it in GitHub Desktop.
Gist to show how the first request to Azure Document DB is much slower than subsequent requests. See: http://stackoverflow.com/questions/39272563/why-is-the-first-request-to-azure-document-db-much-slower-than-subsequent-reques
Stopwatch stopwatch = new Stopwatch();
Dictionary<string, TimeSpan> times = new Dictionary<string, System.TimeSpan>();
async Task Main()
{
var endpoint = "";
var key = "";
var connectionPolicy = new ConnectionPolicy
{
ConnectionMode = ConnectionMode.Direct,
ConnectionProtocol = Protocol.Tcp
};
Start();
var client = new DocumentClient(new Uri(endpoint), key, connectionPolicy);
Stop("New up client");
Start();
var collection = UriFactory.CreateDocumentCollectionUri("test", "TestCollection");
Stop("New up collection uri");
Start();
await client.OpenAsync();
Stop("Open client");
for (int i = 0; i < 5; i++)
{
var test = new Test { Foo = $"Test doc {i}" };
Start();
await client.CreateDocumentAsync(collection, test);
Stop($"Save doc {i}");
}
times.Dump();
}
class Test
{
public string id { get; set; }
public string Foo { get; set; }
}
void Start()
{
stopwatch.Reset();
stopwatch.Start();
}
void Stop(string desc)
{
stopwatch.Stop();
times.Add(desc, stopwatch.Elapsed);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment