Make the Server's EMAverage a member

The combined effort of all workers of updating EMAverage is needed for precision,
statistics and making parts of it adaptive (rather than hardcoded or configured).
This commit is contained in:
Niclas Antti
2018-10-03 18:32:13 +03:00
parent ada91f2d53
commit 19f8e1697b
2 changed files with 12 additions and 4 deletions

View File

@ -39,17 +39,17 @@ public:
int response_time_num_samples() const
{
return m_response_time->num_samples();
return m_response_time.num_samples();
}
double response_time_average() const
{
return m_response_time->average();
return m_response_time.average();
}
void response_time_add(double ave, int num_samples)
{
m_response_time->add(ave, num_samples);
m_response_time.add(ave, num_samples);
}
mutable std::mutex m_lock;
@ -59,7 +59,7 @@ private:
// can be calculated at runtime. The "500" or sample_max affects how often a
// session should updates this stat. sample_max should be slightly lower than max sample
// rate (which is less than qps due to the noise filter).
mxs::rworker_local<maxbase::EMAverage> m_response_time;
maxbase::EMAverage m_response_time;
};
void server_free(Server* server);

View File

@ -1535,9 +1535,17 @@ bool server_set_disk_space_threshold(SERVER* server, const char* disk_space_thre
return rv;
}
namespace
{
std::mutex ave_write_mutex;
}
void server_add_response_average(SERVER* srv, double ave, int num_samples)
{
Server* server = static_cast<Server*>(srv);
std::lock_guard<std::mutex> guard(ave_write_mutex);
server->response_time_add(ave, num_samples);
}