Hi everyone, I’m running a Django-based website that focuses on restaurant content mainly Texas Roadhouse menus, reviews, and food guides. Everything has been working great for several months, but lately, I’ve been experiencing performance issues and intermittent database connection errors that I can’t seem to track down. I’m hoping someone here might be able to help me troubleshoot or point out what I might be missing.
The biggest problem is that certain pages (especially those that pull dynamic menu data from the database) take a long time to load — sometimes up to 10 seconds and occasionally throw a “OperationalError: MySQL server has gone away” message. I’m using MySQL as my database backend with Django 4.2, hosted on a VPS. I’ve already tried increasing the CONN_MAX_AGE and wait_timeout settings, but the issue persists intermittently. Interestingly, it happens more often when the site experiences moderate traffic spikes.
Another issue is that Django’s ORM seems to be creating duplicate queries. When I check the debug toolbar, I see multiple redundant SELECT statements for the same data, especially in my view that handles menu categories and items. I’ve tried using select_related() and prefetch_related(), which helped slightly, but I still get a high number of queries per page load. I’m not sure if this is an architectural problem in my view logic or if I need to restructure how I’m querying related models.
I also implemented caching using Redis, but it doesn’t seem to be helping as much as I expected. My cache hit rate is under 40%, and even cached pages sometimes load slowly. I’m wondering if my cache keys aren’t being reused correctly or if I’m not caching the right data. The site uses Django’s built-in cache framework with Redis as the backend, configured in settings.py. Could this be related to how my sessions are stored or how I’m invalidating cache keys?
Another strange behavior is that static files occasionally fail to load after a deployment. I’m using WhiteNoise for static file serving, and I’ve verified that collectstatic runs successfully, but users sometimes report missing CSS or image files. The logs show 404 errors for files that definitely exist in the /staticfiles/ directory. Restarting Gunicorn or clearing the cache usually fixes it temporarily, which makes me think it’s a caching or file reference issue.
Has anyone else run into similar problems combining Django, MySQL, Redis, and WhiteNoise in production? I’d love some advice on how to stabilize the database connections, optimize ORM performance, and make caching more predictable. My website doesn’t have heavy traffic, but these issues have started affecting usability. Any tuning tips or example configurations would be hugely appreciated I really want to get my Texas Roadhouse content site back to running smoothly. Sorry for the long post!