This commit is contained in:
Konstantin Knizhnik
2024-09-13 10:53:51 +01:00
parent 61f827364f
commit 580946de44
2 changed files with 13 additions and 9 deletions

View File

@@ -137,7 +137,7 @@ addSHLL(HyperLogLogState *cState, uint32 hash)
uint32 cell = Min(interval_log2, HIST_SIZE-1);
new_histogram[cell] += cState->regs[index][count].histogram[i];
}
memcpy(cState->regs[index][count].histogram, new_histogram, sizeof new_hostogram);
memcpy(cState->regs[index][count].histogram, new_histogram, sizeof new_histogram);
}
cState->regs[index][count].ts = now;
cState->regs[index][count].histogram[0] += 1;
@@ -166,7 +166,7 @@ getMaximum(const HyperLogLogRegister* reg, TimestampTz since, time_t duration, d
{
for (i = 0; i < HLL_C_BITS + 1; i++)
{
if (reg[i].ts >= since && 1.0 - getAccessCount(reg, duration) / total_count >= min_hit_ration)
if (reg[i].ts >= since && 1.0 - getAccessCount(reg, duration) / total_count >= min_hit_ratio)
{
max = i;
}

View File

@@ -130,7 +130,7 @@ def test_optimal_cache_size_approximation(neon_simple_env: NeonEnv):
)
conn = endpoint.connect()
cur = conn.cursor()
cur.execute("create extension neon")
cur.execute("create extension neon version '1.5'")
cur.execute(
"create table t_huge(pk integer primary key, count integer default 0, payload text default repeat('?', 128))"
)
@@ -138,14 +138,18 @@ def test_optimal_cache_size_approximation(neon_simple_env: NeonEnv):
"create table t_small(pk integer primary key, count integer default 0, payload text default repeat('?', 128))"
)
cur.execute("insert into t_huge(pk) values (generate_series(1,1000000))")
cur.execute("insert into t_small (pk) values (generate_series(1,100000))")
cur.execute("insert into t_small(pk) values (generate_series(1,100000))")
time.sleep(2)
before = time.monotonic()
for _ in 1..100:
for _ in range(100):
cur.execute("select sum(count) from t_small")
cur.execute("select sum(count) from t_huge")
after = time.monotonic()
cur.execute(f"select approximate_optimal_cache_size({int(after - before + 1, 0.99)})")
estimation = cur.fetchall()[0][0]
log.info(f"Working set size for selecting 1k records {estimation}")
assert estimation_1k >= 20 and estimation_1k <= 40
cur.execute(f"select approximate_working_set_size_seconds({int(after - before + 1)})")
ws_estimation = cur.fetchall()[0][0]
log.info(f"Working set size estimaton {ws_estimation}")
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