Forums

Slow Web App Reload (Using Reload Button on 'Web' Page)

Like the title says, I have been experiencing very slow reload times. When I first started using pythonanywhere my webapp would take 10 seconds max to reload and now it takes a minimum of 5 minutes. Often times I have to hit the reload button multiple times for it to work.

As I have been unable to find anything on the topic. An explanation of what goes into reloading pythonanywhere web apps might be helpful so I (and others) can understand what to do to make long reload times shorter and to reduce failed reloads. If I need to roll out a quick bugfix, spending 45 minutes of "trial and error" to reload my web app is not really an option and I am just waiting for this to cause a problem.

What factors make a web app reload take longer?

What causes a reload to fail?

Are these problems normally caused by my code or some sort of configuration problem (or something else)?

What is the best way to track down any problems causing long reload times or reload failures?

Also, can tasks or running consoles impact reloading?

When you reload your website, we simply stop the running processes (which should be instant) and then start up new ones. This happens by starting up a uWSGI process, which imports your WSGI file (the one linked from the web tab), then forks off a number of worker processes to handle requests.

The most likely cause of a slow reload is if the import phase is slow. (This, by the way, is why we tell people not to call app.run in a Flask app at module level -- the app.run will block the import so your site will never start.)

So the best way to debug would be to add print statements at the module level inside the file that is imported from your WSGI file to work out what's taking the time. Something like:

from datetime import datetime

...

print("{}: about to load models".format(datetime.now())

...

print("{}: about to connect to database".format(datetime.now())

...and so on would put appropriately-timestamped stuff into the server log.

That is super useful. Wish I would have known about printing timestamps months ago. Allowed me to solve both the failed reloads and the long reload times. A reload take approximately 5 seconds now. Thanks!

Excellent -- thanks for confirming!