aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/server/executorthreadingservice.h
blob: e571e205f475d4c74e03d42ca041fd248a89ff60 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "executor_thread_service.h"
#include <vespa/searchcorespi/index/ithreadingservice.h>
#include <vespa/vespalib/util/threadstackexecutor.h>

namespace proton {

class ExecutorThreadingServiceStats;
class ThreadingServiceConfig;

/**
 * Implementation of IThreadingService using 2 underlying thread stack executors
 * with 1 thread each.
 */
class ExecutorThreadingService : public searchcorespi::index::IThreadingService
{
private:
    vespalib::ThreadExecutor                           & _sharedExecutor;
    vespalib::ThreadStackExecutor                        _masterExecutor;
    std::unique_ptr<vespalib::SyncableThreadExecutor>    _indexExecutor;
    std::unique_ptr<vespalib::SyncableThreadExecutor>    _summaryExecutor;
    ExecutorThreadService                                _masterService;
    ExecutorThreadService                                _indexService;
    ExecutorThreadService                                _summaryService;
    std::unique_ptr<vespalib::ISequencedTaskExecutor>    _indexFieldInverter;
    std::unique_ptr<vespalib::ISequencedTaskExecutor>    _indexFieldWriter;
    std::unique_ptr<vespalib::ISequencedTaskExecutor>    _attributeFieldWriter;
    std::unique_ptr<vespalib::ISequencedTaskExecutor>    _field_writer;
    vespalib::ISequencedTaskExecutor*                    _index_field_inverter_ptr;
    vespalib::ISequencedTaskExecutor*                    _index_field_writer_ptr;
    vespalib::ISequencedTaskExecutor*                    _attribute_field_writer_ptr;

    void syncOnce();
public:
    using OptimizeFor = vespalib::Executor::OptimizeFor;
    /**
     * Constructor.
     *
     * @stackSize The size of the stack of the underlying executors.
     * @cfg config used to set up all executors.
     */
    ExecutorThreadingService(vespalib::ThreadExecutor &sharedExecutor,
                             const ThreadingServiceConfig & cfg, uint32_t stackSize = 128 * 1024);
    ExecutorThreadingService(vespalib::ThreadExecutor &sharedExecutor, uint32_t num_treads = 1);
    ~ExecutorThreadingService() override;

    void sync_all_executors() override;

    void shutdown();

    void setTaskLimit(uint32_t taskLimit, uint32_t summaryTaskLimit);

    // Expose the underlying executors for stats fetching and testing.
    // TOD: Remove - This is only used for casting to check the underlying type
    vespalib::ThreadExecutor &getMasterExecutor() {
        return _masterExecutor;
    }
    vespalib::ThreadExecutor &getIndexExecutor() {
        return *_indexExecutor;
    }
    vespalib::ThreadExecutor &getSummaryExecutor() {
        return *_summaryExecutor;
    }

    searchcorespi::index::IThreadService &master() override {
        return _masterService;
    }
    searchcorespi::index::IThreadService &index() override {
        return _indexService;
    }

    searchcorespi::index::IThreadService &summary() override {
        return _summaryService;
    }
    vespalib::ThreadExecutor &shared() override {
        return _sharedExecutor;
    }

    vespalib::ISequencedTaskExecutor &indexFieldInverter() override;
    vespalib::ISequencedTaskExecutor &indexFieldWriter() override;
    vespalib::ISequencedTaskExecutor &attributeFieldWriter() override;
    ExecutorThreadingServiceStats getStats();
};

}