Skip to content

Checking your reading list…

Retry

Stay curious. Build better.

Appearance

Choose how BestHub looks on this device.

Changes apply immediately.

Search articles

Open Discover with these filters

Suggested searches

Operations 17 min read

How We Cut OpenStack Full Sync from 54 Minutes to 6 for 27K Instances

Engineers reduced OpenStack instance full-sync time from 41–54 minutes to 5 minutes 58 seconds for 27,000 instances by parallelizing cursor-based pagination with boundary sharding, preloading associated data per round, and batching database writes into fewer transactions while handling marker semantics, boundary invalidation, and error tracking.

Cloud management platforms periodically reconcile their instance database with Nova, OpenStack's compute service. At ~27,000 active instances, a full sync took 41–54 minutes, exceeding the 30-minute scheduling interval and leaving the platform's view stale.

Measuring the bottlenecks

The sync was split into timed stages:

Fetch instances from Nova

补全可能遗漏的实例

Load associated data (flavors, images, networks, security groups, volumes)

Process instances and write to database

Two dominant costs emerged:

Instance fetch: ~29 minutes – serial cursor pagination (marker) where each page request depends on the previous page's last record.

Database writes: ~24 minutes – one transaction commit per instance, accumulating commit overhead (log flushes, etc.).

Additional overhead: repeated per-instance lookups of shared reference data, verbose per-instance logging, and an incomplete change-detection shortcut that skipped updates for fields like security-group names, subnets, and IP addresses.

Parallelizing cursor pagination without breaking correctness

Nova's list API uses a marker (cursor) parameter: the client sends the last record's ID to get the next page. This creates a serial dependency chain. Simply adding threads does not break the chain.

Solution: boundary-based sharding. First, scan the instance list once to pick a set of boundary markers (e.g., every N-th record). Then launch concurrent workers, each responsible for the range between two boundaries. Workers still paginate serially inside their shard, but shards run in parallel. Concurrency is capped to avoid overwhelming the Nova API.

Boundaries are cached after the first run and updated each round, so the initial scan cost is amortized. However, the first run and post-restart runs are slower than steady-state runs.

Why not shard by host?

Instances in BUILD or error states may lack host assignment. Sharding by host would miss them, requiring a separate catch-up mechanism. Sharding by the global return sequence includes all instances, provided the pagination semantics are correctly understood.

Marker is a bookmark, not a sortable ID

In the Nova cells v2 deployment, the global list is a concatenation of per-cell segments. Each segment may be ordered, but the concatenation is not globally sorted by UUID . Using "max UUID on this page" as the next marker can skip records.

Correct handling:

Advance the cursor using the last record actually returned .

Detect shard-end by equality comparison with the right-boundary marker, not by UUID magnitude.

Never infer global position from UUID ordering.

The marker is a bookmark telling the server "continue from here"; the client must not reinterpret it as a global sequence number.

Fewer-than-page-size results do not guarantee end-of-list

Because multiple data sources feed the paginated response, a page can return fewer than the requested limit while more data remains. The implementation therefore:

Controls cursor advancement client-side.

Records seen cursors to prevent loops or duplicate pages.

Sets a max-page guard; on anomaly, falls back to a full unsharded fetch and clears the boundary cache for rebuild.

These behaviors depend on Nova version, API parameters, and deployment; teams must validate sorting, marker semantics, and termination conditions in their own environment.

Boundaries drift as instances are created/deleted

During a sync, instances can appear or disappear. A right-boundary instance may be deleted before its shard reaches it, causing the shard to overshoot into the next shard's range. The design allows overlap and deduplicates by UUID at merge time, then regenerates fresh boundaries.

If a shard sees an empty page before hitting its right boundary, it retries with a smaller page size; if it still fails, the whole region falls back to unsharded fetch and the boundary cache is cleared.

In production, boundary invalidation caused a temporary spike in page requests; the round slowed, duplicates were removed at merge, and the next round returned to normal after boundaries were rebuilt.

Key distinction: deduplication handles duplicate records, but cannot prove absence of missing records . Completeness still relies on correct upstream semantics, boundary logic, and fallback behavior. Sharded concurrency does not provide a strict point-in-time snapshot.

Preload reference data once per round

After fetch acceleration, per-instance lookups of flavors, images, networks, subnets, and security groups became the new hotspot. These are now loaded in bulk at the start of each sync round (~4.3 seconds for 27K instances) and kept in memory. Cache scope is per-region to avoid cross-region collisions (e.g., same network name in different regions). Region affiliation comes from explicit data relationships, not hostname conventions.

Batch database writes: fewer commits, not just more threads

Each instance sync involves multiple SQL statements (instance row, volume attachments, security-group bindings). Committing each statement separately accumulated thousands of transaction commits.

Changed to: accumulate a batch of operations, execute them in a single transaction, commit, repeat. Final remainder committed at end.

Original: write one, commit one; write next, commit next
Batch: accumulate N ops, execute in one transaction, commit

This is transaction-commit batching, not necessarily a single bulk-INSERT. Combined with controlled write concurrency, the write phase dropped to ~3 minutes for 27K instances.

Errors must remain visible

Batch processing must not swallow failures. On insert failure, the in-memory cache must not be marked "exists"; update operations must check DB error codes. One measured round logged 144 errors – the 5:58 elapsed time reflects execution duration, not a 100% success rate. Reports should show duration, success count, skip count, and error count together; errors still require investigation and compensation.

Incomplete change detection causes silent staleness

The old code compared only a few fields (status, name) to decide "no change, skip write." But the sync actually manages more fields (security-group names, subnets, IPs, disks). Changes to those fields were silently ignored. The optimization removed the incomplete shortcut; the batch-write throughput absorbs the cost. Any future change-detection must cover every field that the sync updates.

Concurrency introduces new safety requirements

Shared counters (success, error) need atomic/thread-safe updates.

Single bad record (e.g., type conversion) must not crash the whole process; validate inputs per record.

Distributed lock release must verify ownership – a lock may have expired and been re-acquired by another process; only delete the lock you own.

Logging shifted from per-instance to per-region/per-round summaries (phase timings, page counts, retries, processed count, error samples), reducing volume and making bottlenecks easier to spot.

Results and applicability

With warm boundary cache, one measured round:

Parallel fetch: ~2 min 54 sec

Reference preload: ~4.3 sec

Batch write: ~3 min

Total: 5 min 58 sec

Versus 41–54 minutes before – roughly a 7× to 9× speedup. Soft-deleted instance sync (hundreds of instances) dropped from 4–5 minutes to ~13 seconds using the same cache and batch pipeline.

These numbers are specific to this scale and environment. Pagination concurrency must be tuned to Nova API capacity; more client requests do not guarantee faster sync. All knobs (fetch mode, concurrency, batch size) remain configurable with fallback switches. Small regions can keep the simple unsharded approach to avoid sharding overhead.

Takeaway

The optimization eliminated three classes of repeated work: serial page waits, per-instance reference lookups, and per-row transaction commits. But the decisive factors for production readiness were correctness details: cursor advancement semantics, boundary drift handling, complete field coverage, honest error accounting, and graceful degradation paths. For similar reconciliation tasks, first instrument each phase (fetch,补全, associate, write), then decide where to add concurrency, caching, or batching – and validate the upstream interface contracts before relying on them.

About this article

For questions about attribution, corrections or content rights, please contactadmin@besthub.devand we will review it promptly.

Distributed Systemsperformance optimizationbatch processingsynchronizationpaginationOpenStackcloud operationsNova

Discussion 0

Questions, practical examples and thoughtful responses.

Open full discussion