Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.

9 downloads

dbbasic-object-server/scripts/bench/experiments/profile_requests_results.md
Install on DigitalOcean Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-server.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-server.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-server.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

Daniel Quellhorst Changelog for this batch. 65ef78d 3 hours, 41 minutes ago History
profile_requests_results.md · 18.5 KB · 142 lines

Where the time goes, per request type (measured with profile_requests.py)

Measurement only. Nothing in the server was edited; the script monkeypatches its own process and lives in temp dirs. Reproduce: .venv-jit/bin/python scripts/bench/experiments/profile_requests.py --compare 10,1000 --budget 1.0 --out r.txt --json r.json (--whatif --users N, --micro for the follow-up experiments; --from-json re-prints a saved run).

Setup

  • In-process through the real ASGI app (persistent event loop, no HTTP server), signed-in NON-admin user via Bearer session token, enforcement ON.
  • 57 packages installed in dependency order (every package under packages/ except admin-write-probe and hello-world; all installed cleanly): 102 schemas, 246 permission rules, ~160 objects.

Seeded per user: 3 sessions, 2 projects, 3 project grants, 10 notes, 2 orders x 3 lines, 1 invoice x 2 lines, 3 contacts, 3 tasks.

  • Flags: DBBASIC_ENABLE_EVENT_HANDLERS=true (HANDLES objects), DBBASIC_ENABLE_RECORD_EVENTS=true (durable event log, default on), realtime on (default, no subscribers), site routes on. The event log is prefilled to its 1000-row retention cap so a publish pays the steady-state price.
  • Fan-out proven to run, not assumed: an order-line create moved the order total 3000 -> 4000 (system_order_totals fired); a payment with a negative amount was rejected 400 by the schema-wired hook_payments; a payment create re-triggered the invoice rollup (payments_received_cents = 1); a payment create executes 6 objects (the hook + 5 HANDLES handlers: books, gift_card_issue, invoice_status, record_conversion, shop_fulfillment).
  • Every response is checked for status AND body shape on every repetition (e.g. list must return exactly 20 rows and no foreign rows; the page must carry VIEW_ID='view_notes' and this viewer's id; search must have notes hits). No request in the tables below is an error path. Zero checks failed.
  • Method per request: (a) bare wall time, nothing patched (best / median of N, N = 5..100 sized to a time budget); (b) perf_counter exclusive-time wrappers around ~50 functions (+ audit hook for file opens) for the stage breakdown, 1.04-1.10x wrapper overhead; (c) cProfile with the wrappers switched off (inflates call-heavy code 2.3-6x, so it is used for call counts and for cross-checking the wrapper numbers, not for percentages).
  • Noise: shared machine (another agent was running tests). Two independent 10-user runs agreed within ~3% (list 10.6 / 10.2 ms, asset 41.9 / 40.9 ms, payment create 41.9 / 40.6 ms). At 1000 users the slowest cases got only n = 5 repetitions (list, anon rows, search), their best-vs-median spread was < 4%.

Finding about the existing bench

scripts/bench/multiuser.py create_note POSTs {"content": "bench note"} with no owner_id. With enforcement on that is 403 "no matching role rule" (the permission check runs on the submitted record BEFORE the server stamps owner_id; the generated form always sends owner_id). oha reports latency for 403s, so that bench's create number is a refusal path. This script sends owner_id like the form does.

Wall time per request, bare (median ms; best within 5% everywhere)

request10 users1000 usersgrowth
floor: GET /health0.060.061x
1 list notes limit=2010.2375.637x
2 get one note2.33.11.3x
3 create note16.238.62.4x
4 update note20.144.32.2x
4 delete note17.440.82.3x
5 order line create (HANDLES order_totals)37.393.22.5x
5 order line update41.998.12.3x
5 order line delete30.366.42.2x
5b payment create (hook + rollup + 5 handlers)40.650.51.2x
5b payment update32.844.41.4x
5b payment delete20.628.71.4x
5c contact create (computed full_name)16.628.51.7x
6 page GET /notes (signed in, HTML)93.494.81.0x
7 search q=note34510923.2x
8 GET /api/schema/notes0.150.151x
8 GET views/view_notes2.53.11.2x
8 GET notes?limit=500 (the list block's own fetch)10.3364.735x
8 GET projects?limit=500 (relation labels)3.476.522x
8 GET /objects/action_nav_entries4.76.41.4x
8 GET views?limit=2007.07.81.1x
8 GET entities?limit=200 / notifications?limit=50 / prefs2.4 / 2.4 / 1.13.2 / 3.1 / 1.8~1.3x
8 nine page assets (/style /markdown /list /form /detail /thread /attachments /share /nav), each39.5-40.941.6-42.31.0x
9 anonymous public page /notes92.691.71.0x
9 anonymous public rows (3 rows returned)5.3347.666x

Opening /notes in a browser = HTML + 9 assets + 9 data calls (read from the served HTML/JS, not by running a browser): 486 ms of server time at 10 users, 938 ms at 1000 (assets alone 358 / 376 ms; assets send no Cache-Control/ETag/Last-Modified and no conditional-request handling, so each page view re-executes them; that last bit is inferred browser behaviour).

Ranked hot spots (all requests)

Percentages are shares of the request as measured with the wrappers; "what-if" numbers are MEASURED with the cheapest plausible patch monkeypatched into the profiling process (response bytes identical to baseline for 8 read requests).

#hot spotevidencekindwhat fixing savesrisk
1A schema-less collection name makes get_schema run object_collections.list_collections(): a full object scan (rglob 160 files, one get_object_state read per object, log probing, policy parse) = 35.7 ms per occurrence. Hit by _site_host_records() on EVERY site-route request (collection site_hosts has no schema and no records), by site_routes on pages, and 7x per search (object categories action hook site system triggers webhook + site_routes returned by list_schemas).asset: 160 get_object_state calls, 38+29+20% of 42 ms; page 3 dir scans; search 8 list_collections; micro: read_collection_records('site_hosts') 35.6 ms vs 0.25 ms for a collection that has a schemaalgorithmic (repeated full scan to answer "does this collection exist")assets 42 -> 4.3 ms (-90%), page 94 -> 24 ms (-75%), page bundle ~ -80% of the fixed part, search 345 -> 188 ms (10u, with #2)site_hosts short-circuit is exact (low); a general negative/derived-schema cache is moderate (collection "known-ness" also comes from objects and permission rules)
2iter_object_sources = rglob("*.py") + sort + per-file resolve on every call: 15.8 ms. Used by list_collections (#1) and by resolve_object_id on a MISS: the convention probe site_notes for /notes misses and scans, so every page routed through the site_routes table (/notes, /orders/{id}, /views/{id}...) pays itpage: 3 scans = 47 of 98 ms; asset 1 scan = 37%algorithmic (no cache; result depends only on which files exist)with #1 fixed: page 89 -> 42 ms by itself, search -40%low (invalidate on directory mtimes)
3_rollup_parents_for_source runs on EVERY write and calls get_schema for all 102 schemas to find rollup parents7.7 ms/call micro; 8.2-8.6 ms incl per plain write (46% of a 10-user note create, 20% at 1000u); 3 invocations in an order-line write (24.6 ms, 61%)algorithmic (O(#schemas) per write, answer changes only when a schema changes)~7.7 ms of every write alone; after #4 only 0.3-2.4 ms remainslow (memo keyed by schemas-dir mtime)
4get_schema costs 71 us even on a cache hit (4 Path.resolve() + 3 stats for a path-safety check on an already-validated name; a hit could be 1 stat = 5 us)49 calls per list (34% of a 10-user list), 115-127 per plain write (43-50%), 224-346 per order-line/payment write (up to 62%), 54 per views list (53%); per-visible-row redaction calls it per row, which is why _redact_records_for_permission costs ~110 us/row of which only ~35 is check_permissionrepeated workmeasured: list 10.4 -> 6.7 ms (-36%), note create 16.3 -> 8.2 (-50%), order-line create 38 -> 14.5 (-62%), views list -55%, payment create -44%low
5check_permission once per row of the whole collection (known #1): 36 us/call, 87% of it the rule scan (24.7 us with 246 rules vs 3.3 us narrowed to the 3 relevant ones)list 1000u: 10,044 calls = 94% (367 ms); anon public rows 94%; load notes?limit=500 94%; projects labels 88%; search 21,136 calls = 66% (762 ms); 10u list 42%algorithmic O(rows x rules)330+ ms of 375 at 1000u, grows linearly with rows; narrowing rules alone ~ -85% of the engine costmedium-high (permission semantics; another agent is editing the engine)
6load_policy re-parses policy.json and rebuilds 246 rules per call, 1-3 calls per request0.98 ms/call; get_note 41%, view record 41%, nav bell/entities 38-40% of 10-user requests; 3 calls in an update, 3 on a pagemissing cachemeasured: get_note 1.89 -> 0.84 ms (-55% on top of #4); every request -0.9..-3 mslow (stat-keyed; frozen dataclass)
7Identity resolved 2-5x per request, each = 3 read_collection_records (project_access, projects, record_shares: every call copies all rows, and record_shares is a collection with a schema but no records file) plus a session lookup0.8 ms (10u) -> 1.7 ms (1000u) per resolution; get_note 30% -> 49%; updates 3.3 / 6.7 ms (14-15%), payment update 9.7 ms (20% at 1000u)repeated work + O(users)2-8 ms per write at 1000u, grows with users (about +0.9 us per user per resolution); get_note ~ -45%low-medium (per-request memo; must not outlive a grant change)
8Classic-mode persist_write rewrites the whole TSVnotes 725 KB: 21 ms = 51% of a create at 1000u; order-line create 54 ms (3 rewrites: line, order via the handler, ...) = 54%; contacts 11 msO(file size), inherent to classic mode~20 ms per write at 1000u (-50%), grows with rows; append mode already existsoperational (storage migration), code risk low
9Durable event log publish rewrites a 1000-row file per writemicro: 0.4 ms at 0 rows, 0.67 at 100, 1.76 at 500, 3.07 at 1000 (306 KiB file); 16% of a 10-user note create, 7% at 1000u; in every writeO(log size) up to the retention cap~2.5 ms per writemedium (daemon/pollers read this file)
10Objects are re-imported on every execution (_load_module: read + compile + exec), 0.8-0.95 ms each, and each execution also appends an execution log under a flockpayment create runs 6 objects = 4.4 ms (10%) + their log appends; nav entries 17%; page 0.8 ms; compile SyntaxWarning re-emitted per loadmissing mtime-keyed module cache~4 ms per payment writemedium (objects may rely on fresh module state)
11Search shape: reads and row-filters every searchable collection (55 collection reads, ~21k permission checks at 1000u) + 8 full scans (#1)1.09 s at 1000u, 345 ms at 10u (75% of it #1/#2 + get_schema)algorithmiccovered by #1, #2, #5-
12Permission audit log: one audit.jsonl append per permission check (1 per request, 55 per search), never rotatedopen-audit shows W permissions/audit.jsonl x1 on every requestunbounded growth (disk), time cost smalln/a (not time)low

Not hot (measured): session lookup (cached) 0.06 ms = 0.6% of a list, 1-5% of the cheap calls; change-log latest lookup 0.2 ms (+0.2 ms with 50,000 prior entries per collection, so the tail read really is O(1)); schema validation, computed fields, transition checks, realtime publish (no subscribers) all < 1% each; the ASGI/driver floor is 0.06 ms; routing's long if-chain is inside the "other" 1-3%.

What-if (cumulative patches, median ms bare, --whatif)

10 users: list 10.4 -> 5.7, get 2.3 -> 0.86, note create 16.3 -> 7.5, update 20.0 -> 8.8, order-line create 38.3 -> 12.0, update 43.4 -> 13.4, payment create 41.0 -> 20.4, page 94.2 -> 22.5, asset 40.4 -> 2.7, search 347 -> 188, views list 7.0 -> 2.1, anon rows 5.3 -> 3.8. 1000 users: list 357 -> 351 (only #5 matters), note create 38.3 -> 29.1 (the rest is #8), order-line create 93.9 -> 66.3, payment create 51.0 -> 30.2, page 96.2 -> 24.3, asset 42.3 -> 4.3, search 1072 -> 914, anon rows 337 -> 335. (c1 get_schema cache, c2 load_policy cache, c3 rollup-parents memo, c4 object-sources cache, c5 site_hosts short-circuit.) The order-line delete row is noisy (14.6 -> 17.2 at c4/c5 at 10u): single-run medians on a shared machine.

Which stages scale with data or users (10 -> 1000 users)

  • check_permission calls per list: 143 -> 10,044 (O(rows); the row count also drives list.row filter, compute_record_rev stays at 20 = the window).
  • persist_write: 0.6 -> 21 ms per notes write (O(file)); 1.7 -> 54 ms per order-line create.
  • identity scans (project_access / projects / record_shares): 0.016 -> 0.26 ms per resolution on top of 0.7 ms constant (3 cached reads that each copy their rows).
  • read_collection_records: 0.6 -> 2.2 ms per list (it copies every row of every collection it reads, also on a cache hit).
  • Constant in users (but large): get_schema calls, load_policy, event-log publish, rollup-parent scans, object loads, iter_object_sources, get_object_state x160.

Per-request counts (calls per request, 10u / 1000u where they differ)

requestread_collection_recordscheck_permissionidentity resolutionsload_policyget_schemajson.loadsos.statfile opens R/Wobject loads
list notes4143 / 100441149 / 5011651 / 10
get note311161341 / 10
note create612112010044024 / 50
note update1234312710064496 / 60
note delete923211510043985 / 50
order-line create712133910041110-1
payment create2513126810371033-6
page /notes912311311306 / 51 (+ 319 get_object_state, 3 dir scans)
asset /style7122925884 / 31 (+ 160 get_object_state, 1 dir scan)
search55346 / 2113619324956939 / 550 (+ 1272 get_object_state, 8 dir scans)
anon public rows1104 / 100041161251 / 10

(Writes parse ~1000 JSON values because load_policy and the event/state files are JSON/TSV parsed per request; a plain write opens 4-6 files for read and 5-6 for write/append: collection file + lock + tmp, change log read + append, event-state, audit log.)

Measured vs inferred, and what did not work

  • Measured: everything in the tables, the micro and what-if numbers. Stage percentages come from perf_counter wrappers (cProfile agreed on ordering everywhere I compared; it is reported in the raw output only for call counts).
  • Inferred: browser behaviour (the page's call list comes from reading the served HTML/JS, not from running it; /ws, realtime subscription and any call made only after user interaction are not included; /api/flags is not requested by the loaded scripts); that missing cache headers make browsers refetch the assets; the 10k-user extrapolations (linear scaling of the O(rows)/O(users) terms was observed between 10 and 1000, not tested beyond).
  • Did not run / not covered: real HTTP and TLS, concurrency (everything single-threaded), the daemon passes, analytics (off by default), packages' schemas other than the ones driven. DBBASIC_OBJECT_TIMEOUT_SECONDS is unset (in-process objects). Event-handler dispatch was verified for order lines and payments only; invoice-line writes were not driven.
  • Everything installed; no package failed. No handler failed to fire. The one surprise was the 403 on creates without owner_id (above), found while building the harness.

After (2026-11-29, at 0d564b2)

Same script, same 57 packages and seed, --budget 1.0 --no-cprofile, one subprocess per size (--users 10 and --users 1000, then --from-json to combine; --compare needs .venv-jit inside the checkout). Median ms, bare wall time; "before" is the table above (c145348). Every response was status- and shape-checked as before.

requestbefore 10uafter 10ubefore 1000uafter 1000u
1 list notes limit=2010.26.1375.6403.4
2 get one note2.30.633.10.65
3 create note16.26.138.626.9
4 update note20.16.844.328.2
4 delete note17.46.340.827.6
5 order line create37.310.793.267.5
5 order line update41.912.398.168.3
5 order line delete30.312.866.445.9
5b payment create40.618.850.527.7
5c contact create16.66.928.516.9
6 page GET /notes (signed in)93.43.094.82.9
7 search q=note34526.71092859
8 GET views?limit=2007.02.27.82.4
8 GET projects?limit=5003.41.3576.579.4
8 page asset, each (9 per page)39.5-40.91.65-2.541.6-42.31.6-2.8
9 anonymous public page /notes92.62.691.72.3
9 anonymous public rows5.34.2347.6371.7
/notes page load (html + 9 assets + 9 data calls)48633.4938507
  • What is left is the two O(data) items that were not touched: check_permission once per row of the whole collection (#5: still 95% of a 1000-user list, of the notes?limit=500 and projects?limit=500 loads and of anonymous rows, and most of search), and classic-mode persist_write rewriting the whole TSV (#8: 21 ms of a 1000-user note write, 75%). The 1000-user list / anon-rows medians are within this shared machine's run-to-run noise of before.
  • Payment update and delete are no longer measured: hook_payments now refuses both (409 "money moves, it does not mutate"), a package change made on this branch by other work, so those rows have no after number.
  • One identity resolution, session lookup included, is now 0.33 ms at 10 users and 0.31 ms at 1000 (it was 0.8 -> 1.7 ms and grew with users), measured with the stage wrappers.
  • Page assets are 1.6-2.8 ms each because the full object scan per request (#1, #2) is gone; they still send no cache headers and run their object every time, deliberately. An ETag/304 would save bytes but none of this time (the object must run to know the body). A freshness lifetime (Cache-Control: max-age) would stop the re-execution but would keep serving an old /style after a theme switch and old /list after a package upgrade, the stale-script failure _html_cache_headers was written for, and objects cannot set cache headers themselves by design (_object_set_cookie_headers). A server-side cache of object output is not provably correct: an object's output may depend on its state, records, the viewer and the clock, and the platform cannot see which.