aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/QueryPipeline/ExecutionSpeedLimits.h
blob: 63658462c9fc67a66b8490661cd32eb77a86bb9d (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
#pragma once

#include <Poco/Timespan.h>
#include <base/types.h>
#include <QueryPipeline/SizeLimits.h>

class Stopwatch;

namespace DB
{

/// Limits for query execution speed.
class ExecutionSpeedLimits
{
public:
    /// For rows per second.
    size_t min_execution_rps = 0;
    size_t max_execution_rps = 0;
    /// For bytes per second.
    size_t min_execution_bps = 0;
    size_t max_execution_bps = 0;

    Poco::Timespan max_execution_time = 0;
    /// Verify that the speed is not too low after the specified time has elapsed.
    Poco::Timespan timeout_before_checking_execution_speed = 0;

    /// Pause execution in case if speed limits were exceeded.
    void throttle(size_t read_rows, size_t read_bytes, size_t total_rows_to_read, UInt64 total_elapsed_microseconds) const;

    bool checkTimeLimit(const Stopwatch & stopwatch, OverflowMode overflow_mode) const;
};

}