From f73128fcaf4f84b4817a4d16c67465adc3031535 Mon Sep 17 00:00:00 2001 From: Konstantin Knizhnik Date: Sat, 14 Sep 2024 13:33:07 +0100 Subject: [PATCH] Fix histogram build --- pgxn/neon/file_cache.c | 2 +- pgxn/neon/hll.c | 8 +++++--- test_runner/regress/test_lfc_working_set_approximation.py | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pgxn/neon/file_cache.c b/pgxn/neon/file_cache.c index 463d2e94c7..5516870b4e 100644 --- a/pgxn/neon/file_cache.c +++ b/pgxn/neon/file_cache.c @@ -1263,7 +1263,7 @@ approximate_working_set_size_seconds(PG_FUNCTION_ARGS) int32 dc; time_t duration = PG_ARGISNULL(0) ? (time_t)-1 : PG_GETARG_INT32(0); LWLockAcquire(lfc_lock, LW_SHARED); - dc = (int32) estimateSHLL(&lfc_ctl->wss_estimation, duration, 0); + dc = (int32) estimateSHLL(&lfc_ctl->wss_estimation, duration, 1.0); LWLockRelease(lfc_lock); PG_RETURN_INT32(dc); } diff --git a/pgxn/neon/hll.c b/pgxn/neon/hll.c index 90a46deb06..a5c89942b9 100644 --- a/pgxn/neon/hll.c +++ b/pgxn/neon/hll.c @@ -147,6 +147,7 @@ static uint32_t getAccessCount(const HyperLogLogRegister* reg, time_t duration) { uint32_t count = 0; + //for (size_t i = 0; i < HIST_SIZE && HIST_MIN_INTERVAL*((1<histogram[i]; } @@ -159,14 +160,15 @@ getMaximum(const HyperLogLogRegister* reg, TimestampTz since, time_t duration, d uint8 max = 0; size_t i, j; uint32_t total_count = 0; - for (i = 0; i < HIST_SIZE && (HIST_MIN_INTERVAL << i) <= duration; i++) { - total_count += getAccessCount(reg, duration); + for (i = 0; i < HLL_C_BITS + 1; i++) + { + total_count += getAccessCount(®[i], duration); } if (total_count != 0) { for (i = 0; i < HLL_C_BITS + 1; i++) { - if (reg[i].ts >= since && 1.0 - getAccessCount(reg, duration) / total_count <= min_hit_ratio) + if (reg[i].ts >= since && 1.0 - (double)getAccessCount(®[i], duration) / total_count <= min_hit_ratio) { max = i; } diff --git a/test_runner/regress/test_lfc_working_set_approximation.py b/test_runner/regress/test_lfc_working_set_approximation.py index 0c3b094c4f..298d5a41e3 100644 --- a/test_runner/regress/test_lfc_working_set_approximation.py +++ b/test_runner/regress/test_lfc_working_set_approximation.py @@ -151,5 +151,5 @@ def test_optimal_cache_size_approximation(neon_simple_env: NeonEnv): cur.execute(f"select approximate_optimal_cache_size({int(after - before + 1)}, 0.99)") optimal_cache_size = cur.fetchall()[0][0] log.info(f"Optimal cache size for 99% hit rate {optimal_cache_size}") - assert ws_estimation >= 1000 and ws_estimation <= 2000 - assert optimal_cache_size >= 100 and optimal_cache_size <= 200 + assert ws_estimation >= 20000 and ws_estimation <= 30000 + assert optimal_cache_size >= 2000 and optimal_cache_size <= 7000