be/src/runtime/workload_management/io_throttle.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <bvar/bvar.h> |
21 | | #include <stdint.h> |
22 | | |
23 | | #include <atomic> |
24 | | #include <condition_variable> |
25 | | #include <mutex> |
26 | | |
27 | | namespace doris { |
28 | | |
29 | | class IOThrottle { |
30 | | public: |
31 | 18 | IOThrottle() = default; |
32 | | |
33 | 0 | IOThrottle(std::string metric_name) : _metric_name(metric_name) {} |
34 | | |
35 | 18 | ~IOThrottle() = default; |
36 | | |
37 | | bool acquire(int64_t block_timeout_ms); |
38 | | |
39 | | // non-block acquire |
40 | | bool try_acquire(); |
41 | | |
42 | | void update_next_io_time(int64_t bytes); |
43 | | |
44 | | void set_io_bytes_per_second(int64_t read_bytes_per_second); |
45 | | |
46 | 0 | std::string metric_name() { return _metric_name; } |
47 | | |
48 | | private: |
49 | | std::mutex _mutex; |
50 | | std::condition_variable wait_condition; |
51 | | int64_t _next_io_time_micros {0}; |
52 | | std::atomic<int64_t> _io_bytes_per_second_limit {-1}; |
53 | | |
54 | | std::string _metric_name; |
55 | | }; |
56 | | }; // namespace doris |