Repository navigation
Follow-ups: count cache, less per-request work, stripped binaries, extensions in releases - #247
Merged
Merged
Conversation
- 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
- New CMake option FLAPI_STRIP_BINARY (default OFF, so local builds keep their symbols): links flapi with --strip-all on Linux (122 MB -> 102 MB on amd64) and ld64 -x (local symbols) on macOS; MSVC executables carry no symbol table - Only the static symbol table goes: .dynsym from ENABLE_EXPORTS (77274 exported symbols, unchanged) is what loadable extensions resolve against; ducklake, postgres, sqlite, fts and httpfs load from the stripped binary - At link time rather than a later strip: on macOS a post-link strip breaks the linker's ad-hoc signature and flapi pack re-signs only after writing its segment - CI turns it on in the Linux and macOS builds, so every job tests the binary that ships; the release job's post-build strip is gone (it skipped the arm64 and macOS binaries silently and left the Docker image unstripped)
- An extensions/<duckdb version>/<platform>/ directory beside the real executable (symlinks resolved; also the wheel's flapi_io/bin layout) is found at startup and added to DuckDB's extension_directories AFTER the user directory: DuckDB installs into the first directory, so the shipped one is only ever read, other extensions still install into ~/.duckdb/extensions, and a deliberate FORCE INSTALL there wins - duckdb.extension_directory, FLAPI_EXTENSION_DIRECTORY and a packed bundle's directory still replace it (no double load); a shipped directory for another DuckDB version or platform is ignored with one warning naming what it holds - Startup LOADs each default extension and INSTALLs only on failure (INSTALL checks the first directory only and would download a shipped extension again); same for httpfs/azure on the bootstrap and credential paths - flapi extensions install --defaults installs the default set; shipped extensions are copied into --dir instead of downloaded, so pack --with-extensions works offline - Integration tests (real binary in a release layout, empty HOME, dead proxy, unshare -rn where available): every default loads online and offline, via symlink and wheel layout, explicit directories win, version mismatch ignored, a non-shipped extension installs into HOME only, install copies; unit tests for lookup and the SET statement quoting
…nsions (#245) - New jobs shipped-extensions-linux (amd64 and arm64 on native runners; the arm64 binary is cross-built) and shipped-extensions-desktop (macOS, Windows): each binary runs flapi extensions install --defaults into extensions/ beside itself, then scripts/check_shipped_extensions.py proves every extension loads from there with an empty HOME, offline, through a dead proxy; the directory is uploaded as an artifact - create-release puts extensions/ into the four archives and, via scripts/wheel_add_tree.py (adds files, rewrites RECORD), into the wheels at flapi_io/bin/extensions; a wheel above PYPI_WHEEL_LIMIT_MB (repo variable, default 100 = PyPI's default limit) is published without them and warns instead of failing the release - Dockerfile copies the binary's directory (binary + extensions) to /app; the default image now has the extensions, -runtime adds bigquery to /app/extensions and drops FLAPI_EXTENSION_DIRECTORY; both images must start with --network none and load every default extension - make docker fills the extensions with the host binary
) - CONFIG_REFERENCE 2.4: where extensions come from (config > env > bundle > shipped after the user directory), read-only shipped directory, user copy wins, version mismatch ignored, offline with the shipped directory alone - CLI_REFERENCE: extensions install --defaults, copying from the shipped directory, FLAPI_STRIP_BINARY - Serverless guide and flapi-deploy skill: release images and archives start without downloads; -runtime moved to /app/extensions - DESIGN_DECISIONS 13 records the decisions on the design issue's open questions; CHANGELOG Unreleased with upgrade notes
- Drop the wheel extension packaging and the PYPI_WHEEL_LIMIT_MB fallback from create-release, and scripts/wheel_add_tree.py: with the extensions a wheel would be ~155 MB, above PyPI's 100 MB file limit - Only the release archives and the Docker images carry extensions/; a pip-installed flapi downloads them on first start, as before (the binary's lookup next to the executable simply finds nothing there) - CHANGELOG, CONFIG_REFERENCE, serverless guide, flapi-deploy skill and DESIGN_DECISIONS 13 say so and why
- The rate limiter, the auth middleware and the handler each scanned every endpoint for the request's route; the first lookup now records the answer in the RequestContext and the others reuse it (one scan instead of three), so all three also judge the same endpoint if a reload lands mid-request - Local SQL templates are cached by path and revalidated with one stat (device, inode, size, mtime, ctime) instead of re-read per request (four stats, open, read, two copies); an edit is still served by the next request, a deleted template still fails; bundles and remote templates are unchanged - The secret collector walks the whitelisted environment variables directly instead of copying the whole environment (the template context already did); SQLTemplateProcessor::getEnvironmentVariables is gone - test_request_path_cpu_243.py: same-size edits, a restored mtime, delete and recreate, and route precedence across rate limit, auth and handler
…changes (#242) - A full page of a cached endpoint ran COUNT(*) over its query on every request, about as costly as the page; the count is now kept in a process-wide LRU (10,000 entries) keyed by the rendered SQL and the bound values, so time travel versions and filters are keyed by their values - Each entry is tagged with the catalog generation, the newest DuckLake snapshot id read from the metadata database before the count would run; any committed change (refresh, full rebuild, MERGE, write endpoint, a writer or one-shot refresh in another process, a replica's writer) makes a new snapshot, so a stale count is never served and replicas can use it - Eligible only when the endpoint has a cache, the SQL parses as one SELECT whose every table is <alias>.<schema>.<table> or a CTE, and every function is per duckdb_functions() non-volatile and not query-time dependent (now, current_date, getvariable, ...); judged once per rendered SQL - If the snapshot id cannot be read, counting runs every time (one warning) - test_count_cache_242.py: repeat, refresh, full rebuild, write endpoint, bound values, time travel, ineligible queries, SQLite catalog shared with a one-shot refresh and a read-only replica; count_cache_test.cpp
- caching.md: the count cache, its generation and the eligibility rule - CONFIG_REFERENCE total-count, query-execution template cache and count, REQUEST_LIFECYCLE single endpoint resolution - CHANGELOG Unreleased with the measured gains - flapi-rest and flapi-cache-tuning skills: a cached endpoint's count is reused until the next refresh
- 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)
) - Two same-size writes within one filesystem timestamp tick leave the same stat stamp; the config service template PUTs, endpoint create/update (writeFile) and every reload now clear the cache, so the next request reads what was written - Windows: stamp from GetFileAttributesEx (100 ns last-write time, creation time) instead of _stat64 (whole seconds, ctime = creation, inode 0) - test_request_path_cpu_243.py: 80 alternating same-size template PUTs through the config service, each served by the next GET - Documented the remaining gap (an external editor writing twice within one tick) in query-execution.md
…robe (#242) - age(ts) reads the transaction start although duckdb_functions() reports its TIMESTAMP overload CONSISTENT: names audited in the vendored DuckDB (age, json_serialize_plan) plus the clock/session/random names are refused by name (UnstableFunctionName), also when written without parentheses (current_date, current_timestamp parse as column references) - TABLESAMPLE on a table reference is refused like USING SAMPLE - Every <alias>.<schema>.<name> must be a TABLE per duckdb_tables(), not a DuckLake VIEW whose body may read other sources; judged per rendered SQL and generation - Count keys are length-prefixed (values containing '=' or 0x1f collided); a key over 4 KB is not cached - A failed snapshot-id probe turns the cache off for 30 s instead of for the process lifetime; off and back on are logged once each - test_count_cache_242.py: age(), bare current_timestamp, TABLESAMPLE, a DuckLake view over read_csv, colliding bound values; unit tests for the rules, key encoding and backoff
… note (#245) - make docker: install extensions with the host-arch Linux binary only; a binaries/<other arch>/flapi left by a cross build is never executed, and a non-Linux host skips the step with a message instead of installing its own platform's extensions into a Linux image - check_shipped_extensions.py: compare against the directory with a trailing separator, so extensions-old/ does not count as extensions/ - CONFIG_REFERENCE 2.4, serverless guide, flapi-setup skill: clear com.apple.quarantine on an archive unpacked after a browser download
…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)
…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
…245) - 'flapi searches' across a line break parsed as an unknown flapi subcommand
# Conflicts: # CHANGELOG.md # Dockerfile # docs/CONFIG_REFERENCE.md # docs/guides/serverless.md # plugins/flapi/skills/flapi-deploy/SKILL.md # plugins/flapi/skills/flapi-rest/SKILL.md # src/database_manager.cpp # src/extension_installer.cpp # src/include/database_manager.hpp # src/include/extension_installer.hpp # src/sql_template_processor.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #246 (DuckDB 2.0.1); will be retargeted to
mainonce #246 is merged.Summary
stat(cleared whenever flAPI writes or reloads a template), the last environment copy is gone. +11-35% req/s on small queries.FLAPI_STRIP_BINARY, on in CI): Linux 122 -> 102 MB; dynamic symbols for loadable extensions kept; macOS strips at link time soflapi packsigning still works. The old post-build strip silently skipped arm64 and macOS.duckdb.extension_directory/ a packed bundle still win), works offline, installs anything else into the user directory, ignores a directory for another DuckDB version. PyPI wheels do not carry them (PyPI's 100 MB file limit). Newflapi extensions install --defaults.Test plan
--network nonechecks; release artifacts verified with an rc tagCloses #242, #243, #244, #245
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.