Forums

Web app suddendly very slow

I've made a website with Django and everything worked fine, but when I upgraded my account then my website stopped working. When i go to my website it keeps loading forever. Sometimes it seems that the website works normally (loads immediatly pages) but it's just for something like 5 sec, then again endless loading time. This is very strange, i've not modified my code, I've just upgraded my account. Reloading the web app takes a long time and i get the 'Your webapp took a long time to reload. It probably reloaded, but we were unable to check it.' message

Update: I see in the logs that the django view works because i see something printed out but the problem is when the server sends the response. Example:

def my_view(request):
    print("i can see this in the logs!")
    return HttpResponse("ok") # the view keeps loading but not 'ok' returned

What do you see in the error and server logs? For the print calls, I'd suggest adding flush=True argument as well as redirection to stderr (file=sys.stderr), it's usually easier to read the output of the error log, than server log.

error log:

2023-08-24 09:11:19,142: OSError: write error
2023-08-24 09:11:19,636: Not Found: /favicon.ico

server log:

2023-08-24 13:27:03 Thu Aug 24 13:27:03 2023 - received message 0 from emperor
2023-08-24 13:27:03 SIGINT/SIGTERM received...killing workers...
2023-08-24 13:27:04 worker 1 buried after 1 seconds
2023-08-24 13:27:04 worker 2 buried after 1 seconds
2023-08-24 13:27:04 goodbye to uWSGI.
2023-08-24 13:27:04 VACUUM: unix socket /var/sockets/looma.eu.pythonanywhere.com/socket removed.
2023-08-24 13:27:17 *** Starting uWSGI 2.0.20 (64bit) on [Thu Aug 24 11:27:07 2023] ***
2023-08-24 13:27:17 compiled with version: 9.4.0 on 22 July 2022 18:35:26
2023-08-24 13:27:17 os: Linux-5.15.0-1031-aws #35~20.04.1-Ubuntu SMP Sat Feb 11 16:19:06 UTC 2023
2023-08-24 13:27:17 nodename: blue-euweb2
2023-08-24 13:27:17 machine: x86_64
2023-08-24 13:27:17 clock source: unix
2023-08-24 13:27:17 pcre jit disabled
2023-08-24 13:27:17 detected number of CPU cores: 4
2023-08-24 13:27:17 current working directory: /home/looma
2023-08-24 13:27:17 detected binary path: /usr/local/bin/uwsgi
2023-08-24 13:27:17 *** dumping internal routing table ***
2023-08-24 13:27:17 [rule: 0] subject: path_info regexp: \.svgz$ action: addheader:Content-Encoding:gzip
2023-08-24 13:27:17 *** end of the internal routing table ***
2023-08-24 13:27:17 chdir() to /home/looma/
2023-08-24 13:27:17 your processes number limit is 256
2023-08-24 13:27:17 your memory page size is 4096 bytes
2023-08-24 13:27:17 detected max file descriptor number: 123456
2023-08-24 13:27:17 building mime-types dictionary from file /etc/mime.types...
2023-08-24 13:27:17 567 entry found
2023-08-24 13:27:17 lock engine: pthread robust mutexes
2023-08-24 13:27:17 thunder lock: disabled (you can enable it with --thunder-lock)
2023-08-24 13:27:17 uwsgi socket 0 bound to UNIX address /var/sockets/looma.eu.pythonanywhere.com/socket fd 3
2023-08-24 13:27:17 Python version: 3.10.5 (main, Jul 22 2022, 17:09:35) [GCC 9.4.0]
2023-08-24 13:27:17 PEP 405 virtualenv detected: /home/looma/.virtualenvs/mysite_venv
2023-08-24 13:27:17 Set PythonHome to /home/looma/.virtualenvs/mysite_venv
2023-08-24 13:27:17 *** Python threads support is disabled. You can enable it with --enable-threads ***
2023-08-24 13:27:17 Python main interpreter initialized at 0x560f1456fe50
2023-08-24 13:27:17 your server socket listen backlog is limited to 100 connections
2023-08-24 13:27:17 your mercy for graceful operations on workers is 60 seconds
2023-08-24 13:27:17 setting request body buffering size to 65536 bytes
2023-08-24 13:27:17 mapped 501384 bytes (489 KB) for 2 cores
2023-08-24 13:27:17 *** Operational MODE: preforking ***
2023-08-24 13:27:17 initialized 54 metrics
2023-08-24 13:27:17 couldn't import psycopg 'c' implementation: No module named 'psycopg_c'
2023-08-24 13:27:17 WSGI app 0 (mountpoint='') ready in 9 seconds on interpreter 0x560f1456fe50 pid: 1 (default app)
2023-08-24 13:27:17 *** uWSGI is running in multiple interpreter mode ***
2023-08-24 13:27:17 gracefully (RE)spawned uWSGI master process (pid: 1)
2023-08-24 13:27:17 spawned uWSGI worker 1 (pid: 2, cores: 1)
2023-08-24 13:27:17 spawned 2 offload threads for uWSGI worker 1
2023-08-24 13:27:17 spawned uWSGI worker 2 (pid: 5, cores: 1)
2023-08-24 13:27:17 metrics collector thread started
2023-08-24 13:27:17 spawned 2 offload threads for uWSGI worker 2
2023-08-24 13:27:22 
2023-08-24 13:27:22 RENDERING INDEX
2023-08-24 13:27:22 
2023-08-24 13:27:37

