Skip to content

DuckDB 2.0.1, and a faster, leaner server - #246

Merged
jrosskopf merged 20 commits into
mainfrom
chore/gh-241-duckdb-2-0
Nov 23, 2026
Merged

jrosskopf merged 20 commits into
mainfrom
chore/gh-241-duckdb-2-0

Conversation

@jrosskopf

@jrosskopf jrosskopf commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • DuckDB 1.5.5 → 2.0.1 with every 2.0 breaking change handled (static extension linking, Parser/Identifier API, removed profiling settings, duckdb_settings() without extension settings, ATTACH option parsing, CTAS validation, single-arrow lambdas, BIT/INTERVAL rendering, DuckLake 1.1 future-timestamp error). State written by 1.5.5 (db_path, DuckLake catalogs) keeps working (tested against the v26.11.21 binary in CI).
  • Faster and leaner than v26.11.21 on the same 50-endpoint benchmark (24 cores): simple endpoint 1.5k → 7.6k req/s at 64 clients and 22 → 5.5k req/s on one keep-alive client; point lookups 1.6–15x; parquet scans 2.4x at 8 clients; peak memory 10–50% lower in every scenario, idle 214 → 175 MB. Remaining: row-heavy pages at 64 clients −20% (DuckDB 2.0 prepared-statement execution), startup 0.05 → 0.10 s (DuckDB 2.0 database open). Main causes: TCP_NODELAY, COUNT only when the page cannot tell the total (+ opt-in total-count: false), connection + prepared-statement reuse, rows streamed straight into the response text, adaptive async I/O, pools and jemalloc arenas sized to usable CPUs, aggregated telemetry.
  • Fixes found on the way: ENUM segfault, NULL DATE/TIME/INTERVAL printing leftover memory, interval text, 1e300 → 1000.0, Arrow >2.7M rows / INTERVAL / explicit paging, >1 MiB body resetting the next keep-alive request, startup-failure exit code under Crow 1.3. Crow 1.2.0 → 1.3.4.
  • Follow-ups filed: Cache total_count for DuckLake-cached endpoints #242 (count cache), Per-request CPU waste: env copy, template re-read, double route match #243 (per-request CPU), Strip release binaries #244 (strip binaries), Design: ship DuckDB extensions with flAPI instead of downloading them #245 (ship extensions with releases, design).

