foundationdb/fdbrpc/QueueModel.cpp

123 lines
3.6 KiB
C++
Raw Normal View History

2017-05-26 04:48:44 +08:00
/*
* QueueModel.cpp
*
* This source file is part of the FoundationDB open source project
*
2022-03-22 04:36:23 +08:00
* Copyright 2013-2022 Apple Inc. and the FoundationDB project authors
*
2017-05-26 04:48:44 +08:00
* Licensed 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
*
2017-05-26 04:48:44 +08:00
* http://www.apache.org/licenses/LICENSE-2.0
*
2017-05-26 04:48:44 +08:00
* 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 "fdbrpc/QueueModel.h"
#include "fdbrpc/LoadBalance.h"
2017-05-26 04:48:44 +08:00
void QueueModel::endRequest(uint64_t id, double latency, double penalty, double delta, bool clean, bool futureVersion) {
2017-05-26 04:48:44 +08:00
auto& d = data[id];
// Remove the penalty added when starting the request.
2017-05-26 04:48:44 +08:00
d.smoothOutstanding.addDelta(-delta);
if (clean) {
2017-05-26 04:48:44 +08:00
d.latency = latency;
} else {
d.latency = std::max(d.latency, latency);
}
if (futureVersion) {
if (now() > d.increaseBackoffTime) {
d.futureVersionBackoff = std::min(d.futureVersionBackoff * FLOW_KNOBS->FUTURE_VERSION_BACKOFF_GROWTH,
FLOW_KNOBS->FUTURE_VERSION_MAX_BACKOFF);
d.increaseBackoffTime = now() + d.futureVersionBackoff;
}
d.failedUntil = now() + d.futureVersionBackoff;
} else if (clean) {
d.futureVersionBackoff = FLOW_KNOBS->FUTURE_VERSION_INITIAL_BACKOFF;
d.increaseBackoffTime = 0.0;
}
if (penalty > 0) {
2017-05-26 04:48:44 +08:00
d.penalty = penalty;
}
}
2022-03-11 12:47:35 +08:00
QueueData const& QueueModel::getMeasurement(uint64_t id) {
return data[id]; // return smoothed penalty
2017-05-26 04:48:44 +08:00
}
double QueueModel::addRequest(uint64_t id) {
2017-05-26 04:48:44 +08:00
auto& d = data[id];
d.smoothOutstanding.addDelta(d.penalty);
return d.penalty;
}
2021-05-29 02:19:42 +08:00
void QueueModel::updateTssEndpoint(uint64_t endpointId, const TSSEndpointData& tssData) {
2021-03-06 03:28:15 +08:00
auto& d = data[endpointId];
2021-05-29 02:15:52 +08:00
d.tssData = tssData;
2021-03-06 03:28:15 +08:00
}
2021-05-29 02:15:52 +08:00
void QueueModel::removeTssEndpoint(uint64_t endpointId) {
auto& d = data[endpointId];
d.tssData = Optional<TSSEndpointData>();
2021-03-06 03:28:15 +08:00
}
Optional<TSSEndpointData> QueueModel::getTssData(uint64_t id) {
return data[id].tssData;
}
Optional<LoadBalancedReply> getLoadBalancedReply(const LoadBalancedReply* reply) {
2017-05-26 04:48:44 +08:00
return *reply;
}
Optional<LoadBalancedReply> getLoadBalancedReply(const void*) {
2017-05-26 04:48:44 +08:00
return Optional<LoadBalancedReply>();
}
Optional<BasicLoadBalancedReply> getBasicLoadBalancedReply(const BasicLoadBalancedReply* reply) {
return *reply;
}
Optional<BasicLoadBalancedReply> getBasicLoadBalancedReply(const void*) {
return Optional<BasicLoadBalancedReply>();
}
2017-05-26 04:48:44 +08:00
/*
void QueueModel::addMeasurement( uint64_t id, QueueDetails qd ){
if (data[new_index].count(id))
total_time[new_index] -= data[new_index][id].queryQueueSize;
data[new_index][id] = qd;
total_time[new_index] += qd.queryQueueSize;
2017-05-26 04:48:44 +08:00
}
TimeEstimate QueueModel::getTimeEstimate( uint64_t id ){
if (data[new_index].count(id)) // give the current estimate
return data[new_index][id].queryQueueSize;
else if (data[1-new_index].count(id)) // if not, old estimate
return data[1-new_index][id].queryQueueSize;
else // if not, the average?
return getAverageTimeEstimate();
2017-05-26 04:48:44 +08:00
}
TimeEstimate QueueModel::getAverageTimeEstimate(){
if(data[new_index].size() + data[1-new_index].size() > 0)
return (total_time[new_index] + total_time[1-new_index]) / (data[new_index].size() + data[1-new_index].size());
return 0;
2017-05-26 04:48:44 +08:00
}
void QueueModel::expire(){
data[1-new_index].clear();
total_time[1-new_index] = 0;
2017-05-26 04:48:44 +08:00
new_index = 1-new_index;
2017-05-26 04:48:44 +08:00
}
*/