2023-08-24 13:32:19 Thu Aug 24 13:32:18 2023 - *** HARAKIRI ON WORKER 1 (pid: 2, try: 1) ***
2023-08-24 13:32:19 Thu Aug 24 13:32:18 2023 - HARAKIRI !!! worker 1 status !!!
2023-08-24 13:32:19 Thu Aug 24 13:32:18 2023 - HARAKIRI [core 0] 10.0.0.162 - GET / since 1692876437
2023-08-24 13:32:19 Thu Aug 24 13:32:18 2023 - HARAKIRI !!! end of worker 1 status !!!
2023-08-24 13:32:19 DAMN ! worker 1 (pid: 2) died, killed by signal 9 :( trying respawn ...
2023-08-24 13:32:19 Respawned uWSGI worker 1 (new pid: 10)
2023-08-24 13:32:19 spawned 2 offload threads for uWSGI worker 1
2023-08-24 13:32:35 Thu Aug 24 13:32:34 2023 - *** HARAKIRI ON WORKER 2 (pid: 5, try: 1) ***
2023-08-24 13:32:35 Thu Aug 24 13:32:34 2023 - HARAKIRI !!! worker 2 status !!!
2023-08-24 13:32:35 Thu Aug 24 13:32:34 2023 - HARAKIRI [core 0] 10.0.0.162 - GET / since 1692876453
2023-08-24 13:32:35 Thu Aug 24 13:32:34 2023 - HARAKIRI !!! end of worker 2 status !!!
2023-08-24 13:32:35 DAMN ! worker 2 (pid: 5) died, killed by signal 9 :( trying respawn ...
2023-08-24 13:32:35 Respawned uWSGI worker 2 (new pid: 13)
2023-08-24 13:32:35 spawned 2 offload threads for uWSGI worker 2

The error about psycopg (couldn't import psycopg 'c' implementation: No module named 'psycopg_c') is "normal", i have it also in local and it doesn't stop the server from running. Thanks for your time

I'm guessing that the view code that you put into your first message in this thread is an example rather than the actual code that's there; if you put prints in between different lines in the code, is there a particular one that is blocking? It's a good idea to put the flush=True keyword in there to make sure that the output is written to the log file.

I found the problem, it's the db, for some reason is very very slow. Switching back to sqlite and everything worked again. I don't even know how i didn't notice that before, probably i changed database just after upgrading the account and forgot about it, feeling kinda stupid but happy to have at least found out what the problem was.

Thanks for letting us know!