Skip to content

controlapi, atepg: cut per-operation PostgreSQL lease writes on ResumeActor and SuspendActor #3977

Open

Description

@chw120

Problem

A cold resume + suspend cycle makes 8 write commits in PostgreSQL. Half of them (4 of 8) are lease writes (AcquireLease and ReleaseLease on the leases table). Each write waits for a log flush, which caps size10 near 7,450 cycles/s.

Today we also write to the leases table even when a call has nothing to do:

  1. Calling ResumeActor when the actor is already RESUMING: Before taking the lease, ResumeActor only returns early if the actor is RUNNING. While an actor is RESUMING (for example, when atenet-router polls every 250 ms), every poll still writes to leases and fails with a conflict.
  2. Calling SuspendActor when the actor is already SUSPENDED or SUSPENDING: SuspendActor takes and deletes a database lease before reading the actor's state at all.
  3. Normal wake and suspend cycles: Every resume and suspend inserts and deletes a lease row, even though actors updates already check the row version.

What to do

  1. Skip the lease on no-op and in-flight calls: Read the actor before taking the lease in ResumeActor, SuspendActor, and ReportSnapshotStatus. Return early without touching leases when the actor is already in the target state, in a terminal state, or actively RESUMING / SUSPENDING.
  2. Cut lease writes on normal cycles: Explore replacing per-call leases rows with versioned state claims on actors (or in-memory fencing). That cuts cycle writes from 8 toward 4.
  3. Measure the gain: Check pg_commits per cycle, peak cycles/s (>= 10,000/s goal on size10), and P90 wake latency on benchmarking/isolate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/api-machinerykind/performance

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions