db session lookup adds 41ms to every request on neon, is that normal Sessions
Server sessions, sessions table in Postgres on Neon, serverless functions. Every authenticated request does one lookup by session token.
With the lookup: p50 around 68ms. With it stubbed out: p50 around 27ms. So the session is costing me 41ms on literally every request, which is more than the rest of my handler.
Is 41ms just what a database session costs on this stack, or is my setup wrong? The table has 4,000 rows and an index on the token.
@burr_and_edge · 7mo ago · 3 replies
41ms is not the cost of a session lookup, it is the cost of your connection. A primary key read against 4,000 rows is sub-millisecond in the database. What you are measuring is almost entirely connect plus TLS plus network round trip.
In order:
After that a session lookup costs about 1ms and the debate about sessions versus tokens stops being about performance, which is where it should have been all along.
Reply
Report
@serger_seth · 7mo ago
The region mismatch is embarrassingly common because both defaults are sensible in isolation. Function defaulted to one region, database created from a laptop somewhere else, and you bought 90ms before anyone wrote any code.
Reply
Report
@rest_day_rita · 7mo ago
If you add the KV cache, remember to bust it on logout and on ban, otherwise you have carefully rebuilt the token revocation problem you chose sessions to avoid. 60 seconds is short enough that most people accept it, but decide it rather than inherit it.
Reply
Report