Skip to content

Add QuestDB QWP support and benchmarking - #28

Draft
RaphDal wants to merge 17 commits into
masterfrom
jv/adding_qwp
Draft

RaphDal wants to merge 17 commits into
masterfrom
jv/adding_qwp

Conversation

@RaphDal

@RaphDal RaphDal commented Jul 23, 2026

Copy link
Copy Markdown

Summary

  • add a native questdb-qwp TSBS data format and QWP ingestion/query paths
  • add the ILP/HTTP comparison and reproducible benchmark artifacts
  • add --qwp-preencode-replay, which captures frames from the pinned upstream Go QWP client before timing and replays them over fresh connections

Replay benchmark boundary

The replay rate is a server-capacity diagnostic, not an end-to-end client result. It includes WebSocket connection setup, network transfer, QWP server processing, and the final cumulative ACK. Binary input decoding, row building, and QWP encoding are reported separately and excluded. The loader has no local client replacement.

Validation

  • go test -count=1 ./...
  • go test -race -count=1 ./cmd/tsbs_load_questdb
  • go vet ./cmd/tsbs_load_questdb
  • clean build against github.com/questdb/go-questdb-client/v4@afc74c3 with no replace directive
  • live 69.12M-row Delta replay with 32 connections, final ACK validation, and exact post-load row, host, and timestamp checks

Repository-wide go vet ./... still reports three pre-existing warnings outside the modified loader package.

javier and others added 17 commits July 22, 2026 18:01
QuestDB now speaks two ingestion protocols in the loader, selected with
--protocol: qwp, the binary columnar QuestDB Wire Protocol over a
WebSocket on port 9000, and ilp, the original hand-written line protocol
text over TCP on 9009. QWP is the default; ILP stays available so runs
remain comparable with the other TSBS targets, which all speak a text
line protocol over a socket.

The loader runs one QWP sender per worker with auto-flush off, publishes
on every batch boundary and relies on a clean Close to drain outstanding
server acknowledgements, so a successful run's row count is
server-confirmed rather than bytes-on-a-socket. --qwp-await-ack makes
every intermediate report acknowledged as well.

A new generator format, questdb-qwp, writes the same points in a binary
schema-and-dictionary encoding: names and symbol values are defined once
and referenced by id, numbers keep their native width. The loader detects
it from the file's magic, so nothing selects it by flag, and refuses to
send it as ILP. Decoding a row costs 51ns against 592ns to parse the
equivalent line of text, and the file is 88MB where the text is 297MB
for 864k cpu-only rows.

Measured on that data set with 8 workers against a local server, in
rows/s the server confirmed: ILP 684k, QWP from text 1234k, QWP from
binary 1867k.

QWP support is not in a client release yet, so go.mod tracks the client's
main branch as a pseudo-version.

The compiled-binaries ignore rule matched the cmd/tsbs_* source
directories too, so new files under them were invisible to git. Command
directories are now re-included.
tsbs_run_queries_questdb can now send queries three ways, selected with
--query-protocol: pg, the PostgreSQL wire default, http, the REST /exec
endpoint, and qwp, the QuestDB Wire Protocol, which streams results back
as columnar batches over the same WebSocket QWP ingestion uses. The
--use-http boolean still selects http, so existing scripts keep working.

The pgx path had its own copy of the parameter handling, so the two
transports could have drifted apart. Both now share sqlFromQuery: arrays
are inlined into the SQL, because QuestDB does not take an array bind for
an IN clause, and the remaining placeholders are renumbered. Every
transport therefore sends identical SQL with identical bind values, which
is what makes comparing them meaningful. QWP bind indexes are zero-based,
unlike the $1-based placeholders they fill.

Verified against questdb/questdb:nightly over 864k rows, 200 queries per
type: the rows returned by QWP match the HTTP response for all seven
query types exercised, including the parameterized ones. In queries/sec
QWP led five of the seven and was level with pg on the rest, with the
largest margins on the heavy aggregations, where it roughly doubled HTTP.

Loading that data also turned up a too-tight default: the client waits
5s for outstanding ACKs at Close, and Close is this loader's
acknowledgement barrier, so the last batches of a large run can exceed
it and the run fails rather than silently dropping rows. The wait is now
configurable with --qwp-close-timeout-ms and defaults to 60s.
The loader only ever spoke line protocol over TCP, which is the legacy
transport: QuestDB serves it from a dedicated thread pool whose size
varies by build, so a TSBS ILP figure was measuring that pool as much as
the database. --protocol=ilp-http sends the same rows over HTTP using the
client library, so line protocol has a baseline that does not depend on
those settings. Both client-library transports now share one processor,
which also lets either of them read the binary data format.

