Skip to content

perf(trino-driver): native REST polling to cut coordinator wait/drain latency - #11548

Open
aman-shrivastava01 wants to merge 2 commits into
cube-js:masterfrom
aman-shrivastava01:trino-driver-enhancement
Open

perf(trino-driver): native REST polling to cut coordinator wait/drain latency#11548
aman-shrivastava01 wants to merge 2 commits into
cube-js:masterfrom
aman-shrivastava01:trino-driver-enhancement

Conversation

@aman-shrivastava01

Copy link
Copy Markdown

Check List

  • Tests have been run in packages where changes have been made if available
  • Linter has been run for changed code
  • Tests for the changes have been added if not covered yet
  • Docs have been added / updated if required

Description of Changes Made

@cubejs-backend/trino-driver no longer wraps presto-client / PrestoDriver. It talks to Trino's HTTP protocol directly (POST /v1/statement, then GET nextUri). The protocol is the same; the poll cadence is not.

presto-client slept ~800ms on every poll, including while the query was still queued and after rows were already flowing. That wait dominates interactive latency. PrestoDB is unchanged and still uses presto-client.

Polling

  • While queued or planning (no rows yet): 50ms for the first 10 empty polls, then +50ms, capped at 500ms.
  • After the first rows: no extra delay (drainInterval default 0).
  • checkInterval: 800 restores constant-interval polling for both phases.

Tune with CUBEJS_DB_TRINO_POLL_* or driverFactory (pollBackoff, drainInterval, checkInterval). Invalid poll env values are rejected.

Compatibility

  • Parameter escaping stays formatAnsi.
  • Custom headers are sent on the statement POST and on every nextUri poll, including worker hosts.
  • SSL, /v1/info testConnection, and X-Trino-Source default nodejs-client are unchanged.

Behavior changes

  • dialectClass() returns TrinoQuery (AT TIME ZONE plus DATE promotion), matching QueryBuilder's trino mapping. The previous wrapper selected PrestodbQuery.
  • CUBEJS_DB_QUERY_TIMEOUT (default 10m) is sent as query_max_run_time on every statement, not only streams.
  • When user is not set, X-Trino-User uses basic_auth.user so the session user matches the authenticated principal.
  • Multi-page results append in arrival order.
  • HTTP(S) keep-alive is on by default; release() destroys the agents.
  • TrinoDriver no longer extends PrestoDriver.

Test plan

  • packages/cubejs-trino-driver: lint and 63 unit tests
  • packages/cubejs-backend-shared: Trino poll/source env parsing tests
  • yarn integration:trino against a live Trino container (11/11)
  • packages/cubejs-testing: yarn smoke:trino timezone snapshot

… latency

presto-client slept ~800ms on every nextUri poll, including while Trino was
still queued and after rows were already flowing. Talk to POST /v1/statement
directly with short wait-phase backoff and immediate drain.

Use OSS TrinoQuery (AT TIME ZONE + DATE promotion) instead of PrestodbQuery.
Keep formatAnsi escaping, poll headers, and X-Trino-Source=nodejs-client.

Signed-off-by: Aman Shrivastava <aman.shrivastava@coupa.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@aman-shrivastava01
aman-shrivastava01 requested review from a team and keydunov as code owners August 13, 2026 18:58
@github-actions github-actions Bot added javascript Pull requests that update Javascript code data source driver driver:trino Issues relating to the Trino driver pr:community Contribution from Cube.js community members. labels Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data source driver driver:trino Issues relating to the Trino driver javascript Pull requests that update Javascript code pr:community Contribution from Cube.js community members.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant