Backend is very very slow.
manishgotame
PROOP

6 months ago

Hi, My App backend is very very slow. for example, it takes over 1 sec to fetch even a simple query from the table for 4 rows. 

I am on the pro plan, I have 3 instances of the backend server, each one in Netherlands, Singapore and Virginia. My database is Postgres hosted only in Singapore. I checked my HTTP logs for my app backend and the edgeRegion is always Singapore so the DB and server are close together. Furthermore, I am using railway's internal networking for communication between the backend and the database so what am I doing wrong here?

here's my middleware and Procfile:

My Middleware:
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'allauth.account.middleware.AccountMiddleware',
]

Procfile command:

web: python manage.py migrate && gunicorn backend.wsgi

$10 Bounty

5 Replies

Railway
BOT

6 months ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


6 months ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open brody 6 months ago


case
PRO

6 months ago

@manishgotame have you tried using the Django Debug Toolbar?

https://django-debug-toolbar.readthedocs.io/en/latest/

The SQL panel within the toolbar displays all database queries executed for a given page request, including their execution time and the raw SQL. This helps identify which queries are slow.

Or run explain on the queries, to see what they are doing and where the time is being spent.

https://forum.djangoproject.com/t/best-practices-for-dealing-with-slow-performance/23707


manishgotame
PROOP

6 months ago

@case thank you for the suggestion. I used django-debug-toolbar to optimize a few of queries and it did help with the speed.

But still the problem remains. It takes over 3 seconds to return a query that reads 4 rows from a simple table. I don't think it should be that slow.

I noticed that my Database has only 1 instance and its only hosted in Singapore. But I can neither increase the instance or host it in different location because I have a volume attached to it. Is there something we can do here to fix this? Can this help with the latency problem?


fra
HOBBYTop 10% Contributor

6 months ago

how are your metrics? I think it might be good to add some logs to understand if it's the query that is slow or if it is the app slow, are you doing any request to third part?


manishgotame

@case thank you for the suggestion. I used django-debug-toolbar to optimize a few of queries and it did help with the speed. But still the problem remains. It takes over 3 seconds to return a query that reads 4 rows from a simple table. I don't think it should be that slow.I noticed that my Database has only 1 instance and its only hosted in Singapore. But I can neither increase the instance or host it in different location because I have a volume attached to it. Is there something we can do here to fix this? Can this help with the latency problem?

6 months ago

Hey! Depending on where your railway instance is, that could be the driving factor behind the speed or lack thereof.
For using a public mongo db you have to:
Railway -> across public network -> mongo
mongo process request and query -> send over public network -> Railway.

I'd suggest running a mongo instance on your Railway project and reference that! Near instant communication


Loading...