MXS-1777 ResponseStat improvements
Fix comments. Fix a bug in make_valid(). Change sync time (when the average should be pushed to the server EMA) to only depend on time, not use sample_max. This decreases the amount of sync calls, and allows for a much shorter sync time. Testing shows this to be more stabel and allow better control of the sample_max.
This commit is contained in:
@ -16,42 +16,33 @@
|
||||
#include <maxbase/stopwatch.hh>
|
||||
#include <maxbase/average.hh>
|
||||
|
||||
/** This could arguably be a utility, but is written specifically for rwsplit
|
||||
* so it stays here at least for now.
|
||||
*/
|
||||
namespace maxscale
|
||||
{
|
||||
/**
|
||||
* Query response statistics. Uses median of N samples to filter noise, then
|
||||
* uses those medians to calculate the average response time.
|
||||
* The class makes an average of the durations between calls to query_started()
|
||||
* and query_ended(). Once the stats are good, sync_time_reached(int max) returns true,
|
||||
* based on the average containing at least max samples (or medians), or the time
|
||||
* sync_duration (constructor arg) has passed since the last reset().
|
||||
* Query response time average for a backend. Uses median of N samples to filter noise,
|
||||
* then uses those medians to calculate the average response time.
|
||||
*/
|
||||
class ResponseStat
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* @param num_filter_samples - collect num samples, use median
|
||||
* @param num_synch_medians - this many medians before the average should be synced, or
|
||||
* @param sync_duration - this much time between syncs.
|
||||
* @param num_filter_samples - collect num samples, use median (digital filter)
|
||||
* @param sync_duration - this much time between synchronize to server stats.
|
||||
*/
|
||||
ResponseStat(int num_filter_samples = 5,
|
||||
int num_synch_medians = 500,
|
||||
maxbase::Duration sync_duration = std::chrono::seconds(5));
|
||||
ResponseStat(int num_filter_samples = 9,
|
||||
maxbase::Duration sync_duration = std::chrono::milliseconds(250));
|
||||
|
||||
void query_started();
|
||||
void query_ended();// ok to call without a query_started
|
||||
bool make_valid(); // make valid even if there are too few filter_samples
|
||||
void query_ended(); // ok to call without a query_started
|
||||
bool make_valid(); // make valid even if there are only filter_samples
|
||||
bool is_valid() const;
|
||||
int num_samples() const;
|
||||
maxbase::Duration average() const;
|
||||
bool sync_time_reached(); // is it time to apply the average?
|
||||
bool sync_time_reached(); // is it time to apply the average to the server?
|
||||
void reset();
|
||||
|
||||
private:
|
||||
const int m_num_filter_samples;
|
||||
const int m_num_synch_medians;
|
||||
const maxbase::Duration m_sync_duration;
|
||||
int m_sample_count;
|
||||
std::vector<maxbase::Duration> m_samples; // N sampels from which median is used
|
||||
|
Reference in New Issue
Block a user