I recently deployed my Django app on Railway, where I set up PostgreSQL and Redis and connected them to my project. However, I’ve noticed a drastic slowdown in query and cache performance compared to running locally—by several orders of magnitude.
For example, one of my views executes queries in 2.58ms on my local database but takes 7411.42ms on Railway. Similarly, the same view’s cache time is 24.14ms on local Redis but 2122.14ms on Railway.
I expected some performance drop when moving to a cloud-hosted setup, but this level of slowdown seems excessive. Initially, I suspected an incorrect connection setup on Railway, but after testing with Redis Cloud, the performance remained similar to Railway’s Redis. I haven’t tested another cloud database yet.
Does anyone have insights into what might be causing such a drastic difference?
Here’s my database setup in settings.py:
DATABASES = {
'default': dj_database_url.config(default=os.getenv('DATABASE_URL'))
}
and cache setup:
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
SESSION_CACHE_ALIAS = "default"
SELECT2_CACHE_BACKEND = "select2"
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": REDIS_URL,
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
},
'select2': {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": REDIS_URL,
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
}
}
Any help would be greatly appreciated!
Thanks!