Skip to content

Release 3.4.2: direct mode keeps its engine connection alive - #34

Merged
1pxone merged 1 commit into
mainfrom
perf/sdk-keepalive
Nov 17, 2026
Merged

1pxone merged 1 commit into
mainfrom
perf/sdk-keepalive

Conversation

@1pxone

@1pxone 1pxone commented Nov 17, 2026

Copy link
Copy Markdown
Member

Direct mode now keeps its connection to the engine alive. Before, DirectEngine opened a new connection (urllib.request.urlopen) for every protocol call.

Change: each thread keeps one http.client connection to the engine and reuses it (HTTPS when the engine URL says so, certificate verified as before). No new dependency.

  • A connection the engine closed while idle is detected before reuse and replaced.
  • If a reused connection is lost before the engine answers, a read (describe, or a query other than a Cypher/SQL statement) is sent once more on a new connection. A write is not sent again; it raises RushDBError, as before.
  • Read timeouts still raise TimeoutError. DirectEngine takes timeout (default 120 s, unchanged) and has close().
  • Connections of threads that have ended are closed; a forked child process leaves the parent's sockets alone.
  • When HTTP_PROXY/HTTPS_PROXY applies to the engine URL, calls still go through urllib and the proxy, without keep-alive.

Measured: count(*) p50 through db.engine.execute() against a local rushdb 3.0.12 container (20K records, 3 × 3000 calls per run, runs alternated old/new/old/new):

Route Before (new connection per call) After (keep-alive) Plain http.client keep-alive
Published Docker port 0.155–0.164 ms 0.077–0.079 ms 0.070 ms
Container IP 0.122–0.123 ms 0.066 ms 0.061 ms

About 0.06–0.08 ms saved per call; the SDK now adds ~0.006 ms over a bare http.client connection.

Tests: new tests/test_direct_engine_transport.py (18 tests against a real local HTTP and HTTPS server: reuse, idle close, Connection: close, read resent at most once, write never resent, timeout, threads, close(), proxy fallback, TLS verified and reused, untrusted certificate refused). Existing direct-mode tests stub DirectEngine._send instead of urlopen. A live test checks that calls share one connection. Lint and mypy clean; 244 tests pass on Python 3.10, 3.12 and 3.13 with ResourceWarning as an error; the live suite passes against rushdb 3.0.12.

Patch release (3.4.2), no API change beyond the additive timeout argument and close().

DirectEngine opened a new connection (urllib.request.urlopen) for every
protocol call. It now keeps one http.client connection per thread and
reuses it (HTTPS when the engine URL says so, verified as before).

- A connection the engine closed while idle is detected before reuse and
  replaced.
- If a reused connection fails before the engine answers, a read
  (describe, query other than a statement) is sent once more on a new
  connection; a write is not and raises RushDBError, as before.
- Read timeouts still raise TimeoutError; DirectEngine takes `timeout`
  (default 120 s, unchanged).
- Connections of ended threads are closed; close() closes all; a forked
  child does not touch the parent's sockets.
- When HTTP_PROXY/HTTPS_PROXY applies to the engine URL, calls go through
  urllib and the proxy, as before.
- No new dependency.

count(*) p50 through db.engine.execute() against a local rushdb 3.0.12
container (20K records, 3 x 3000 calls per run, ABBA):
  via the published port:  urlopen 0.155-0.164 ms, keep-alive 0.077-0.079 ms
  via the container IP:    urlopen 0.121-0.123 ms, keep-alive 0.066 ms
  raw http.client keep-alive floor: 0.070 / 0.061 ms
@1pxone
1pxone merged commit 0976986 into main Nov 17, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant