Skip to content

Commit 4916d22

Browse files
committed
More fixes/clean up
1 parent 924eb70 commit 4916d22

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

samples/documentdb-benchmark/App.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<gcServer enabled="true"/>
88
</runtime>
99
<appSettings>
10-
<add key="EndPointUrl" value="https://FILLME.azure.com:443/"/>
10+
<add key="EndPointUrl" value="https://FILLME.documents.azure.com:443/"/>
1111
<add key="AuthorizationKey" value="FILLME"/>
1212

1313
<add key="DatabaseName" value="db"/>
@@ -18,7 +18,7 @@
1818
<add key="ShouldCleanupOnStart" value="false"/>
1919
<add key="ShouldCleanupOnFinish" value="false"/>
2020
<add key="DegreeOfParallelism" value="500"/>
21-
<add key="NumberOfDocumentsToInsert" value="10000"/>
21+
<add key="NumberOfDocumentsToInsert" value="100000"/>
2222

2323
<add key="CollectionPartitionKey" value="/partitionKey"/>
2424
<add key="DocumentTemplateFile" value="Player.json"/>

samples/documentdb-benchmark/Program.cs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -361,52 +361,56 @@ private DocumentCollection GetCollectionIfExists(string databaseName, string col
361361
public static async Task<V> ExecuteWithRetries<V>(DocumentClient client, Func<Task<V>> function, bool shouldLogRetries = false)
362362
{
363363
TimeSpan sleepTime = TimeSpan.Zero;
364+
int[] expectedStatusCodes = new int[] { 429, 400, 503 };
364365

365366
while (true)
366367
{
367368
try
368369
{
369370
return await function();
370371
}
371-
catch (DocumentClientException de)
372-
{
373-
if ((int)de.StatusCode != 429 && (int)de.StatusCode != 400 && (int)de.StatusCode != 503)
374-
{
375-
Trace.TraceError(de.ToString());
376-
throw de;
377-
}
378-
379-
sleepTime = de.RetryAfter;
380-
}
381372
catch (System.Net.Http.HttpRequestException)
382373
{
383374
sleepTime = TimeSpan.FromSeconds(1);
384375
}
385-
catch (AggregateException ae)
376+
catch (Exception e)
386377
{
387-
if (!(ae.InnerException is DocumentClientException))
378+
DocumentClientException de;
379+
if (!TryExtractDocumentClientException(e, out de))
388380
{
389-
Trace.TraceError(ae.ToString());
390381
throw;
391382
}
392383

393-
DocumentClientException de = (DocumentClientException)ae.InnerException;
394-
if ((int)de.StatusCode != 429 && (int)de.StatusCode != 400 && (int)de.StatusCode != 503)
384+
sleepTime = de.RetryAfter;
385+
if (shouldLogRetries)
395386
{
396-
Trace.TraceError(de.ToString());
397-
throw de;
387+
Console.WriteLine("Retrying after sleeping for {0}", sleepTime);
398388
}
399-
400-
sleepTime = de.RetryAfter;
401389
}
402390

403-
if (shouldLogRetries)
391+
await Task.Delay(sleepTime);
392+
}
393+
}
394+
395+
private static bool TryExtractDocumentClientException(Exception e, out DocumentClientException de)
396+
{
397+
if (e is DocumentClientException)
398+
{
399+
de = (DocumentClientException)e;
400+
return true;
401+
}
402+
403+
if (e is AggregateException)
404+
{
405+
if (e.InnerException is DocumentClientException)
404406
{
405-
Console.WriteLine("Retrying after sleeping for {0}", sleepTime);
407+
de = (DocumentClientException)e.InnerException;
408+
return true;
406409
}
407-
408-
await Task.Delay(sleepTime);
409410
}
411+
412+
de = null;
413+
return false;
410414
}
411415
}
412416
}

0 commit comments

Comments
 (0)