如何配置WaitHandle?

时间:2019-07-04 08:34:35

标签: c# elasticsearch profiling dottrace

我有以下代码将文档编入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函数中。这是可以理解的,因为那是我的代码等待完成的地方,但是对我来说很难找出我所有的时间在哪里。

线程正在等待几乎100%,我看不到任何活动: The threads are waiting for almost 100% enter image description here enter image description here enter image description here

0 个答案:

没有答案