Django 4.2.15 on Cloud Run - Severe Slowdown with uWSGI and High `domLoading` Time, But Only in One Project

enter image description here

enter image description here

I'm encountering severe performance issues with my Django 4.2.15 application when running on Google Cloud Run. However, the problem seems to be isolated to this specific project, as other projects on Cloud Run do not exhibit the same behavior. Here are the details:

  • Django version: 4.2.15
  • Environment: Google Cloud Run (1 Core, 2 GB Memory)
  • Web Server: uWSGI 2.0.26 (Nginx is not being used)
  • Database: MySQL (queries are not the bottleneck)
  • First response When checking in Chrome's Network tab, the initial document load takes 2.04 seconds.
  • Issue: The site is significantly slower on Cloud Run compared to my local environment.
  • Observation: The Django Debug Toolbar shows that about 90% of the total time is spent during the domLoading phase, which is disproportionately long.
  • Caching: The site performs well when serving cached views (i.e., when database access is avoided).
  • Local Environment: The application runs very quickly locally without any noticeable delays.
  • Cloud Run Details:
    • The slowdown occurs even when no other users are accessing the service.
    • This is not due to a cold start; the service is already running.
    • Other projects on Cloud Run do not experience this issue.

Additionally, I created a simple static HTML page with the following content:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Hello world</title>
</head>
<body>
Hello world!
</body>
</html>

This page is rendered using a basic Django TemplateView as shown below:

path('plane/', TemplateView.as_view(template_name='plane.html'), name='test'),

Despite its simplicity, this page takes around 2 seconds to load on Cloud Run, which is far too long.

Given that this issue is specific to this project and does not affect my other Cloud Run projects, I suspect there may be something unique about this project's configuration or setup that is causing the problem.

Could this be related to the way uWSGI is configured, or might there be other factors within this specific project that are contributing to the slowdown? Any insights on how to diagnose or resolve this issue would be greatly appreciated.

Additional Information: Safari and curl Results

Safari:

  • domLoading: 2963 ms

curl:

  • http_code: 200
  • time_total: 6.228104
  • time_namelookup: 0.003261
  • time_connect: 0.017354
  • time_appconnect: 0.078004
  • time_starttransfer: 6.095002

Change from uWSGI to Gunicorn

I switched from uWSGI to Gunicorn, but there was no improvement in loading speed.

enter image description here

Back to Top