backoff.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2016 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * 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, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
20 
22 
23 #include <algorithm>
24 
26 
27 namespace grpc_core {
28 
30 
32  if (initial_) {
33  initial_ = false;
34  return current_backoff_ + ExecCtx::Get()->Now();
35  }
41  return ExecCtx::Get()->Now() + current_backoff_ + jitter;
42 }
43 
46  initial_ = true;
47 }
48 
49 } // namespace grpc_core
grpc_core::Duration::seconds
double seconds() const
Definition: src/core/lib/gprpp/time.h:209
grpc_core::BackOff::rand_gen_
absl::BitGen rand_gen_
Definition: backoff.h:82
backoff.h
grpc_core::Duration::FromSecondsAsDouble
static Duration FromSecondsAsDouble(double seconds)
Definition: src/core/lib/gprpp/time.h:279
grpc_core::BackOff::NextAttemptTime
Timestamp NextAttemptTime()
Returns the time at which the next attempt should start.
Definition: backoff.cc:31
grpc_core
Definition: call_metric_recorder.h:31
options
double_dict options[]
Definition: capstone_test.c:55
grpc_core::Timestamp
Definition: src/core/lib/gprpp/time.h:62
grpc_core::BackOff::BackOff
BackOff(const Options &options)
Initialize backoff machinery - does not need to be destroyed.
Definition: backoff.cc:29
grpc_core::BackOff::options_
const Options options_
Definition: backoff.h:81
grpc_core::BackOff::Options::initial_backoff
Duration initial_backoff() const
how long to wait after the first failure before retrying
Definition: backoff.h:65
min
#define min(a, b)
Definition: qsort.h:83
options_
DebugStringOptions options_
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.cc:2390
grpc_core::BackOff::current_backoff_
Duration current_backoff_
current delay before retries
Definition: backoff.h:85
grpc_core::BackOff::Reset
void Reset()
Definition: backoff.cc:44
grpc_core::BackOff::Options::multiplier
double multiplier() const
factor with which to multiply backoff after a failed retry
Definition: backoff.h:67
exec_ctx.h
grpc_core::ExecCtx::Now
Timestamp Now()
Definition: exec_ctx.cc:90
grpc_core::Duration
Definition: src/core/lib/gprpp/time.h:122
grpc_core::BackOff::Options
Definition: backoff.h:46
grpc_core::BackOff::initial_
bool initial_
Definition: backoff.h:83
grpc_core::BackOff::Options::jitter
double jitter() const
amount to randomize backoffs
Definition: backoff.h:69
grpc_core::ExecCtx::Get
static ExecCtx * Get()
Definition: exec_ctx.h:205
grpc_core::BackOff::Options::max_backoff
Duration max_backoff() const
maximum time between retries
Definition: backoff.h:71
port_platform.h
absl::Uniform
absl::enable_if_t<!std::is_same< R, void >::value, R > Uniform(TagType tag, URBG &&urbg, R lo, R hi)
Definition: abseil-cpp/absl/random/distributions.h:123


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:35