Measured on an r8a.8xlarge, 32 vCPU, 69.1M cpu-only rows, 32 workers,
client and server on one box as in the published comparisons. Send rates:

                                        ILP/TCP      ILP/HTTP
  9.4.3 release, defaults            9.3-12.5M      6.8-6.9M
  9.4.4-SNAPSHOT nightly, defaults        1.7M      6.9-7.0M
  nightly, 16 ILP io workers              8.0M             -

ILP/TCP swings sevenfold across builds and settings while HTTP does not
move. The nightly gives the ILP/TCP pools 2 threads where every shared
pool gets 31; the release has no separate ILP pool at all. Neither the
client nor the connection count explains it: 32 connections were
established every time, and the loader parses that file at 17.3M rows/s
with --do-load=false.

Against a fairly configured server, committed throughput was QWP 6.7M,
ILP/HTTP 5.3M, ILP/TCP 5.0M rows/s. Every transport sends faster than the
write-ahead log applies, so committed rates converge and WAL apply, not
the wire, is the ceiling.

Queries went the other way from ingestion: QWP wins where result sets are
large, 2.1x HTTP and 1.4x PostgreSQL wire on a query returning 1.6M rows,
and is level with the others on aggregates returning tens of rows. Rows
returned over QWP matched the HTTP response for all 16 query types.

Two measurement traps are documented alongside the numbers. A QWP send
rate moves 25% with the ack policy alone while committed throughput moves
the other way, and ILP/TCP's fire-and-forget send rate ranks it first on
the wire and last on rows made visible. docs/questdb-qwp-benchmark.md has
the full write-up; docs/questdb.md carries the caveats next to the flags.

Close's drain default of 5s was also too tight to be the loader's
acknowledgement barrier and failed a large run outright, so it is now
configurable with --qwp-close-timeout-ms and defaults to 60s.
Two claims in the write-up were wrong and are replaced by measurements.

QWP was reported as 1.3-1.7x ILP on throughput. That margin came from
comparing against a build serving ILP/TCP from a 2-thread pool. Sized like
the other pools, ILP/TCP reaches release-build speed, and on rows sent the
two transports are level: at 4,000 hosts ILP 11.6M against QWP 11.1M, at
100,000 ILP 9.6M against QWP 11.6M. The best QWP configuration leads the
best ILP one by 19% and 5% respectively, not by a multiple.

Write-ahead log apply was described as the ceiling every transport
converges on. It is not. Raising QDB_WAL_APPLY_WORKER_COUNT from its
default of 3 to 8, 16 and 31 leaves committed throughput unchanged for
every transport, and the transports do not converge: on the same table
and the same apply path ILP commits at ~3.5M rows/s and QWP at ~6.5M.
QWP's advantage is in rows made visible, it is 1.85x at identical
configuration, and it survives the apply-thread sweep. Why the two differ
upstream of apply is now the open question worth answering.

The write-up also records that the nightly's ILP/TCP default costs 5.5x
at 4,000 hosts and 8.7x at 100,000 against the release, that the
published 8.39M and 11.36M figures both reproduce on the release build,
that a QWP send rate moves 25% with the ack policy alone while committed
moves the other way, and that ILP's committed rate falls as its pools
grow while QWP shows no such tension.

benchmark-artifacts/ holds every raw result and the harness that produced
them, so each table can be traced to the run behind it.
Rows sent is the metric QuestDB publishes, so it now carries every table
and the visibility metric moves to a closing note.

The narrative follows the day instead of the conclusions. It opens with
4,000 hosts on stock defaults, where ILP/TCP reads 1.7M against QWP's
11.1M, then shows that figure to be the nightly's 2-thread ILP pool:
sized like the other pools ILP/TCP reaches 12.9M, matching the release
build. The fair comparison at 4,000 hosts follows, where plain QWP is
marginally behind ILP/TCP and only per-batch acks put it ahead, by 19%.
Then the other scales, where QWP leads by 10-20% at 1,000 and 100,000
hosts. Then queries, which is where QWP wins clearly and only on large
result sets.

