Skip to content

Commit 5df0898

Browse files
removing code snippet
1 parent e743a6c commit 5df0898

File tree

1 file changed

+3
-46
lines changed

1 file changed

+3
-46
lines changed

articles/search/tutorial-optimize-indexing-pushapi.md

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ public static async Task TestBatchSizes(ISearchIndexClient indexClient, int min
179179
// Pausing 2 seconds to let the search service catch its breath
180180
Thread.Sleep(2000);
181181
}
182+
}
182183
```
183184

184185
Because not all documents are the same size (although they are in this sample), we estimate the size of the data we're sending to the search service using the function below. The function converts the object to json and then converts the json to an array of bytes to determine its size:
@@ -282,58 +283,14 @@ do
282283
} while (true);
283284
```
284285

285-
```csharp
286-
public static async Task IndexData(ISearchIndexClient indexClient, List<Hotel> hotels, int batchSize, int numThreads)
287-
{
288-
int numDocs = hotels.Count;
289-
Console.WriteLine("Uploading {0} documents...\n", numDocs.ToString());
290-
291-
DateTime startTime = DateTime.Now;
292-
Console.WriteLine("Started at: {0} \n", startTime);
293-
Console.WriteLine("Creating {0} threads...\n", numThreads);
294-
295-
// Creating a list to hold active tasks
296-
List<Task<DocumentIndexResult>> uploadTasks = new List<Task<DocumentIndexResult>>();
297-
298-
for (int i = 0; i < numDocs; i += batchSize)
299-
{
300-
List<Hotel> hotelBatch = hotels.GetRange(i, batchSize);
301-
var task = ExponentialBackoffAsync(indexClient, hotelBatch, i);
302-
uploadTasks.Add(task);
303-
Console.WriteLine("Sending a batch of {0} docs starting with doc {1}...\n", batchSize, i);
304-
305-
// Checking if we've hit the specified number of threads
306-
if (uploadTasks.Count >= numThreads)
307-
{
308-
Task<DocumentIndexResult> firstTaskFinished = await Task.WhenAny(uploadTasks);
309-
Console.WriteLine("Finished a thread, kicking off another...");
310-
uploadTasks.Remove(firstTaskFinished);
311-
}
312-
}
313-
314-
// waiting for remaining results to finish
315-
await Task.WhenAll(uploadTasks);
316-
317-
DateTime endTime = DateTime.Now;
318-
319-
TimeSpan runningTime = endTime - startTime;
320-
Console.WriteLine("\nEnded at: {0} \n", endTime);
321-
Console.WriteLine("Upload time total: {0}", runningTime);
322-
323-
double timePerBatch = Math.Round(runningTime.TotalMilliseconds / (numDocs / batchSize), 4);
324-
Console.WriteLine("Upload time per batch: {0} ms", timePerBatch);
325-
326-
double timePerDoc = Math.Round(runningTime.TotalMilliseconds / numDocs, 4);
327-
Console.WriteLine("Upload time per document: {0} ms \n", timePerDoc);
328-
}
329-
```
330-
331286
```cmd
332287
ExponentialBackoff.IndexData(indexClient, hotels, 1000, 8).Wait();
333288
```
334289

335290
![Output of index data function](media/tutorial-optimize-data-indexing/index-data-start.png "Output of index data function")
336291

292+
When a batch of documents fails, an error is printed out indicating the failure and that the batch is being retried:
293+
337294
![Error from index data function](media/tutorial-optimize-data-indexing/index-data-error.png "Output of test batch size function")
338295

339296
## 6 - Explore index

0 commit comments

Comments
 (0)