2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* QueueModel.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
|
|
|
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
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
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
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.
|
|
|
|
*/
|
|
|
|
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbrpc/QueueModel.h"
|
|
|
|
#include "fdbrpc/LoadBalance.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2017-10-20 06:36:32 +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];
|
|
|
|
d.smoothOutstanding.addDelta(-delta);
|
|
|
|
|
|
|
|
if(clean) {
|
|
|
|
d.latency = latency;
|
|
|
|
} else {
|
|
|
|
d.latency = std::max(d.latency, latency);
|
|
|
|
}
|
|
|
|
|
2017-10-20 06:36:32 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-05-26 04:48:44 +08:00
|
|
|
if(penalty > 0) {
|
|
|
|
d.penalty = penalty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QueueData& QueueModel::getMeasurement( uint64_t id ) {
|
|
|
|
return data[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
double QueueModel::addRequest( uint64_t id ) {
|
|
|
|
auto& d = data[id];
|
|
|
|
d.smoothOutstanding.addDelta(d.penalty);
|
|
|
|
return d.penalty;
|
|
|
|
}
|
|
|
|
|
|
|
|
Optional<LoadBalancedReply> getLoadBalancedReply(LoadBalancedReply *reply) {
|
|
|
|
return *reply;
|
|
|
|
}
|
|
|
|
|
|
|
|
Optional<LoadBalancedReply> getLoadBalancedReply(void*) {
|
|
|
|
return Optional<LoadBalancedReply>();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QueueModel::expire(){
|
|
|
|
data[1-new_index].clear();
|
|
|
|
total_time[1-new_index] = 0;
|
|
|
|
|
|
|
|
new_index = 1-new_index;
|
|
|
|
}
|
|
|
|
*/
|