The write-ahead log apply sweep is reduced to a paragraph recording that
it changed nothing.
The same-host TSBS numbers hid QWP's advantage: client and server share
the 32 cores, and QWP's binary encoding competes with the server for
them, so the two look level on rows sent. Splitting the loader onto its
own instance separates them. Over the private network both ILP transports
pin at the 14.7 Gbit/s link ceiling at 5.3M rows/s, while QWP sustains
9-12M, because line protocol text is 3.4x larger on the wire. That is the
result that matters and it now opens the write-up.

Pre-encode replay then locates the bottleneck by taking the Go client's
encoding out of the timed path. QWP tops out at three distinct ceilings,
all with every row verified visible: 9.4M via the Go client over the
network (client-bound), 18.5M pre-encoded over the network (network-bound,
matching the wire), and 45-50M pre-encoded on localhost (the server's true
ingest capacity, ~4-9x ILP). The Go client encoding is the single biggest
lever for QWP ingestion.

The write-up now also explains how the loader sends QWP: one sender per
worker, rows built through the client's typed API and encoded per row,
flushed per batch, published rather than committed by default. That
per-row encoding is the client cost the replay path isolates, and ILP
avoids it only because its text is already the wire format.

benchmark-artifacts/ carries every raw result and the harness. The earlier
split-replay files are kept for provenance but superseded by the corrected
replay-localhost and replay-network files, whose committed counts were
measured rather than inferred.
Folds three things that lived only in raw JSON or in conversation into
the benchmark doc:

- The direct-frame (pre-encode replay) send rate across cardinalities,
  including the 100,000-host network figure (~12M) that was only in the
  raw JSON. Records honestly that 4,000 hosts is the fully measured scale,
  100,000 is send-only, and 1,000 was never run. Notes the finding that
  the server's pure-frame ingest falls with cardinality (18M at 4k to 12M
  at 100k) while the Go-client rate barely moves, because the client is
  its limit at both.

- The CPU split sampled from /proc during a co-located load: the QWP
  loader burns ~10 of 32 cores encoding rows against ILP/TCP's ~1.7, and
  QWP is the most server-efficient transport per row. This was measured
  once and existed nowhere but the session transcript.

Committed rows are deliberately out of scope for the send-rate benchmark,
so the only remaining soft spot (100k direct-frame committed unverified)
does not matter here.
Update go.mod/go.sum to go-questdb-client/v4 at the latest main commit
(4f2723e2), dropping the removed WithInFlightWindow option in the QWP
replay encoder. Add --qwp-tags-as-varchar, which sends tag columns as
VARCHAR over QWP instead of SYMBOL so no per-frame symbol dictionary is
shipped, while the server can still store the columns as SYMBOL.
…ted pinning

Document --qwp-tags-as-varchar, correct the --qwp-preencode-replay example to a
batch size that stays under the server's ~2 MB frame limit (45000 produced
oversized frames the server rejects at any real cardinality), and add the
co-located CPU-pinning methodology for a fair ILP-vs-QWP comparison.
The loaders are light (ILP ~1.7 cores, a replay send lighter), so pin the
client to two cores and the server to thirty rather than splitting 16/16.
That keeps the server near full capacity while still isolating it from the
client, and gives the server the same 30-core budget in the networked run.
Report (qwp-varchar-report.md): ILP vs QWP-symbol vs QWP-varchar ingestion at
1K/4K/100K/1M, localhost and network, on the latest go-questdb-client (4f2723e2)
with 30/2 CPU pinning, plus the pg/http/qwp query-transport comparison at 4000
hosts. Raw results: the varchar sweep, the 1K sweep, the cardinality sweep, and
the query results.
Fold the still-valid explanatory sections of docs/questdb-qwp-benchmark.md
(loader mechanics, the co-located CPU competition that motivates the 30/2 CPU
pinning, the ILP/TCP thread-pool default, WAL apply / send-vs-committed, data
volume, ack policy) into benchmark-artifacts/qwp-varchar-report.md, corrected
against the latest-client run: high cardinality no longer drops off over the
network, 1M ingests cleanly, and the query numbers are refreshed. Remove the
superseded docs/questdb-qwp-benchmark.md so there is one canonical write-up.
Make explicit that --qwp-tags-as-varchar was an experiment testing dictionary
(SYMBOL) vs raw-string (VARCHAR) tag encoding, and that symbols were at least as
fast in every cardinality and topology (about 2x over the network).
# Conflicts:
#	README.md
#	cmd/tsbs_load_questdb/main.go
#	cmd/tsbs_load_questdb/qwp.go
#	cmd/tsbs_load_questdb/qwp_binary.go
#	cmd/tsbs_load_questdb/qwp_binary_test.go
#	cmd/tsbs_load_questdb/qwp_test.go
#	cmd/tsbs_run_queries_questdb/main.go
#	cmd/tsbs_run_queries_questdb/qwp_client.go
#	cmd/tsbs_run_queries_questdb/sql.go
#	cmd/tsbs_run_queries_questdb/sql_test.go
#	docs/questdb.md
#	go.mod
#	go.sum
#	scripts/load/load_questdb.sh
Each *MeasurementTick test seeded the global rand only after constructing
the measurement, whose starting values also come from it. A field could
start near a clamp bound and stay there across both ticks, failing the
'value changed' check (seen in CI on usage_guest). Seed first.

