neon
neon copied to clipboard
Deactivate sk timelines when no compute activity
In-memory timelines will be deactivated after there will be no compute connections for more than 10 minutes. Deactivation here will set active = false
in SharedState
struct and that will stop pushing info about this timeline to etcd.
Timeline deactivation happens in update_status
, which is called on every etcd message from the peer.
Tested locally with a test that counts active timelines:
from fixtures.metrics import parse_metrics
def test_plenty_timelines(neon_env_builder: NeonEnvBuilder):
neon_env_builder.num_safekeepers = 3
neon_env_builder.enable_local_fs_remote_storage()
env = neon_env_builder.init_start()
# start postgres on each timeline
pgs = []
branch_idx = 0
def create_branch():
nonlocal branch_idx
branch_name = f"abc_{branch_idx}"
branch_idx += 1
new_timeline_id = env.neon_cli.create_branch(branch_name)
pg = env.postgres.create_start(branch_name)
pg.safe_psql("CREATE TABLE IF NOT EXISTS t (key INT)")
pg.safe_psql(f"INSERT INTO t (key) VALUES ({branch_idx})")
pg.stop()
pgs.append(pg)
def report_metrics():
# collect metrics from other servers
for sk in env.safekeepers:
all_metrics = parse_metrics(sk.http_client().get_metrics_str())
active_tlis = sum(map(lambda f: int(f.value), all_metrics.query_all("safekeeper_timeline_active", {})))
log.info(f"Safekeeper {sk.id} have {active_tlis} active timelines")
for i in range(100):
create_branch()
report_metrics()
# sleep until timelines are deactivated
time.sleep(50)
for j in range(10):
for i in range(10):
create_branch()
report_metrics()
time.sleep(10)
Superseded by 26746