wil
wil

Reputation: 599

Gateway timeout 504 when moving from django development server to Nginx/uWSGI?

I have a Django app that talks to a remote Raspberry Pi to acquire imagery through the Pi's camera. Whenever I test the "get a new image" button in the app, the browser gets hung up for about 60 seconds and the image never arrives.

The Raspberry Pi is trying to POST the image to the Django app which is then supposed to save it to persistent storage.

The logs of Nginx show a 504 "gateway timeout" at the 60 second mark. However, this worked smoothly when I was using the Django development server and took about a second to POST the image. What's going wrong now?

Upvotes: 2

Views: 1490

Answers (1)

wil
wil

Reputation: 599

Make sure you're running uWSGI with multiple processes and threads.

You can test this on the uWSGI command line by adding:

--processes 4 --threads 2

or in a uWSGI ini file:

processes = 4
threads = 2

If the Pi is POSTing the image back to the app while waiting to display the result to the user, then uWSGI needs to be able to handle both things concurrently.

Another possibility is that your django app uses threads itself, and without the --threads N or --enable-threads option to uWSGI, the GIL isn't enabled when your app runs. Adding --enable-threads (or enable-threads = true to the ini file) will enable the GIL without starting multiple app threads.

See a note on python threads in the uWSGI docs if you suspect that your app's threading may be the problem.

In any case, make sure you've provided for enough concurrency if you're seeing gateway timeouts.

Upvotes: 1

Related Questions