Repository navigation
perf(db): Raise the Neon pool to 10 connections - #2712
Merged
Merged
Conversation
One function instance serves many concurrent requests that share the pool. On a conversation page load, the conversation list held all three connections for seconds, so the detail, agents, spend, and Review item requests on the same instance waited for a free connection. Co-Authored-By: Thomas Jiang <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
8 screenshot changes — 8 changed · 0 added · 0 removed Review screenshots in Frameshift |
thomasjiangcy
approved these changes
Nov 5, 2026
thomasjiangcy
added a commit
that referenced
this pull request
Nov 5, 2026
…2716) When a conversation opens with no cached copy, the transcript waits for two requests in a row: `/pending-messages`, then `/api/conversations/:id`. #1932 added this order on purpose. Workers commit input before they acknowledge it, so reading the mailbox first means a message that moves into history between the two reads still appears in one of them. In prod traces, the detail request started only after the mailbox request returned: - [`3cffecfa…`](https://sentry.sentry.io/explore/traces/trace/3cffecfa6ae6460f8677a8fc57ea128e/) (navigation): mailbox 47→383ms, then detail from 385ms. - [`0d26d374…`](https://sentry.sentry.io/explore/traces/trace/0d26d3741d5d477793c326ccfbed4f4b/) (pageload): mailbox 713→856ms, then detail from 861ms. - [`19019d5f…`](https://sentry.sentry.io/explore/traces/trace/19019d5f769341a2916e865e93267baa/) and [`40a68dfc…`](https://sentry.sentry.io/explore/traces/trace/40a68dfc3ed248dca589f837bd109bb8/): the mailbox took 0.86s and 1.8s in the browser, and the detail waited for it. Change: - `GET /api/conversations/:id?mailbox=true` reads the mailbox first and then history, in one request. It returns the `/pending-messages` report as `mailbox`. A request with `mailbox=true` never returns 304. - The client uses it only for a first read with no cached copy. Polls and cached reopens keep the two reads, so the detail can still return 304 (#2655). - The mock reporting API and its hash-based 304 middleware support the flag. A shared e2e helper, `withRequestedMailbox`, adds the mailbox to mocked detail reports. Expected impact (inference): opening a conversation saves one round trip plus the server's mailbox read, about 150–350ms in typical traces and up to about 1.8s in the slow ones. Polling cost does not change. Checks: `pnpm typecheck` (junior, junior-dashboard), oxlint, prettier, `file-length:check`, junior `pending-messages` and `detail` integration tests, dashboard vitest, and the whole dashboard Playwright suite (87 passed). `tests/dashboard-output.test.ts` fails in my sandbox on `main` too, during its Nitro build, so it is not related to this change. Overlaps: #2657, #2676, #2677, #2678, and #2428 change the conversation page UI. This PR changes only `queries.ts` data loading and the detail route, so I expect few conflicts. #2657 (catch up on unread activity) may touch the same detail options. This branch is based on `main`. #2712 (Neon pool size) is independent, and it fixes most of the server-side wait in the slow traces. <!-- junior-request-attribution:start --> via @thomasjiangcy. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A34a570431e2cdbd57aba2d8c15a0c1ac --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A34a570431e2cdbd57aba2d8c15a0c1ac) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A34a570431e2cdbd57aba2d8c15a0c1ac/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Thomas Jiang <[email protected]>
This branch was successfully deployed
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.
On slow dashboard conversation loads, the fast requests spend most of their time waiting for a database connection. The pool allows 3 connections per function instance, and Fluid compute routes many concurrent requests to one instance.
Evidence (prod traces, grouped by
service.instance.id):19019d5f…: instancef44614ffservedGET /api/conversations(the list) and also detail, agents, spend, and Review items. The list ran 3 queries at once for 1.3–5.5s. Detail (1.8s), agents (1.8s), spend (1.7s), andreview-items(1.8s) did their first query only after a list query finished. Detail's own queries total about 0.15s.40a68dfc…: instancee5f5d1ed, same pattern. Detail took 4.27s. It had two gaps with no spans (1.5s and 2.0s). In both gaps, the list's queries held all 3 connections. Detail's own queries took about 0.4s.The list and memory queries are still slow. Separate PRs fix those (#2713 for memory). This change stops one slow request from blocking every other request on the same instance. 10 leaves room for the list (up to 3–4 connections at once), the detail fan-out, and memory reads.
Notes for review:
-poolerendpoint, which accepts many client connections. A direct (non-pooler) Neon URL with many instances uses more server connections. Thepostgresdriver stays at 3, because a direct Postgres server has a lowermax_connections.via @thomasjiangcy.
--
View Session [Sentry]