TestMemMeasurementToPoint computed (100*x)/total while ToPoint computes
100*(x/total); the two round differently and the comparison is exact.
Mirror ToPoint's operation order.
The raw result files, the varchar report and the scripts that produced
them are working material, not part of the tool.
@ideoma

ideoma commented Oct 8, 2026

Copy link
Copy Markdown

Review: level 3 (adversarial, evidence-gated)

Verdict: approve with comments. Nothing is blocking. I'd fix M1–M4 before merging.

Every item below was reproduced by running it, at head 2fecddc, with base b12abbe, against a local QuestDB 10.0.2-SNAPSHOT. The happy path works: replaying the cpu-only and 9-table devops data loaded the exact row counts. go test, go vet and CI are green.

The PR changes no submodules, so the scope is the 14 files in the diff.

Critical

None.

Moderate

M1. A replay can hang forever on an endpoint that never answers

  • Problem: the replay sets no timeout on dial, on the upgrade response, or while sending frames.
  • Who is hit: anyone running --qwp-preencode-replay against a stalled or silent endpoint. The run never ends.
  • Evidence: I pointed it at a local listener that accepts connections and never responds. The replay was still running when I killed it at 60s. The normal QWP path fails after 15s with timeout awaiting response headers, on both head and base.
  • Where: cmd/tsbs_load_questdb/qwp_replay.go:
    • net.Dial at line 470 has no timeout.
    • http.ReadResponse at line 515 has no deadline.
    • io.Copy at line 434 has no write deadline.
    • The only deadline is a read deadline, set at line 449 after sending has finished.
  • Fix: use a net.Dialer with a timeout, and set a deadline on the connection before the upgrade, matching the client's 15s auth_timeout. Also put a progress-based write deadline on the copy.

M2. A comma-separated --qwp-addr means failover normally, but round-robin in replay

  • Problem: the same flag value behaves differently with --qwp-preencode-replay.
  • Who is hit: replay users with a failover address list. The run fails and leaves the tables partly loaded.
  • Evidence: with --qwp-addr 127.0.0.1:29000,127.0.0.1:1 --workers 2:
    • The normal path loads all 216000 rows.
    • Replay exits 1 with dial 127.0.0.1:1: connection refused, leaving 110000 rows in the table.
  • Where: qwp_replay.go:107 sends worker i to endpoints[i%len(endpoints)] with no fallback. The flag help says "Comma-separated list enables failover". Against a primary+replica pair, the replica connections would get a 421.
  • Fix: pick one of these:
    • Fail over per connection, trying each endpoint in turn.
    • Reject multiple addresses in replay mode.
    • Document round-robin explicitly.

M3. --qwp-tags-as-varchar is not limited to the paths it describes

  • Problem: the flag is silently ignored in one case and silently changes a non-QWP protocol in another.

  • Who is hit: anyone running the varchar experiment can get results labelled with the wrong tag type.

  • Evidence (fresh tables):

    Input Protocol Result with the flag
    text qwp tags stay SYMBOL, so the flag does nothing
    binary ilp-http tags become VARCHAR
    binary qwp tags become VARCHAR, as intended
  • Where:

    • qwp_binary.go:371 is the only place that reads tagsAsVarchar.
    • The ILP text path always calls Symbol (qwp.go:255).
    • GetProcessor routes binary ilp-http input through writeBinaryRow, so the flag reaches ILP/HTTP.
    • main.go:158 reads the flag but never checks protocol or input format.
  • Fix: in main, reject the flag unless the protocol is qwp and the input is binary. Alternatively, also implement it in writeRow.

