Fix histogram build

This commit is contained in:
Konstantin Knizhnik
2024-09-14 13:33:07 +01:00
parent 16b0e57d11
commit f73128fcaf
3 changed files with 8 additions and 6 deletions

View File

@@ -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);
}

View File

@@ -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<<i) + ((1<<i)/2))/2 <= duration; i++) {
for (size_t i = 0; i < HIST_SIZE && HIST_MIN_INTERVAL*((1 << i)/2) <= duration; i++) {
count += reg->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(&reg[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(&reg[i], duration) / total_count <= min_hit_ratio)
{
max = i;
}

View File

@@ -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