N
Neon15mo ago
other-emerald

Connection issue on first couple of request

Hello There, I’m currently using the free tier for testing purposes on one of my PoC projects, and I've encountered a significant issue. Whenever there’s no interaction with the database for an extended period, my application experiences a connection issue on the first request. Below are the details of the stack I’m using: 1. Python - 3.12
2. FastAPI - 0.111.0
3. SQLAlchemy - 2.0.31
4. asyncpg - 0.29.0
5. Alembic - 1.13.2 Could you please provide a solution for this as soon as possible?
3 Replies
deep-jade
deep-jade15mo ago
Hi Sinbad - the key is to configure your connection to refresh or recycle within 5 minutes, in order to play nicely with the autosuspend feature. Here is one python example: https://arc.net/l/quote/nojcaewr
other-emerald
other-emeraldOP15mo ago
Thank you for your previous response; it worked perfectly. I made some changes and collected the following response time data for our application: Suspend compute: Aug 19, 2024, 11:38 am Start compute: Aug 19, 2024, 11:39 am Response Time: 10.40s Suspend compute: Aug 19, 2024, 11:44 am Start compute: Aug 19, 2024, 11:46 am Response Time: 7.86s Suspend compute: Aug 19, 2024, 11:51 am Start compute: Aug 19, 2024, 12:11 pm Response Time: 6.26s Suspend compute: Aug 19, 2024, 12:16 pm Start compute: Aug 19, 2024, 12:56 pm Response Time: 7.89s Suspend compute: Aug 19, 2024, 1:01 pm Start compute: Aug 19, 2024, 2:16 pm Response Time: 7.30s Suspend compute: Aug 19, 2024, 2:21 pm Start compute: Aug 19, 2024, 4:56 pm Response Time: 8.35s Suspend compute: Aug 19, 2024, 5:01 pm Start compute: Aug 19, 2024, 6:09 pm Response Time: 7.08s As you can see, the response times are quite high. I would greatly appreciate any insights or suggestions on how we might address this issue to improve performance. Thank you for your assistance!
deep-jade
deep-jade15mo ago
hm - what are these logs from? Is there a code snippet you can share? The p50 cold start time (when a suspended db first gets a query, turns on, responds to query) is ~400ms https://neon-latency-benchmarks.vercel.app/
Neon Latency Benchmarks
An open-source tool for understanding and benchmarking the connect, query and cold start timing of Neon projects.

Did you find this page helpful?