be/src/runtime/workload_management/io_context.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 "common/factory_creator.h" |
21 | | #include "runtime/runtime_profile.h" |
22 | | #include "runtime/workload_management/io_throttle.h" |
23 | | |
24 | | namespace doris { |
25 | | |
26 | | class ResourceContext; |
27 | | |
28 | | class IOContext : public std::enable_shared_from_this<IOContext> { |
29 | | ENABLE_FACTORY_CREATOR(IOContext); |
30 | | |
31 | | public: |
32 | | /* |
33 | | * 1. operate them thread-safe. |
34 | | * 2. all tasks are unified. |
35 | | * 3. should not be operated frequently, use local variables to update Counter. |
36 | | */ |
37 | | struct Stats { |
38 | | RuntimeProfile::Counter* scan_rows_counter_; |
39 | | RuntimeProfile::Counter* scan_bytes_counter_; |
40 | | RuntimeProfile::Counter* scan_bytes_from_local_storage_counter_; |
41 | | RuntimeProfile::Counter* scan_bytes_from_remote_storage_counter_; |
42 | | RuntimeProfile::Counter* bytes_write_into_cache_counter_; |
43 | | |
44 | | // number rows returned by query. |
45 | | // only set once by result sink when closing. |
46 | | RuntimeProfile::Counter* returned_rows_counter_; |
47 | | RuntimeProfile::Counter* process_rows_counter_; |
48 | | RuntimeProfile::Counter* shuffle_send_bytes_counter_; |
49 | | RuntimeProfile::Counter* shuffle_send_rows_counter_; |
50 | | |
51 | | RuntimeProfile::Counter* spill_write_bytes_to_local_storage_counter_; |
52 | | RuntimeProfile::Counter* spill_read_bytes_from_local_storage_counter_; |
53 | | RuntimeProfile::Counter* spill_write_bytes_to_remote_storage_counter_; |
54 | | RuntimeProfile::Counter* spill_read_bytes_from_remote_storage_counter_; |
55 | | RuntimeProfile::Counter* spill_remote_read_requests_counter_; |
56 | | |
57 | 0 | RuntimeProfile* profile() { return profile_.get(); } |
58 | 145k | void init_profile() { |
59 | 145k | profile_ = std::make_unique<RuntimeProfile>("MemoryContext"); |
60 | 145k | scan_rows_counter_ = ADD_COUNTER(profile_, "ScanRows", TUnit::UNIT); |
61 | 145k | scan_bytes_counter_ = ADD_COUNTER(profile_, "ScanBytes", TUnit::BYTES); |
62 | 145k | scan_bytes_from_local_storage_counter_ = |
63 | 145k | ADD_COUNTER(profile_, "ScanBytesFromLocalStorage", TUnit::BYTES); |
64 | 145k | scan_bytes_from_remote_storage_counter_ = |
65 | 145k | ADD_COUNTER(profile_, "ScanBytesFromRemoteStorage", TUnit::BYTES); |
66 | 145k | bytes_write_into_cache_counter_ = |
67 | 145k | ADD_COUNTER(profile_, "BytesWriteIntoCache", TUnit::BYTES); |
68 | 145k | returned_rows_counter_ = ADD_COUNTER(profile_, "ReturnedRows", TUnit::UNIT); |
69 | 145k | process_rows_counter_ = ADD_COUNTER(profile_, "ProcessRows", TUnit::UNIT); |
70 | 145k | shuffle_send_bytes_counter_ = ADD_COUNTER(profile_, "ShuffleSendBytes", TUnit::BYTES); |
71 | 145k | shuffle_send_rows_counter_ = |
72 | 145k | ADD_COUNTER(profile_, "ShuffleSendRowsCounter_", TUnit::UNIT); |
73 | 145k | spill_write_bytes_to_local_storage_counter_ = |
74 | 145k | ADD_COUNTER(profile_, "SpillWriteBytesToLocalStorage", TUnit::BYTES); |
75 | 145k | spill_read_bytes_from_local_storage_counter_ = |
76 | 145k | ADD_COUNTER(profile_, "SpillReadBytesFromLocalStorage", TUnit::BYTES); |
77 | 145k | spill_write_bytes_to_remote_storage_counter_ = |
78 | 145k | ADD_COUNTER(profile_, "SpillWriteBytesToRemoteStorage", TUnit::BYTES); |
79 | 145k | spill_read_bytes_from_remote_storage_counter_ = |
80 | 145k | ADD_COUNTER(profile_, "SpillReadBytesFromRemoteStorage", TUnit::BYTES); |
81 | 145k | spill_remote_read_requests_counter_ = |
82 | 145k | ADD_COUNTER(profile_, "SpillRemoteReadRequests", TUnit::UNIT); |
83 | 145k | } |
84 | 0 | std::string debug_string() { return profile_->pretty_print(); } |
85 | | |
86 | | private: |
87 | | std::unique_ptr<RuntimeProfile> profile_; |
88 | | }; |
89 | | |
90 | 145k | IOContext() { stats_.init_profile(); } |
91 | 145k | virtual ~IOContext() = default; |
92 | | |
93 | 0 | RuntimeProfile* stats_profile() { return stats_.profile(); } |
94 | | |
95 | 15 | int64_t scan_rows() const { return stats_.scan_rows_counter_->value(); } |
96 | 9 | int64_t scan_bytes() const { return stats_.scan_bytes_counter_->value(); } |
97 | 3 | int64_t scan_bytes_from_local_storage() const { |
98 | 3 | return stats_.scan_bytes_from_local_storage_counter_->value(); |
99 | 3 | } |
100 | 6 | int64_t scan_bytes_from_remote_storage() const { |
101 | 6 | return stats_.scan_bytes_from_remote_storage_counter_->value(); |
102 | 6 | } |
103 | 3 | int64_t bytes_write_into_cache() const { |
104 | 3 | return stats_.bytes_write_into_cache_counter_->value(); |
105 | 3 | } |
106 | 3 | int64_t returned_rows() const { return stats_.returned_rows_counter_->value(); } |
107 | 5 | int64_t process_rows() const { return stats_.process_rows_counter_->value(); } |
108 | 3 | int64_t shuffle_send_bytes() const { return stats_.shuffle_send_bytes_counter_->value(); } |
109 | 3 | int64_t shuffle_send_rows() const { return stats_.shuffle_send_rows_counter_->value(); } |
110 | | |
111 | 4 | int64_t spill_write_bytes_to_local_storage() const { |
112 | 4 | return stats_.spill_write_bytes_to_local_storage_counter_->value(); |
113 | 4 | } |
114 | | |
115 | 4 | int64_t spill_read_bytes_from_local_storage() const { |
116 | 4 | return stats_.spill_read_bytes_from_local_storage_counter_->value(); |
117 | 4 | } |
118 | | |
119 | 4 | int64_t spill_write_bytes_to_remote_storage() const { |
120 | 4 | return stats_.spill_write_bytes_to_remote_storage_counter_->value(); |
121 | 4 | } |
122 | | |
123 | 11 | int64_t spill_read_bytes_from_remote_storage() const { |
124 | 11 | return stats_.spill_read_bytes_from_remote_storage_counter_->value(); |
125 | 11 | } |
126 | | |
127 | 7 | int64_t spill_remote_read_requests() const { |
128 | 7 | return stats_.spill_remote_read_requests_counter_->value(); |
129 | 7 | } |
130 | | |
131 | 6 | void update_scan_rows(int64_t delta) const { stats_.scan_rows_counter_->update(delta); } |
132 | 5 | void update_scan_bytes(int64_t delta) const { stats_.scan_bytes_counter_->update(delta); } |
133 | 0 | void update_scan_bytes_from_local_storage(int64_t delta) const { |
134 | 0 | stats_.scan_bytes_from_local_storage_counter_->update(delta); |
135 | 0 | } |
136 | 2 | void update_scan_bytes_from_remote_storage(int64_t delta) const { |
137 | 2 | stats_.scan_bytes_from_remote_storage_counter_->update(delta); |
138 | 2 | } |
139 | 0 | void update_bytes_write_into_cache(int64_t delta) const { |
140 | 0 | stats_.bytes_write_into_cache_counter_->update(delta); |
141 | 0 | } |
142 | 0 | void update_returned_rows(int64_t delta) const { stats_.returned_rows_counter_->update(delta); } |
143 | 1.07k | void update_process_rows(int64_t delta) const { stats_.process_rows_counter_->update(delta); } |
144 | 0 | void update_shuffle_send_bytes(int64_t delta) const { |
145 | 0 | stats_.shuffle_send_bytes_counter_->update(delta); |
146 | 0 | } |
147 | 0 | void update_shuffle_send_rows(int64_t delta) const { |
148 | 0 | stats_.shuffle_send_rows_counter_->update(delta); |
149 | 0 | } |
150 | | |
151 | 711 | void update_spill_write_bytes_to_local_storage(int64_t delta) const { |
152 | 711 | stats_.spill_write_bytes_to_local_storage_counter_->update(delta); |
153 | 711 | } |
154 | | |
155 | 670 | void update_spill_read_bytes_from_local_storage(int64_t delta) const { |
156 | 670 | stats_.spill_read_bytes_from_local_storage_counter_->update(delta); |
157 | 670 | } |
158 | | |
159 | 239 | void update_spill_write_bytes_to_remote_storage(int64_t delta) const { |
160 | 239 | stats_.spill_write_bytes_to_remote_storage_counter_->update(delta); |
161 | 239 | } |
162 | | |
163 | 65 | void update_spill_read_bytes_from_remote_storage(int64_t delta) const { |
164 | 65 | stats_.spill_read_bytes_from_remote_storage_counter_->update(delta); |
165 | 65 | } |
166 | | |
167 | 65 | void update_spill_remote_read_requests(int64_t delta) const { |
168 | 65 | stats_.spill_remote_read_requests_counter_->update(delta); |
169 | 65 | } |
170 | | |
171 | 0 | IOThrottle* io_throttle() { |
172 | 0 | // TODO: get io throttle from workload group |
173 | 0 | return nullptr; |
174 | 0 | } |
175 | | |
176 | | protected: |
177 | | friend class ResourceContext; |
178 | | |
179 | 145k | void set_resource_ctx(ResourceContext* resource_ctx) { resource_ctx_ = resource_ctx; } |
180 | | |
181 | | Stats stats_; |
182 | | ResourceContext* resource_ctx_ {nullptr}; |
183 | | }; |
184 | | |
185 | | } // namespace doris |