aboutsummaryrefslogtreecommitdiffstats
path: root/ydb/public/lib/ydb_cli/commands/topic_operations_scenario.h
blob: c5c92f79592cb714f63338d0af0bbcc6fecbf883 (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
#pragma once

#include <ydb/public/lib/ydb_cli/common/command.h>

#include <util/datetime/base.h>
#include <util/generic/fwd.h>
#include <util/system/types.h>

#include <atomic>
#include <future>
#include <memory>
#include <thread>
#include <vector>

class TLogBackend;
class TLog;

namespace NYdb {

class TDriver;

}

namespace NYdb::NConsoleClient {

class TTopicWorkloadStatsCollector;

class TTopicOperationsScenario {
public:
    TTopicOperationsScenario();

    int Run(const TClientCommand::TConfig& config);

    void EnsurePercentileIsValid() const;
    void EnsureWarmupSecIsValid() const;

    TDuration TotalSec;
    TDuration WindowSec;
    TDuration WarmupSec;
    bool Quiet;
    bool PrintTimestamp;
    double Percentile;
    TString TopicName;
    ui32 ProducerThreadCount;
    ui32 ConsumerThreadCount;
    ui32 ConsumerCount;
    size_t MessageSize;
    size_t MessageRate;
    size_t ByteRate;
    ui32 Codec;

protected:
    void StartConsumerThreads(std::vector<std::future<void>>& threads,
                              const TString& database);
    void StartProducerThreads(std::vector<std::future<void>>& threads,
                              ui32 partitionCount,
                              ui32 partitionSeed,
                              const std::vector<TString>& generatedMessages);
    void JoinThreads(const std::vector<std::future<void>>& threads);

    bool AnyErrors() const;
    bool AnyIncomingMessages() const;
    bool AnyOutgoingMessages() const;

    std::unique_ptr<TDriver> Driver;
    std::shared_ptr<TLog> Log;
    std::shared_ptr<std::atomic_bool> ErrorFlag;
    std::shared_ptr<TTopicWorkloadStatsCollector> StatsCollector;

private:
    virtual int DoRun(const TClientCommand::TConfig& config) = 0;

    static THolder<TLogBackend> MakeLogBackend(TClientCommand::TConfig::EVerbosityLevel level);

    void InitLog(const TClientCommand::TConfig& config);
    void InitDriver(const TClientCommand::TConfig& config);
    void InitStatsCollector();
};

}