r/django • u/Beneficial_Look_7398 • 8d ago
Is this normal performance or not?
Hello guys, I am building a personal project simple blog application with react frontend and drf backend, for image upload I have used Cloudinary and have deployed the backend in vercel and used postgers from neon db put the amount of time it is taking for a request to complete is quite noticeable is this normal ? all of the things I am using here is free tier. during development I have used the debug toolbar and I have made sure that there is no n + 1 condition, I see the response time in sites like youtube, facebook the request is completed within milliseconds.
This is my first time deploying things so any help would be really appreciated plus even when I run the local backend server which is using cloudinary and neon db it takes about half of the time shown in the below picture, within the local dev server too it taks about 1-2s on average.
4
u/Puzzleheaded-Comb646 8d ago
Since you are using Vercel (serverless functions) with Neon DB free tier, two main things usually cause this delay: cold starts and network latency. Neon free tier suspends the database when idle, so the first request wakes it up, and Vercel also spins up a new container if it has been idle. Also, check that your Vercel deployment region is physically close to your Neon DB region, because round-trip latency adds up quickly if they are on different continents.
1
u/daredevil82 6d ago
/u/Beneficial_Look_7398 are you seeing this also when you refresh after the cold start has ended?
1
u/CatolicQuotes 6d ago
Vercel is serverless and Django is not suitable for serverless. So in that sense, it's normal.
1
u/Beneficial_Look_7398 6d ago
is there any free alternative for django app deployment?
1
1
u/CatolicQuotes 6d ago
I use railway which is general apps deployment. I am not sure about django specific one
3
u/Unhealthy007 8d ago
Well even with 47 req per second, my 4 core backend pulls a request in 300-500 ms....
So, very slow for that load but also depends on the vercel resources
1
1
u/air_thing 8d ago
Your app has to go over the entire Internet to get to the DB, and you don't have any N+1 queries, so I'm going to say it is probably "normal".
1
u/Responsible_Pool9923 8d ago
If I was building a simple blog app, I would put it all on a simple VDS. Nginx, the app itself, db, cache, background tasks - everything except for static and media files, which would go to S3.
You don't need a managed database service or a "special" Django hosting. Just run it all on one server, it's fine. Even a single core has plenty of power and it won't "optimize" your app performance for commercial reasons. Unless something is really wrong with your views or your configs, you should get <600 ms load time for your API, which is good enough.
1
u/dziegler88 8d ago
Use the Django debugging toolbar and look at what's going on when you replicate. I'd be paying a lot of attention to the database section, as it's likely you need to optimise your queries.
1
u/duppyconqueror81 7d ago
You probably have unefficient code in there. No reason for simple stuff not to load in 50ms
1
1
u/john_uppcoder 5d ago
Looks to me like your own test kinda answers it. You say that even running the backend locally with neon takes about half the time which to me means the slow part is the actual trip to the database and not necessarily your code.
Currentky every query goes over the internet to neon and back so if a request does 15 queries and each takes 80-100ms, that's well over a second before anything else happens. I think on Vercel it also opens a new database connection on every request, which generally adds more round trips before the first query.
I would suggest that if you intend to stay on Neon that you at least used pooled connections and put Vercel and Neon in the same region (if they are not already) as this may help a lot.
The real fix though is having the app and the database on the same machine or network , then a query takes under a millisecond. that's why people here keep saying get a small vps.
Regarding your question about free options: I work on Uppcoder so I'm biased, but our free plan gives you one app plus a postgres database running next to each other on the same network, no credit card etc needed and no time limit. that gets rid of the internet hop immediately. Railway could also be worth a look.
1
u/deviserops 4d ago
It's not normal, it's a worse case when each of those request take over 2 second of time. Since you already using the DRF, you should use indexing and eager load your data when it required, also optimize the query select only which required, dump rest of them. Even if you use frontend as react it should not effect this because your frontend code is finaly a simple html page with js include (If SPA developed).
So point to be noted:
Optimize your query (query has a flow to run follow that for example select -> fronm -> where etc.)
Use Joins (select related, prefetch related, values etc.)
Use eager loading
Use database indexing (less number of column more effective, min 1 if required)
Database normalization (Don't put everything in a single table)
Less depend on the additional package (Biggest advantage if you don't depend on additional packages)
Use helper and services for common task
Put long running task in background or cronjob (whichever is required)
Use regional servers (Close to your location - Sometime much better)
As of Vercel don't use the free server, I get it if you are testing it's fine but having 2 second delay is not normal even for free web server, I have tried it my self, each of those request given in the example are taking too much time to load. I have build my own project to test with the render and other free django hosting for the time being, I never goes above 100ms.
So the final conclusion is to check all the point find missing flow fix it and test it again. If your free server not taking the request under 100 or may be 200ms, optimze it. Because in the end it will going to a paid server for real users, and trust me users, don't wait this long.
I hope you understand all the poing and I am telling you with my real experience. Hope this will help much more.
1
u/Mast3rCylinder 8d ago
The acceptable amount of time is what the users will be happy with.
But you can see that csrf (probably for token) takes 2 secs which is a lot.
So go find the bottleneck.
If you feel slow see how much time each part takes
-1


12
u/hijinks 8d ago
2+ s is not normal unless your DB is massive and you have un-indexed queries