Forums

Performance question

I have a site that emails the user before rendering a confirmation page. I think (not sure) that logging in to Gmail and sending the email is what is slowing down the rendering of the confirmation page. How would I got about determining the cause of the slow rendering?

Some ideas I thought of: 1. Embedding a timeit statement/function after each function call and throughout the program and writing the timeit results to a log file 2. Using Google Search console to detect if there's any SEO or page speed issues 3. Chrome DevTools & Google Analytics to find specific page elements or network calls that are taking awhile

Ok I found this page https://help.pythonanywhere.com/pages/MySiteIsSlow/ which confirmed some of my suspicions i.e. using SQL lite, 3rd party APIs, and the filesystem and probably the app itself.

DevTools is saying its 20seconds to load and access log is saying 9 seconds for a POST request. Can network transit time really be 11 seconds though?

Your conclusions are quite right. I'd suggest eliminating usage of an external service during the view rendering -- that's something you don't have control over. We have a help page that might provide some inspiration: https://help.pythonanywhere.com/pages/AsyncInWebApps/.

I learned about logger for Python so no need to use timeit. So it looks like the issue is using the external service during the view rendering and then SQL lite.

2021-01-08 05:10:56,310 INFO app uWSGIWorker2Core0:email must be sent..now rendering confirm
2021-01-08 05:15:37,117 INFO app uWSGIWorker3Core0:email must be sent..now rendering confirm
2021-01-08 05:16:07,033 INFO app uWSGIWorker3Core0:confirm is rendered and email triggered now...
2021-01-08 05:16:07,052 INFO app uWSGIWorker3Core0:yagmail logging in to gmail
2021-01-08 05:16:07,067 INFO app uWSGIWorker3Core0:yagmail now sending email
2021-01-08 05:16:14,807 INFO app uWSGIWorker3Core0:sqlite retrieved
2021-01-08 05:16:14,851 INFO app uWSGIWorker3Core0:insert completed

Test 2...

2021-01-08 05:20:19,551 INFO app uWSGIWorker3Core0:email must be sent..now rendering confirm
2021-01-08 05:31:22,915 INFO app uWSGIWorker3Core0:email must be sent..now rendering confirm
2021-01-08 05:31:56,498 INFO app uWSGIWorker3Core0:confirm is rendered and email triggered now...
2021-01-08 05:31:56,502 INFO app uWSGIWorker3Core0:yagmail logging in to gmail
2021-01-08 05:31:56,507 INFO app uWSGIWorker3Core0:yagmail now sending email
2021-01-08 05:32:04,375 INFO app uWSGIWorker3Core0:sqlite retrieved
2021-01-08 05:32:04,414 INFO app uWSGIWorker3Core0:insert completed

Thanks for the tip on asynch.

[formatted by admin]

OK, I assume you resolved your problem? (I'm a little bit confused about two first logs, which are the same and there's a huge time gap between them; apart from that the most time consuming parts are "between email must be sent..now rendering confirm" and "confirm is rendered and email triggered now...", and between "yagmail now sending email" and "sqlite retrieved").

I've improved it, but it's still taking over 5 seconds.

Here's the server: 73.70.14.95 - - [23/Jan/2021:06:15:30 +0000] "POST / HTTP/1.1" 200 1460 "https://www.marinhaulers.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" "73.70.14.95" response-time=0.505

73.70.14.95 - - [23/Jan/2021:06:15:30 +0000] "GET /static/images/MG_6429_2_10.jpg HTTP/1.1" 200 2945354 "https://www.marinhaulers.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" "73.70.14.95" response-time=0.027

73.70.14.95 - - [23/Jan/2021:06:15:32 +0000] "GET /static/images/MG_6429_2_10.jpg HTTP/1.1" 200 2945354 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36" "73.70.14.95" response-time=0.028

And in the log MySQL sped things up: 01/23/2021 06:15:29 AM image starts saving 01/23/2021 06:15:30 AM image ends saving 01/23/2021 06:15:30 AM database write starts 01/23/2021 06:15:30 AM database write ends and render template starts 01/23/2021 06:15:30 AM rendetemplate ends

DevTools output

Is it consistent between different requests happening at different times?