M4. The replay hides the server's reason when it rejects an oversized frame

  • Problem: the server's WebSocket CLOSE code and reason are thrown away.
  • Who is hit: anyone whose batch size is too large. The error doesn't say why.
  • Evidence: I ran --batch-size 40000 through a proxy that captured the server's bytes.
    • The server sent CLOSE code=1009 reason='frame payload exceeds maximum size'.
    • The loader printed only server acknowledged 0 frames from …, expected 3.
  • Where: qwp_replay.go:588 handles the close frame with return acked, nil and never reads its payload.
  • Fix: decode the close code and reason, and include them in the error whenever the ACK count is short. A related case I could not reproduce locally: a large stream that outlasts the server's 5s drain fails in io.Copy with a generic broken pipe.

M5. Ctrl-C or SIGTERM leaves the whole pre-encoded dataset in $TMPDIR

  • Problem: the temp directory is removed only by defer dump.close() (line 75). The loader has no signal handler, so a signal skips the cleanup.
  • Who is hit: anyone who interrupts a replay. Each interrupted run leaves a copy the size of the encoded data (gigabytes at a 69M-row scale). The path is never printed.
  • Evidence: 4 of 4 runs leaked the directory under SIGINT and SIGTERM, against both a stub endpoint and the real server. Each leftover directory was 19717928 bytes, exactly the encoded size. A normal exit cleans up.
  • Docs gap: docs/questdb.md doesn't mention that replay needs temp space equal to the encoded size. On a Linux host where /tmp is in memory (tmpfs), that space takes RAM from a co-located server.
  • Fix:
    • Handle signals and clean up.
    • Print the directory path.
    • Document the temp-space requirement, or add a flag to choose the location.

M6. The PR title and description don't match the diff

  • Problem: the title and summary describe the data format, query paths and ILP/HTTP comparison. That work already merged in feat: add QuestDB QWP ingress/egress and InfluxDB 3 support #29. This diff is the replay mode, --qwp-tags-as-varchar, docs, and devops test fixes.
  • Further mismatches:
    • The body cites client commit afc74c3, but go.mod pins 4f2723e2d5cb and isn't changed by this PR.
    • The body doesn't mention the varchar flag or the flaky-test fixes.
    • The title isn't in the feat:/chore: form that recent master commits use (e.g. feat: add QuestDB QWP ingress/egress… (#29)).
  • Fix: something like feat(questdb): add QWP pre-encoded replay and tags-as-varchar, with the body rewritten to match the diff.

Minor

  • pkg/data/usecases/devops/*_test.go: the same 3-line comment is pasted 10 times. Use one shared seeding helper or a single comment.
  • qwp_replay.go:266: the comment narrates a removed client option (WithInFlightWindow). Keep only the line describing current behaviour.
  • qwp_replay.go:567,576: status bytes are hard-coded, though the client exports qdb.QwpStatusOK and qdb.QwpStatusDurableAck. The error-ACK test uses status 0x01, which the client doesn't define; 0x05 (QwpStatusParseError) would be realistic.
  • The pre-encode senders log CONNECTED, endpoint=127.0.0.1:9000 whatever --qwp-addr is set to. That's misleading next to replay errors.

Coverage map

The test gate passes. There are 2 coverage gaps, both Moderate:

  1. The real server's success path has no test.
    • QuestDB ends a replay connection with EOF, not a CLOSE frame. The test's stub server always sends CLOSE (qwp_replay_test.go:137).
    • I mutated the check at qwp_replay.go:454 to if result.err != nil { (dropping the EOF tolerance). go test still passes, yet every live replay then fails with read QWP replay response: EOF (7 of 7 runs).
    • Fix: add a variant where the stub server just closes the connection.
  2. The tagsAsVarchar branch and the pre-encode logic have no tests.
    • The pre-encode logic covers round-robin batching, frame counting, the final partial batch, and the auth headers.
    • The existing recordingSender in qwp_test.go makes the varchar case a few-line test.
    • A small binary input pre-encoded and then replayed into the existing stub server would cover the rest.

Summary

  • Severity counts: 0 Critical, 6 Moderate, 4 Minor. All are in the diff; none are breakage outside it.
  • Devops test fixes: correct. The seed now takes effect because go.mod declares go 1.23.10. The mem_test arithmetic matches ToPoint exactly.
  • Callers checked: every caller of the changed symbols and global flags. The query runner and the legacy ILP path are unaffected.
  • Not reported, for lack of a way to reproduce: the --tls half-close behaviour (OSS QuestDB has no server-side TLS to test against) and a host-only --qwp-addr (it fails fast with a clear error).

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.

3 participants