Area: Deployment Issues
Sub-Area: GraphQL Performance / Elasticsearch Query Optimization
Applies to: OSS + Cloud
Issue
A script or service pages through the catalog with the scrollAcrossEntities GraphQL query. It uses a large count and asks for many fields per entity. Some requests return HTTP 503 or 504 from /api/graphql, and the DataHub UI (search and lineage) gets slow while the job runs.
Each page makes DataHub load every requested field for every entity on the page. A large page with a wide field selection can take longer than the request timeout of the proxy or load balancer in front of DataHub. The proxy then closes the request and returns a 5xx error, even though the server is still working on it. GMS has its own request timeout too. The default is 55 seconds, and you can configure it. When a GraphQL request runs longer than this timeout, GMS returns 503 with a Retry-After: 30 header. GMS keeps the query running in the background. Either timeout can cause the 5xx error. The fix is the same for both timeouts: make each page smaller and cheaper. On DataHub Cloud, contact DataHub Support to change the GMS timeout. Retries and parallel loops add more load, so the UI slows down for everyone.
On DataHub Cloud, a second cause makes this worse: metadata tests that run against the whole catalog write one graph edge per evaluated asset into the same Elasticsearch index that serves lineage queries.
You Might Be Asking
- Why does my
scrollAcrossEntitiesloop return 503 errors only some of the time? - What
countshould I use when I scroll through the whole catalog? - Why is lineage slow when Elasticsearch reports a green cluster?
- How do metadata tests affect lineage and search performance?
Solution
1. Make each scroll page smaller and cheaper (OSS + Cloud)
- Lower
count. The GraphQL best practices say a page with a minimal set of attributes can return 1,000 to 2,000 results. Lowercountas you add fields, especially nested objects, down to 20 to 25 for very complex requests. - Request only the fields you use.
- Set
skipHighlightingandskipAggregatesinsearchFlags. A scroll loop doesn't need highlights or facet counts. - Pass
nextScrollIdfrom each response asscrollIdin the next request. Stop whennextScrollIdis null.
A minimal query:
query ScrollEntities($input: ScrollAcrossEntitiesInput!) {
scrollAcrossEntities(input: $input) {
nextScrollId
searchResults {
entity {
urn
type
}
}
}
}
Variables for the first page:
{
"input": {
"query": "*",
"types": ["DATASET"],
"count": 500,
"searchFlags": { "skipHighlighting": true, "skipAggregates": true }
}
}
- Don't run several scroll loops against the same DataHub instance at the same time. Each loop adds its own load.
- Retry 502, 503 and 504 responses with exponential backoff and jitter. Don't retry right away.
import random
import time
import requests
SCROLL_QUERY = """
query ScrollEntities($input: ScrollAcrossEntitiesInput!) {
scrollAcrossEntities(input: $input) {
nextScrollId
searchResults { entity { urn type } }
}
}
"""
def scroll_page(gms_url, token, input_vars, max_retries=5):
delay = 1.0
for _ in range(max_retries):
response = requests.post(
f"{gms_url}/api/graphql",
json={"query": SCROLL_QUERY, "variables": {"input": input_vars}},
headers={"Authorization": f"Bearer {token}"},
timeout=120,
)
if response.status_code in (502, 503, 504):
time.sleep(delay + random.uniform(0, delay / 2))
delay = min(delay * 2, 60)
continue
response.raise_for_status()
return response.json()["data"]["scrollAcrossEntities"]
raise RuntimeError("scrollAcrossEntities still failing after retries")
def scroll_all(gms_url, token, input_vars):
while True:
page = scroll_page(gms_url, token, input_vars)
for result in page["searchResults"]:
yield result["entity"]["urn"]
if not page["nextScrollId"]:
return
input_vars = {**input_vars, "scrollId": page["nextScrollId"]}
If you use the Python SDK, DataHubGraph.get_urns_by_filter() scrolls with batch_size=5000 by default. It asks only for URNs and already skips highlighting and aggregates. If those calls time out, pass a smaller batch_size.
2. Cut graph writes from metadata tests (Cloud)
Metadata tests are the tests under Govern > Tests. They are not assertions. Every time a test evaluates an asset, DataHub stores the result on that asset and writes one graph edge from the asset to the test: IsPassing for a pass, IsFailing for a fail. Passing results write edges too. A test scoped to millions of assets writes millions of edges into the graph index that lineage queries use. The test's scheduled batch then rewrites those results every day.
- Go to Govern > Tests. Look at the passing count and the failing count on each test card. Add the two counts, because
IsPassingedges andIsFailingedges both add to the graph index. Change the tests that have very large totals. - For scorecard tests (ownership, documentation, descriptions), narrow the selection criteria to the domains, containers, platforms or tags you actually govern.
- To stop a test while you rethink its scope, turn off the switch on its card. This sets the test to inactive, so it no longer runs. Turn the switch back on to resume.
- For tests that exist only to apply actions (add a tag, set a domain, assign owners), edit the test and turn off Track & show results per asset. The test still runs its actions, but DataHub doesn't store a pass or fail result per asset.
See Metadata Tests for how to edit selection criteria and rules.
As a DataHub Cloud customer, you can't query Elasticsearch, run index maintenance or change GMS settings yourself. If pages stay slow, contact DataHub Support.
3. Check Elasticsearch and GMS settings (OSS)
A green cluster status doesn't rule out problems with one index or one node. If you run DataHub yourself, check these.
- Deleted documents on the graph index. The index is named
graph_service_v1, or<prefix>_graph_service_v1if you set an index prefix, so match it with a wildcard:
GET /_cat/indices/*graph_service_v1*?v&h=index,docs.count,docs.deleted,store.size
- Heap and CPU per node:
GET /_cat/nodes?v&h=name,heap.percent,cpu,node.role&s=heap.percent:desc
- GMS settings (see Deployment Environment Variables):
-
SEARCH_SERVICE_ENABLE_CACHE(defaultfalse) turns on the GMS search service cache. -
ELASTICSEARCH_SEARCH_GRAPH_LINEAGE_MAX_HOPS(default20) sets the most hops GMS traverses for the lineage graph. A lower value means fewer Elasticsearch round trips for deep lineage.
-