Search code examples
dockernginxuwsgi

UWSGI response time causing 504 Gateway timeout


I am running a UWSGI in combination with Nginx using this docker-container. After around 16 hours of uptime the response time of the UWSGI server suddenly skyrockets and I get a 504 gateway timeout. All the pages and files that are served by Nginx are still reachable. So far all of my attempts at fixing this have been unsuccessful. I didn't find anything online except for people having timeouts because of their code runtime. This does not seem to be the case with this project as Graylog tells me that my method takes < 100 milliseconds to run through. However uwsgi seems to be doing something very time consuming before or after it calls my method. Has anyone ever experienced this kind of problem?

Code


Solution

  • It turns out that psycopg2 has a memory leak in certain situations (at least that is what we suspect). After adding a profiler we found out that the psycopg2 cursor.execute method took > 50s to complete after some uptime. A little bit of research lead us to some memory leak issue that seems to occur whenever a cursor is initialized without a name. Sadly we could not just assign a name to our cursor because of the commit-mode we were using. We resolved that issue by ditching the connection-pool and manually handling connection refreshing so that the memory leak issue would not be a problem because the connection isn't open for long enough...