Vacuum on a big table with a long history of removed files sends a lot of S3
requests in a short window. It lists the table, then deletes every expired
file it finds. S3 answers the burst with 503 SlowDown, and the vacuum dies
partway through.
Slow the requests down and the job finishes. deltalake-core takes an
ObjectStore, so the throttle goes there.
Where the requests come from
deltalake-core does not talk to S3 directly. Vacuum and optimize both get their store from the table's log store, so one wrapper covers both.
VacuumBuildertakes its store fromlog_store.object_store()for the listing and the deletes.OptimizeBuilderdoes the same for reads and compacted writes.
DeltaTableBuilder::with_storage_backend accepts a store from the caller. Wrap
it there and both operations pick up the wrapper.
ThrottledStore
object_store::throttle::ThrottledStore<T> wraps any ObjectStore and sleeps
around each call. ThrottleConfig sets the delays:
wait_delete_per_call: one sleep per delete. Vacuum deletes throughdelete_stream, so this is the knob for vacuum.wait_list_per_callandwait_list_per_entry: listings.wait_put_per_callandwait_get_per_call: writes and reads.wait_get_per_byte: reads, per byte.
config_mut changes the config on a live store, so a long job can change pace
without a restart.
The object_store docs call ThrottledStore a performance-testing tool. The
sleeps are fixed. It does not enforce a requests-per-second budget, so it won't
hold a rate under a bursty load. For a batch job, a fixed delay per request is
usually enough. It needs the tokio feature.
Wiring it up
This is the shape of the code. A runnable version is in the
throttled-store-s3-example
repo, GPLv3, pinned to deltalake-core 1.1.4, deltalake-aws 1.0.0, and
object_store 0.13.2.
use std::sync::Arc;
use std::time::Duration;
use deltalake_core::DeltaTableBuilder;
use object_store::throttle::{ThrottleConfig, ThrottledStore};
use url::Url;
// Register the s3:// scheme. The custom-store path skips the registry, but the
// log store lookup still needs it.
deltalake_aws::register_handlers(None);
let location = Url::parse("s3://my-bucket/events")?;
let raw_store = Arc::new(build_s3_store()?);
let throttle = ThrottleConfig {
wait_delete_per_call: Duration::from_millis(50),
wait_list_per_call: Duration::from_millis(20),
..Default::default()
};
let store = Arc::new(ThrottledStore::new(raw_store, throttle));
let mut table = DeltaTableBuilder::from_url(location.clone())?
.with_storage_backend(store, location)
.build()?;
table.load().await?;
build_s3_store() stands in for however you already build your AmazonS3.
Throttling a shared store slows every other reader and writer on it, so give
the maintenance job its own instance.
Picking numbers
The right values depend on your bucket's request budget and on how many files a vacuum will delete. Pick a delete delay that keeps the sustained rate under the limit in your logs. Measure it on a copy of the table before you run it on production.
Local results
The example runs against LocalStack 4.11.1 on one machine. Five overwrites, then a zero-retention vacuum:
| delete delay | files deleted | vacuum elapsed |
|---|---|---|
| 0 ms | 4 | 0.05 s |
| 50 ms | 4 | 0.25 s |
The 50 ms run adds about 200 ms for four deletes, which is the configured delay.
Not the fix for everything
Throttling covers a backlog that already exists. The longer-term fixes are a shorter retention window, vacuuming more often so each run has less to delete, and optimizing small files so a later vacuum has fewer requests to make.
Throttling with fixed delays is the simple version. There are more clever ways to make it dynamic, for example backing off based on the S3 error codes that come back. That is an exercise for another day.
If vacuum still hits limits with the throttle in place, open an issue on delta-rs with the table size, the number of expired files, and the error. Buoyant Data also helps teams size and schedule maintenance on big tables. Reach us at hello@buoyantdata.com.
