Report this

What is the reason for this report?

Django handel request peak

Posted on October 31, 2020

Hello,

I have server (1 cup adn 1gb ram) with a django app, served with daphne and a redis server for django channels.

Then I have a managed database (postgres) which is used in django app.

My application is a very simple web browser quiz game, but when the game start all the user need to request the same information ( or almost the same) in a very short period of time. I have an approximated request of 44 for user. (80% are static files)

User plays in teams of 7-9 players, so I have a plan to implement the game a staggered start. So every second 7-9 user request the start of the game, so if I have 60 teams the game will start staggered along one minute.

Do you think that this is a good strategy to minify the load on my server?

In the other hand I have planned to make this upgrades:

  • Use a space to server static files.

  • Use a managed redis database from DO.

  • May update my server to 2cpu or 4 cpu with 4 workers of daphne.

What do you think of these upgrades will be worth it?

** Some date:

  • 60 user I have a peak of 40% of cup and then it stays 4-5%. (no staggered strategy)

Thanks in advance.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Heya,

Just came across this answer and decided to write some general guidelines for anyone who comes across this in the future despite the old question.

Your staggered start strategy can certainly help in spreading the load over a period of time, effectively mitigating server stress during peak loads. However, hardware upgrades will also enhance overall performance and handle traffic more efficiently. Here’s a little bit of insight into your upcoming upgrade plans:

  • Using DigitalOcean Spaces for serving static files would be a highly beneficial choice. It offloads the task of serving static files from your main server, helping to free up resources.
  • A managed Redis database could provide you with better performance and ease of maintenance.
  • If your server’s CPU spikes while dealing with traffic, upgrading the server to a 2 or 4 CPU configuration with 4 Daphne workers can help in increasing the overall performance.

Overall, your planned upgrades seem logical and may significantly improve the performance and responsiveness of your Django application. I would suggest monitoring your servers to understand better what works and what doesn’t for your specific use case.

For detailed documentation on scaling and optimising your servers, check out this link.

Hope that this helps!

Your staggered start strategy is a good approach to reduce the load on your server, as it distributes the requests over time, preventing all users from hitting the server simultaneously. This can help manage CPU and memory usage effectively for your setup. Below are considerations and evaluations of your planned upgrades:

  1. Using a Space to Serve Static Files Offloading static files to a DigitalOcean Space or similar object storage service is highly recommended. Serving static files directly from your server consumes resources that could otherwise be used for dynamic requests. Spaces are optimized for such use cases and will improve your server’s performance while reducing latency for static file delivery.

  2. Using a Managed Redis Database Moving to a managed Redis database can be beneficial if your current server’s Redis usage is close to its resource limits. Managed Redis ensures high availability, scalability, and performance. It will also reduce the burden on your application server, which can focus solely on running your Django app and Daphne.

  3. Upgrading to a Higher CPU Server Upgrading to a 2-CPU or 4-CPU server with additional workers for Daphne will allow your server to handle more concurrent requests. If your application is already running at 40% CPU usage with 60 users, this upgrade is worthwhile if you anticipate scaling up the number of teams or users significantly.

  4. Staggered Game Start This is a highly effective strategy, especially for scenarios like yours where many users request similar information simultaneously. By staggering the start times, you distribute the load evenly over time, minimizing resource contention.

  5. Cost vs. Benefit

    • Static Files via Space: Cost-effective and should be prioritized.
    • Managed Redis: Worth it if Redis usage grows with user count.
    • Server Upgrade: Evaluate based on current and expected user growth. If your staggered strategy works well, upgrading may not be immediately necessary. Monitor performance metrics before committing to this expense.
  6. Additional Suggestions

    • Enable caching for database queries to reduce repeated hits to the managed PostgreSQL database.
    • Use a CDN to serve static files globally for better performance and reduced server load.
    • Monitor application performance regularly using tools like New Relic or DigitalOcean’s monitoring to identify bottlenecks and optimize accordingly.

Your current strategy, coupled with these planned upgrades, provides a solid foundation for scaling your application efficiently while managing costs.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.