Test plan

  • ctest: 1001/1001
  • Full integration suite on the 2.0.1 binary (last full run 1497 passed; the 4 failures it showed were Crow 1.3's bind-failure behaviour, fixed and re-run green); new tests: upgrade from 1.5.5 state, robustness (kill -9 during refresh, max_memory), pagination COUNT behaviour + query counts from traces, large-response memory, keep-alive latency, threads under a CPU affinity limit, async_threads defaults, connection reuse vs refreshes and session state, value rendering, startup resources, a realistic differential suite (362 requests byte-compared with the previous build + 48 parallel clients during cache refreshes) and a soak (FLAPI_SOAK=1, 10 min: 102k requests, 0 errors, stable fds/threads)
  • scripts/bench harness: results above, gated with compare.py
  • check_skills --static-only: 91/0
  • CI green on all platforms (Linux amd64/arm64, macOS, Windows, docker, pack smoke)
  • Real cloud (AWS/GCS/Azure) still only verified against fakes.

Closes #241


Get evidence
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

- scripts/bench: black-box latency, throughput, startup and RSS benchmark plus a compare gate
- test_duckdb_upgrade: state written by the previous binary (db_path, DuckLake full and merge caches) must keep working
- test_robustness_upgrade: kill -9 during a refresh and max_memory pressure leave the server usable
- Version strings in the pack tests are opaque fixtures, no longer tied to a DuckDB version
- Pin the duckdb submodule and DUCKDB_EXPLICIT_VERSION to 2.0.1
- CMake: link core_functions, parquet, json and icu plus the httplib/loadable_extensions/local_extension_repository
  capabilities ourselves (2.0 puts them into libduckdb only, duckdb_static is a bare archive), by file so the
  extensions do not export DuckDB's namespaced zstd headers over the real zstd.h; register them from the executables
- CMake: turn DuckDB's own test runner off (its test dir no longer configures as a subproject)
- C++: Parser::GetBuiltinParser(), Identifier names for ATTACH/DETACH, QueryResult::Fetch in the embed fs test
- SQL: lambda x : ... instead of the removed single-arrow lambda in the DuckLake retention queries
- BIT values render as plain bit strings (duckdb_value_to_string returns a SQL literal in 2.0)
- Unit test fixtures: explicit +00 for TIMESTAMPTZ, core_functions is linked so the offline message lists only the missing extension
- A bare ATTACH (READ_ONLY) option lands in AttachInfo::options in 2.0, not parsed_options: read both
- A CTAS is prepared without binding its query in 2.0: report the binder/catalog error of the WITH NO DATA dry run
- Profiling: tracked_metrics with the dotted 2.0 metric names; read them from the nested metric groups
  (flapi.db.result_set_bytes is gone: 2.0 has no result-size metric)
- Settings: read s3_* through current_setting(); duckdb_settings() no longer lists extension settings,
  so a user-configured s3_region lost to the environment
- Time travel to a future timestamp is refused by DuckLake 1.1: answer 400 snapshot_in_future, not 500
- Tests: time-travel literals use a timestamp after the refresh instead of 2100-01-01
- DuckDB 2.0 starts 4 async I/O threads per core; with many short concurrent queries this cost throughput and memory
- duckdb: async_threads in flapi.yaml overrides it
- test_duckdb_defaults covers both
- 0 when nothing is remote: the async pool cost ~25% throughput and ~3x memory on local data
- 2x the worker threads when a connection, template.path, the config or DuckLake names object storage or http(s):
  uncached remote reads are 2-3x faster than on 1.5 with the pool
- duckdb: async_threads always wins; test_duckdb_defaults covers all four cases
- Crow never set it, so every keep-alive response after the first waited ~40 ms for Nagle + delayed ACK
- Accepted sockets inherit it from the listener (Linux, macOS); Windows keeps the old behaviour
- test_http_keepalive_latency: median keep-alive request under 20 ms (red on the previous binary)
…lse (#241)

- A short page (fewer rows than the limit, not empty past the end) and an unpaged result give total_count
  themselves: no second COUNT query; when it runs, it reuses the page query's connection
- MCP tool calls never count (the tool result carries only the rows)
- total-count: false on an endpoint: no total_count / X-Total-Count, never a COUNT; next comes from reading
  one row past the page; OpenAPI drops the field for it
- test_pagination_count: exact totals and next for full, short, exactly-full, past-the-end and limit 0 pages,
  DuckDB query count per request from the trace (red on the previous binary)
- Docs: CONFIG_REFERENCE, rest-endpoints guide, flapi-rest skill
- REST JSON (paged and bare), CSV and MCP tool results append each converted row to their output through a
  ResultSink instead of building a JSON tree of the whole result and copying it (3 deep copies + 2 text copies)
- Internal callers keep QueryResult::data; the tree path moves rows instead of copying them
- Bodies are byte-identical to before (JSON, CSV, a 200k-row response compared against the 1.5.5 build)
- 200k-row (8.7 MB) response: peak RSS 638 MB -> 261 MB
- test_large_response_memory: peak growth bound (red on the previous binary) and JSON/paged/CSV/MCP agreement
…est telemetry (#241)

- UsableCpus(): CPU affinity mask and cgroup v2 cpu.max quota, not every host CPU
- DuckDB threads, the Crow handler pool and the async_threads default follow it (configured values win)
  A/B on 8 pinned CPUs: equal or better throughput (paged up to 2x), 20-50% less peak memory, 31 vs 79 threads
- DuckDB jemalloc: one arena per 6 usable CPUs (DUCKDB_JE_MALLOC_CONF set before DuckDB starts, an operator's
  own value wins). On 24 CPUs: 4 arenas matched or beat the default throughput with 30-45% less memory
- Telemetry: rest_endpoint_served, mcp_tool_called and auth_enforced are aggregated per key and emitted every
  60 s (and on flush) with count, mean and max duration, instead of one buffered event per request
- Tests: threads follow a 2-CPU affinity mask (red on the previous binary); telemetry aggregation unit test
- Statically linked extensions (core_functions, parquet, json, icu) are never INSTALLed, LOADed or packed:
  first start on an empty host 1.8 s -> 0.1 s, flapi pack --with-extensions 123 MB smaller
- TCP_NODELAY as soon as the listener exists and on sockets accepted before it: connections opened at bind
  time (load balancer pools, health checks) paid ~41 ms per response for their lifetime
- Caches with warmup never/if-empty whose table exists are ready synchronously after a restart: no burst of
  503 cache_warming (median 162 -> 0)
- test_startup_resources.py (6 tests, red on the previous binary); docs and skills updated
- Rows are written straight from DuckDB vectors into the JSON text (fallback to the per-row converter for
  DECIMAL, nested types, JSON, special doubles): a 10.6 MB response 275 -> 95 ms CPU
- Per-thread DuckDB connection reuse with an LRU of 64 prepared SELECTs; a non-SELECT, an unpreparable
  statement or profiling retires the connection; FLAPI_NO_CONNECTION_REUSE=1 opts out.
  SELECT 1 endpoint at 8 clients 8.5k -> 18.6k req/s
- Template env variables read from environ through the whitelist instead of copying the environment per request
- Crow stream_threshold raised: bodies over 1 MiB went through Crow's synchronous path, which reset the next
  request on the same keep-alive connection
- test_request_path_cpu_241: exact rows, duplicate columns, CSV, two large bodies on one socket (red before),
  template edits, no session state leaking between requests, no stale plans after file/schema changes
- test_realistic_differential: 362 requests over a realistic project (parquet, CSV, DuckDB file, DuckLake cache,
  auth, nested types) byte-compared with the previous build, plus 48 parallel clients during cache refreshes
  compared with serial responses; known older bugs are strict xfails
- test_realistic_soak (FLAPI_SOAK=1): mixed load with refresh, gc, MCP and config reads; no 5xx, no mismatches,
  bounded RSS, stable fds/threads, clean SIGTERM. A 10-minute run: 102k requests, 0 errors
- Note: nested STRUCT/MAP key order in a row is unspecified (hash order) and can differ from the previous build
… limits (#241)

- ENUM: the dictionary index is read with its real width (UTINYINT/USMALLINT/UINTEGER), not as idx_t;
  one GET on an ENUM column could crash the server
- NULL DATE, TIME, INTERVAL and ENUM render as null; they printed the slot's leftover bytes
  (1970-01-01 or random dates like -4943794-02-21, different per request)
- INTERVAL renders as DuckDB's text (3 days 04:00:00), in JSON, CSV, MCP and Arrow; it printed
  months:days.millis. Arrow served no INTERVAL column at all (500)
- Arrow: the memory cap counts what the stream holds instead of 100 bytes per row, which failed every
  result over ~2.7M rows; an explicit ?limit= / ?offset= pages the stream, without them it stays the full result
- The realistic suite's strict xfails for these are now regular tests; test_value_rendering covers interval
  text, a 3M-row Arrow stream and Arrow paging
- Overlay port moved from 1.2.0 to 1.3.4, flAPI's connection-keepalive patch rebased
- Native tcp_nodelay(true) replaces the listener socket scan (also covers Windows)
- Adapt to 1.3: request::io_context, size_t routing indices, const-ref log handler
- 1.3 logs a bind failure and returns from run(): flapi now reports 'the server could not start' and
  exits non-zero when the listener never came up (the startup-failure tests caught this)
- Fixes doubles in exponent form (1e300 printed as 1000.0 by 1.2's JSON writer); test added
- ports/README.md documents the overlay
#241)

- CHANGELOG Unreleased: what changed, measured against v26.11.21, and the upgrade notes (2.0-only new files,
  per-version extension directory, DuckDB 2.0 SQL changes, Arrow paging, INTERVAL text, removed profiling attribute)
- CONFIG_REFERENCE: DuckDB 2.0.1, built-in extensions, threads/async_threads/allocator defaults,
  FLAPI_NO_CONNECTION_REUSE and DUCKDB_JE_MALLOC_CONF
- CLAUDE.md: DuckDB 2.0.1
- A lock-contention retry after rows had streamed appended the page a second time (invalid JSON, CSV header
  twice): the ResultSink is reset at the start of every attempt
- Closing the database disconnects every idle pooled connection (a pooled connection kept the DuckDB instance
  and its db_path open until the thread's next query, or until exit()); a busy one is dropped when its
  executor ends
- Telemetry aggregated after the SIGTERM flush is flushed at the end of main
- test_reuse_after_refresh: reused connections and cached plans see an incremental (MERGE) and a full refresh
- macOS: posthog-telemetry keeps OpenSSL's certificate store (httplib 0.53 would need -framework Security)
- CLAUDE.md is a symlink to AGENTS.md again (the version edit had replaced it with a copy); stray r2.log removed
- Docs: Readme DuckDB version, connection reuse in OBSERVABILITY / query-execution, built-in extensions in the
  CLI reference and the deploy skill; test nits
…he runtime image (#241)

- The integration job downloads the v26.11.21 linux-amd64 release and sets FLAPI_OLD_BINARY /
  FLAPI_REFERENCE_BINARY, so the upgrade test and the byte-for-byte differential run on every PR
- Job timeout 30 -> 45 min (it was below the 35-minute test step)
- -runtime image: bigquery@community is best effort (not published for DuckDB 2.0.1 yet), the built-in
  core_functions/json/parquet are no longer installed; docs, skill and upgrade note updated
- Disconnecting other threads' idle pooled connections when the database closed raced with a task thread's
  thread-local teardown after the database was closed and corrupted the heap (SIGABRT on SIGTERM with an MCP
  task in flight: test_graceful_shutdown, about 1 in 3 runs)
- Back to the generation counter: each thread drops its pooled connection the next time it builds or ends an
  executor; the handler pool and the task manager are joined before the database closes
- Reproduced 3/8 before, 0/8 after (with and without connection reuse)
…process

- Linux carries a process's peak RSS across exec, so flapi forked straight from a large pytest process
  reported pytest's own peak (645 MiB late in a full run) and the test failed only in full runs
- A fresh helper process starts flapi's peak from a small address space (red under a 700 MiB parent before,
  green after)
jrosskopf added a commit that referenced this pull request Nov 22, 2026
…kLake 1.1 (#241)

- make check-skills expected 200 (1.5 read the newest snapshot)
- DuckLake 1.1 refuses it; flAPI maps that to 400 snapshot_in_future
@jrosskopf
jrosskopf merged commit 00d324e into main Nov 23, 2026
25 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.

Upgrade DuckDB 1.5.5 -> 2.0.1

1 participant