backlog_controller: allow users to compute inverse function of shares

There are some situations in which we want to force a specific amount of
shares and don't have a backlog. We can provide a function to get that
from the controller.

Signed-off-by: Glauber Costa <glauber@scylladb.com>
This commit is contained in:
Glauber Costa
2018-05-21 15:39:16 -04:00
parent d9c80cac26
commit d3f985ef46
2 changed files with 18 additions and 0 deletions

View File

@@ -96,6 +96,8 @@ protected:
}
virtual ~backlog_controller() {}
public:
float backlog_of_shares(float shares) const;
};
// memtable flush CPU controller.

View File

@@ -2165,6 +2165,22 @@ void backlog_controller::adjust() {
update_controller(result);
}
float backlog_controller::backlog_of_shares(float shares) const {
size_t idx = 1;
while ((idx < _control_points.size() - 1) && (_control_points[idx].output < shares)) {
idx++;
}
const control_point& cp = _control_points[idx];
const control_point& last = _control_points[idx - 1];
// Compute the inverse function of the backlog in the interpolation interval that we fall
// into.
//
// The formula for the backlog inside an interpolation point is y = a + bx, so the inverse
// function is x = (y - a) / b
return last.input + (shares - last.output) * (cp.input - last.input) / (cp.output - last.output);
}
void backlog_controller::update_controller(float shares) {
_scheduling_group.set_shares(shares);
if (!_inflight_update.available()) {