github-actions[bot] commented on code in PR #38238: URL: https://github.com/apache/doris/pull/38238#discussion_r1687484329
########## be/src/runtime/workload_management/io_throttle.cpp: ########## @@ -0,0 +1,76 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "runtime/workload_management/io_throttle.h" + +#include <thread> + +#include "common/config.h" +#include "util/time.h" + +namespace doris { + +bool IOThrottle::acquire(int64_t block_timeout_ms) { + if (_io_bytes_per_second < 0) { + return true; + } + + std::unique_lock<std::mutex> w_lock(_mutex); + int64_t current_time = GetCurrentTimeMicros(); + int64_t block_finish_time = block_timeout_ms <= 0 ? 0 : current_time + block_timeout_ms * 1000; + + while (current_time <= _next_io_time_micros) { + if (block_finish_time > 0 && current_time >= block_finish_time) { + return false; + } + wait_condition.wait_for(w_lock, + std::chrono::microseconds(_next_io_time_micros - current_time)); + current_time = GetCurrentTimeMicros(); + } + return true; +} + +bool IOThrottle::try_acquire() { + if (_io_bytes_per_second < 0) { + return true; + } + std::unique_lock<std::mutex> w_lock(_mutex); + return GetCurrentTimeMicros() > _next_io_time_micros; +} + +void IOThrottle::update_next_io_time(int64_t io_bytes) { + if (_io_bytes_per_second <= 0 || io_bytes <= 0) { + return; + } + int64_t read_bytes_per_second = _io_bytes_per_second; + std::unique_lock<std::mutex> w_lock(_mutex); + double io_bytes_float = static_cast<double>(io_bytes); Review Comment: warning: use auto when initializing with a cast to avoid duplicating the type name [modernize-use-auto] ```suggestion auto io_bytes_float = static_cast<double>(io_bytes); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org