我有以下代码将文档编入ElasticSearch,并希望了解花费最多的时间。
private void DoIndex(IEnumerable<TDocument> documents, LanguageCode languageCode, ElasticSettings elasticSettings, string indexName, List<Exception> errors)
{
var waitHandle = new CountdownEvent(1);
var bulkAll = ElasticClient.BulkAll(Project(documents, languageCode), b => b
.BackOffRetries(elasticSettings.BulkBackOffRetries)
.BackOffTime(elasticSettings.BulkBackOffTime)
.RefreshOnCompleted()
.MaxDegreeOfParallelism(elasticSettings.BulkThreadCount)
.Refresh(Refresh.False)
.Size(500)
.Index(indexName));
bulkAll.Subscribe(new BulkAllObserver(
onError: exception =>
{
errors.Add(exception);
Log.Error(exception, "ES indexing failed for batch.");
},
onCompleted: () => waitHandle.Signal(),
onNext: response =>
{
Logger.Log($"Processed {response.Page * 500} documents");
}));
waitHandle.Wait(CancellationToken);
}
当我附加一个事件探查器(在我的情况下为dotTrace)时,我看到99%的时间都花在了我的代码的Wait
函数中。这是可以理解的,因为那是我的代码等待完成的地方,但是对我来说很难找出我所有的时间在哪里。