diff --git a/include/maxscale/response_stat.hh b/include/maxscale/response_stat.hh index d4c437c60..728bfe97c 100644 --- a/include/maxscale/response_stat.hh +++ b/include/maxscale/response_stat.hh @@ -36,7 +36,7 @@ public: 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; + long num_samples() const; maxbase::Duration average() const; bool sync_time_reached(); // is it time to apply the average to the server? void reset(); @@ -44,7 +44,7 @@ public: private: const int m_num_filter_samples; const maxbase::Duration m_sync_duration; - int m_sample_count; + long m_sample_count; std::vector m_samples; // N sampels from which median is used maxbase::CumulativeAverage m_average; maxbase::TimePoint m_last_start; diff --git a/maxutils/maxbase/include/maxbase/average.hh b/maxutils/maxbase/include/maxbase/average.hh index 626fe94dd..8a76d6182 100644 --- a/maxutils/maxbase/include/maxbase/average.hh +++ b/maxutils/maxbase/include/maxbase/average.hh @@ -34,7 +34,7 @@ public: * @param ave The average value * @param num_samples How many samples were taken to construct it */ - void add(double ave, int num_samples = 1); + void add(double ave, long num_samples = 1); /** * Get the average value @@ -48,7 +48,7 @@ public: * * @return Number of collected samples */ - int num_samples() const; + long num_samples() const; /** * Reset the average value @@ -60,8 +60,8 @@ public: CumulativeAverage& operator+=(const CumulativeAverage& rhs); private: double m_ave = 0; - int m_num_samples = 0; - int m_num_last_added = 0; + long m_num_samples = 0; + long m_num_last_added = 0; }; CumulativeAverage operator+(const CumulativeAverage& rhs, const CumulativeAverage& lhs); @@ -81,7 +81,7 @@ public: * @param max_alpha The extra alpha value * @param sample_max Maximum number of samples to use */ - EMAverage(double min_alpha, double max_alpha, int sample_max); + EMAverage(double min_alpha, double max_alpha, long sample_max); /** * Add a new value to the average made of `num_samples` samples @@ -101,7 +101,7 @@ public: * @param ave Value to add * @param num_samples Number of samples the value consists of */ - void add(double ave, int num_samples = 1); + void add(double ave, long num_samples = 1); /** * Add a CumulativeAverage @@ -124,21 +124,21 @@ public: * * @return The number of samples */ - int num_samples() const; + long num_samples() const; /** * Set maximum sample size * * @param sample_max The new sample max size */ - void set_sample_max(int sample_max); + void set_sample_max(long sample_max); /** * Get maximum sample size * * @return The maximum sample size */ - int sample_max() const; + long sample_max() const; /** * Reset the average @@ -150,8 +150,8 @@ public: private: const double m_min_alpha; const double m_max_alpha; - int m_sample_max; - int m_num_samples = 0; + long m_sample_max; + long m_num_samples = 0; double m_ave = 0; }; diff --git a/maxutils/maxbase/include/maxbase/random.hh b/maxutils/maxbase/include/maxbase/random.hh index 85d40c72f..0d25b2890 100644 --- a/maxutils/maxbase/include/maxbase/random.hh +++ b/maxutils/maxbase/include/maxbase/random.hh @@ -37,8 +37,8 @@ public: uint64_t rand(); uint32_t rand32(); bool rand_bool(); - int64_t b_to_e_exclusive(int64_t b, int64_t e); - double zero_to_one_exclusive(); + int64_t b_to_e_co(int64_t b, int64_t e); + double zero_to_one_co(); private: uint64_t rotl(const uint64_t x, int k); std::array m_state; @@ -57,8 +57,8 @@ public: uint64_t rand(); uint32_t rand32(); bool rand_bool(); - int64_t b_to_e_exclusive(int64_t b, int64_t e); - double zero_to_one_exclusive(); + int64_t b_to_e_co(int64_t b, int64_t e); + double zero_to_one_co(); // Borrow the mt19937_64 engine for other distributions. std::mt19937_64& rnd_engine(); @@ -104,7 +104,7 @@ inline bool XorShiftRandom::rand_bool() return std::signbit(int64_t(rand())); } -inline double XorShiftRandom::zero_to_one_exclusive() +inline double XorShiftRandom::zero_to_one_co() { uint64_t x = rand(); @@ -118,7 +118,7 @@ inline double XorShiftRandom::zero_to_one_exclusive() return u.d - 1.0; } -inline int64_t XorShiftRandom::b_to_e_exclusive(int64_t b, int64_t e) +inline int64_t XorShiftRandom::b_to_e_co(int64_t b, int64_t e) { // With 64 bits mod bias does not happen in practise (a very, very large e-b would be needed). // alternative: return b + int64_t(zero_to_one_exclusive()*(e-b)); @@ -140,13 +140,13 @@ inline bool StdTwisterRandom::rand_bool() return std::signbit(int32_t(rand32())); } -inline double StdTwisterRandom::zero_to_one_exclusive() +inline double StdTwisterRandom::zero_to_one_co() { std::uniform_real_distribution zero_to_one {0, 1}; return zero_to_one(m_twister_engine_64); } -inline int64_t StdTwisterRandom::b_to_e_exclusive(int64_t b, int64_t e) +inline int64_t StdTwisterRandom::b_to_e_co(int64_t b, int64_t e) { std::uniform_int_distribution dist {b, e - 1}; return dist(m_twister_engine_64); diff --git a/maxutils/maxbase/src/average.cc b/maxutils/maxbase/src/average.cc index 593b3dc1d..9a4741b34 100644 --- a/maxutils/maxbase/src/average.cc +++ b/maxutils/maxbase/src/average.cc @@ -17,7 +17,7 @@ namespace maxbase { -void CumulativeAverage::add(double ave, int num_samples) +void CumulativeAverage::add(double ave, long num_samples) { m_num_samples += num_samples; @@ -38,7 +38,7 @@ double CumulativeAverage::average() const return m_ave; } -int CumulativeAverage::num_samples() const +long CumulativeAverage::num_samples() const { return m_num_samples; } @@ -61,17 +61,17 @@ void CumulativeAverage::reset() m_num_last_added = 0; } -EMAverage::EMAverage(double min_alpha, double max_alpha, int sample_max) +EMAverage::EMAverage(double min_alpha, double max_alpha, long sample_max) : m_min_alpha{min_alpha} , m_max_alpha{max_alpha} , m_sample_max{sample_max} { } -void EMAverage::add(double ave, int num_samples) +void EMAverage::add(double ave, long num_samples) { // Give more weight to initial samples. - int sample_max = std::min(m_num_samples ? m_num_samples : 1, m_sample_max); + long sample_max = std::min(m_num_samples ? m_num_samples : 1, m_sample_max); double alpha = m_min_alpha + m_max_alpha * std::min(double(num_samples) / sample_max, 1.0); @@ -97,17 +97,17 @@ double EMAverage::average() const return m_ave; } -int EMAverage::num_samples() const +long EMAverage::num_samples() const { return m_num_samples; } -void EMAverage::set_sample_max(int sample_max) +void EMAverage::set_sample_max(long sample_max) { m_sample_max = sample_max; } -int EMAverage::sample_max() const +long EMAverage::sample_max() const { return m_sample_max; } diff --git a/server/core/response_stat.cc b/server/core/response_stat.cc index f090cab66..2c77b1a6a 100644 --- a/server/core/response_stat.cc +++ b/server/core/response_stat.cc @@ -71,7 +71,7 @@ bool ResponseStat::is_valid() const return m_average.num_samples(); } -int ResponseStat::num_samples() const +long ResponseStat::num_samples() const { return m_average.num_samples(); } diff --git a/server/modules/routing/readwritesplit/rwsplit_select_backends.cc b/server/modules/routing/readwritesplit/rwsplit_select_backends.cc index 8cdb9e6c4..a7dfc8131 100644 --- a/server/modules/routing/readwritesplit/rwsplit_select_backends.cc +++ b/server/modules/routing/readwritesplit/rwsplit_select_backends.cc @@ -161,7 +161,7 @@ PRWBackends::iterator backend_cmp_response_time(PRWBackends& sBackends) } // Find the winner, role the ball: - double ball = maxbase::Worker::get_current()->random_engine().zero_to_one_exclusive(); + double ball = maxbase::Worker::get_current()->random_engine().zero_to_one_co(); double slot_walk {0}; int winner {0};