Skip to content

perf: singleflight same-ref OCI snapshot and cloud-image imports #35

Description

@CMGS

Problem

Concurrent Pods using the same cold OCI artifact can independently download and import the same bytes. The check-and-pull/import sequences are not synchronized:

Snapshot import also removes the existing local name before starting. A cold burst can therefore perform N registry transfers/imports and race on the same local destination. A previous implementation identified this corruption class in vk-cocoon#1, but the protection was lost during the OCI-path rewrite.

The provider already has the desired singleflight pattern for fork snapshots in ensureForkSnapshot.

Proposed scope

  • Add provider-owned keyed singleflight around the complete local-check + transfer/import + post-check sequence.
  • Use separate key namespaces for snapshots and images, keyed by local destination/ref.
  • Keep the local-hit fast path and let different artifacts import concurrently.
  • Detach shared work from an individual CreatePod cancellation, with a bounded provider-lifecycle context.
  • Preserve force-pull semantics: concurrent force requests share one active import, while a later force request can import again.

Acceptance criteria

  • 16 concurrent cold requests for one snapshot produce one registry stream and one snapshot import.
  • 16 concurrent cold requests for one cloud image produce one registry stream and one image import.
  • Different refs are not serialized behind each other.
  • A local cache hit performs no transfer or import.
  • Cancelling one waiter does not cancel shared work for remaining callers.
  • A shared failure reaches every waiter and a later call can retry successfully.
  • Tests pass under go test -race.
  • A cold-cache burst benchmark records registry bytes, import process count, and CreatePod p95 before and after.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions