liaoxin01 commented on code in PR #65420: URL: https://github.com/apache/doris/pull/65420#discussion_r3680022602
########## be/src/util/s3_rate_limiter_manager.cpp: ########## @@ -0,0 +1,214 @@ +// 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 "util/s3_rate_limiter_manager.h" + +#include <algorithm> +#include <limits> +#include <thread> + +#include "common/config.h" +#include "common/logging.h" +#include "util/cgroup_util.h" + +namespace doris { + +bvar::Adder<int64_t> s3_get_bytes_rate_limit_sleep_ns("s3_get_bytes_rate_limit_sleep_ns"); +bvar::Adder<int64_t> s3_get_bytes_rate_limit_sleep_count("s3_get_bytes_rate_limit_sleep_count"); +bvar::Adder<int64_t> s3_get_bytes_rate_limit_rejected_count( + "s3_get_bytes_rate_limit_rejected_count"); +bvar::Adder<int64_t> s3_put_bytes_rate_limit_sleep_ns("s3_put_bytes_rate_limit_sleep_ns"); +bvar::Adder<int64_t> s3_put_bytes_rate_limit_sleep_count("s3_put_bytes_rate_limit_sleep_count"); +bvar::Adder<int64_t> s3_put_bytes_rate_limit_rejected_count( + "s3_put_bytes_rate_limit_rejected_count"); + +namespace { + +std::function<void(int64_t)> bytes_rate_limiter_metric_func(S3RateLimitType type) { + switch (type) { + case S3RateLimitType::GET: + return metric_func_factory(s3_get_bytes_rate_limit_sleep_ns, + s3_get_bytes_rate_limit_sleep_count, + &s3_get_bytes_rate_limit_rejected_count); + case S3RateLimitType::PUT: + return metric_func_factory(s3_put_bytes_rate_limit_sleep_ns, + s3_put_bytes_rate_limit_sleep_count, + &s3_put_bytes_rate_limit_rejected_count); + default: + return [](int64_t) {}; + } +} + +// min(per_core * cores, cap) with overflow protection; cap == 0 means no cap. +int64_t cap_multiply(int64_t per_core, int64_t cores, int64_t cap) { + cap = cap > 0 ? cap : std::numeric_limits<int64_t>::max(); + if (per_core > cap / cores) { + return cap; + } + return per_core * cores; +} + +size_t index_of(S3RateLimitType type) { + CHECK(type == S3RateLimitType::GET || type == S3RateLimitType::PUT) << to_string(type); Review Comment: CHECK -> DCHECK -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
