Search code examples
djangoamazon-web-serviceswebserver

How to improve the performance of a Django application across different geographic regions?


I have a Django application that is hosted on an AWS box located in the us-east-1 geographic region using Nginx and django-channels. Recently, I have had some users in the ap-southeast-1 region complain that my app is not very responsive. The app runs fine for me as I am using us-east-1.

  1. How can I detect poor performance in a region is happening before a user complains?
  2. What can I do to improve the app performance and user experience in the ap-southeast-1 timezone?
  3. Is there any way to test the performance in another geographic region as part of unit-testing or something similar?

I have a feeling the answer for #2 will have something to do with: (A) Adding another web server in ap-southeast-1 and (B) caching, but I'm keen to hear if there are additional things I should be doing.

However, I have no clue how to detect slow performance for other regions is happening in the first place or to test to ensure it does not happen again in the future.


Solution

  • Yes, optimally you should have a server wherever you have users. However, if multiple servers in different regions have to talk to the same database, you will still have latency issues when the server communicates with the database in another region.

    The best solution would be to have your full stack, servers and databases, in all supported regions and use cross-region replication to ensure that all regions share the same data. This is supported for some AWS databases such as DynamoDB and RDS.

    As your architecture gets more complex, it may be a good idea to use Cloudformation to manage your stack in each region so that everything is kept up to date.

    As for detecting performance, Cloudwatch is a good tool for monitoring your AWS resources. Depending on what AWS resource you are using for your server, it should have some metrics to measure the response times.

    As for testing performance, you could look into creating a dev/test version of your server in another region, and use a proxy to access it. Then just use Cloudwatch to see how long those requests take.