Slow Performance on Django Rest Framework API

Matthew Evans 1 Reputation point
2021-02-22T19:29:22.84+00:00

I recently deployed and Django Rest Framework API with a PostgreSQL database using a web app service.

I'm receiving bad response times of > 1 second, I'm not exactly sure what it could be.

  • Locally, django queries are almost instant.
  • Tested B1 and B2 service plans, didn't seem to make any difference
  • All resource metrics - CPU, memory etc. aren't maxing out

Any suggestions on how to investigate further would be greatly appreciated. Thanks!

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,866 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. ajkuma 22,401 Reputation points Microsoft Employee
    2021-02-23T16:46:34.567+00:00

    @Matthew Evans , Thanks for sharing a detailed description of the issue.

    You have stated, the WebApp was recently deployed, just to confirm- have you been experiencing this issue since the time of deployment or after some config change? Do you also receive any specific error message or just the slow response time?

    There could be several causes for high response time, to isolate the issue. Kindly try these steps:

    1. If it’s not done already, turn on Always On feature. By default, web apps are unloaded if they are idle for some period of time. This lets the system conserve resources. In Basic or Standard mode, you can enable Always On to keep the app loaded all the time.
    2. On the App Service App, in the left navigation, click on Diagnose and solve problems – Checkout the tile for “Diagnostic Tools” > “Availability and Performance” & "Best Practices".
      71175-image.png
    3. Update the CPU utilization as 75% for scale out condition or 25% for scale-in condition as test and see if that makes any difference (to avoid flapping condition/I understand you have already analyzed CPU usage)
    4. Isolate/Avoiding the outbound TCP limits is easier to solve, as the limits are set by the size of your worker. You can see the limits in Sandbox Cross VM Numerical Limits - TCP Connections- - To avoid outbound TCP limits, you can either increase the size of your workers, or scale out horizontally.
    5. Troubleshooting intermittent outbound connection errors in Azure App Service - (to isolate port exhaustion).
    6. If there are multiple Apps under a single App Service Plan, distribute the apps across multiple app service plans to obtain additional compute levels (to isolate the issue further/shared more details on this in the ‘comment’ section below)
      71224-image.png
    7. Review the logs to fetch more details on this issue:
      You may also inspect the log files from the browser at https://<app-name>.scm.azurewebsites.net/api/logs/docker.

  2. Ashish Kumar Verma 1 Reputation point Student Ambassador
    2021-05-07T04:34:44.037+00:00

    There is a small trick that you can follow to speed up for drf
    Just remove the unwanted apps in INSTALLED_APPS and MIDDLEWARE

    94595-image.png

    Like here you can see messages, csrf middle ware that are not needed in a web api so you can remove these things and boost your django rest framework performance

    0 comments No comments