Area: Ingestion Issues
Sub-Area: Custom Ingestion Performance / Write Throughput
Applies to: Cloud
Issue
Custom Python scripts that write metadata with the DataHub SDK (DatahubRestEmitter or DataHubGraph) take much longer to finish than before. The data still lands, but each run is slow. Sometimes several scripts slow down at the same time.
On DataHub Cloud, this happens when your instance has a write rate limit and your scripts send synchronous writes. The server rejects writes over the limit with HTTP 429. The SDK waits and retries each rejected request, so runs get longer.
You Might Be Asking
- Why did my custom ingestion scripts start taking much longer, with no changes on my side?
- What does write rate limiting on DataHub Cloud do to my scripts?
- How do I switch my scripts to async emit mode?
- Does batching with
emit_mcpslower my rate limit usage? - Can a rate limited write fail?
Cause
By default the SDK emitter uses the SYNC_PRIMARY emit mode. Each write is committed to the primary database before the call returns. This mode is not meant for bulk writes, because one synchronous commit per write puts heavy load on the backend.
When DataHub Cloud applies a write rate limit, synchronous writes can be checked against their own, stricter limit than async writes. The stricter sync limit exists to move bulk writers to async mode. The limit is not per script, so every script that writes to the instance shares it.
The server counts every metadata change proposal (MCP), not every HTTP request. A batch of 200 MCPs uses 200 units of the limit.
When a write is over the limit, the server returns HTTP 429. The SDK retries 429 responses with backoff, up to about 8 times with the default settings. If the limit still holds after the last retry, the emit call raises an error that starts with Unable to emit metadata to DataHub GMS, and that write is not stored.
Recipe based ingestion that uses the datahub-rest sink is a different case. Its default mode is ASYNC_BATCH, which already sends async writes. This article is about scripts that call the SDK emitter directly.
Solution
-
Confirm that rate limiting is the cause.
The SDK logs each retry as
Retrying after 429at debug level only, so you don't see it in normal output. Turn on debug logging for thedatahublogger in your script and look for that line:import logging logging.basicConfig() logging.getLogger("datahub").setLevel(logging.DEBUG)You can also contact DataHub Support to confirm whether a write rate limit is active on your instance.
-
Switch your scripts to async emit mode.
Set this environment variable where your scripts run:
export DATAHUB_EMIT_MODE=ASYNC python your_ingestion_script.pyOr for a single run:
DATAHUB_EMIT_MODE=ASYNC python your_ingestion_script.pyThe SDK reads
DATAHUB_EMIT_MODEwhen it is first imported. Set it in the shell, container or job environment. Settingos.environinside the script after the import has no effect.You can also set the mode in code. Pass
default_emit_modewhen you create the emitter, or passemit_modeon a single call. See Emit Modes.from datahub.emitter.rest_emitter import DatahubRestEmitter, EmitMode emitter = DatahubRestEmitter( gms_server="https://<your-instance>.acryl.io/gms", token="<your-access-token>", default_emit_mode=EmitMode.ASYNC, )In
ASYNCmode, the server queues each write and the call returns right away. The write is processed after the call returns. -
Send writes in batches with
emit_mcps.emit_mcpssends a list of MCPs in as few requests as it can. This cuts the number of HTTP requests and the network overhead. It does not lower your rate limit usage, because every MCP in the batch still counts. Async mode is the change that moves your writes off the stricter sync limit.# mcps is the list of MetadataChangeProposalWrapper objects your script builds emitter.emit_mcps(mcps)You don't need to size batches yourself.
emit_mcpssplits a large list into chunks of at most 200 MCPs or 15 MB each. -
Plan for async behavior.
In
ASYNCmode, two things change:-
emit()andemit_mcps()don't raise an error for a write the server rejects later. The call succeeds once the change is queued. - A read right after a write can return the old value. If your script writes an entity and then reads it back, split the work into a write phase and a read phase, or use
ASYNC_WAITfor the writes you must read back.ASYNC_WAITwaits until the queued change is confirmed persisted.
-
-
Check the result.
Run your scripts again and compare run times against earlier runs. Check the debug log for
Retrying after 429lines.
Writes that contain only timeseries aspects (for example dataset profiles and operations) always count against the general limit, in both sync and async mode. Async mode does not change their rate limit usage.