Skip to content

Instantly share code, notes, and snippets.

View akshar-raaj's full-sized avatar
💭
Learning something new everyday!

Akshar Raaj akshar-raaj

💭
Learning something new everyday!
View GitHub Profile
@akshar-raaj
akshar-raaj / nginx-performance-test.md
Created November 3, 2024 02:36
Nginx Performance Testing

Performance Analysis of Nginx with Increasing Concurrent Users

Summary of Findings

  1. Total Requests per Second (RPS):
    • Run #1: Low RPS, likely due to minimal concurrent users.
    • Run #2: Steady increase in RPS, reaching around 200 requests per second.
    • Run #3: Further increase, stabilizing around 800–900 requests per second.
    • Run #4: Peaks at approximately 1,000 requests per second. Notably, no failures occurred across all runs, indicating strong stability and load-handling capacity.
Optimizing Nginx and Python Configuration with Load Testing: A Case Study
Objective
The goal of this experiment was to determine how many concurrent users and requests per second a modest server configuration could handle with a basic Nginx and Python web application setup. The server in question has 1 GB RAM and a 2000 MHz single-core CPU, hosted on Linode.
Initial Setup
We started with a high-performance Nginx server capable of handling 10,000 requests per second for static content. For dynamic content, we configured Nginx to route requests to a Python web application. The web application simulates both CPU-bound tasks and a database operation with a total processing time of approximately 20 milliseconds per request, giving the backend the ability to serve at most 50 requests per second.
The backend Python application was served by a single instance initially, and Nginx was configured to proxy requests to this backend:
nginx

This post is targetted towards Celery beginners. It discusses different ways to run Celery.

  • Using celery with a single module
  • Using celery with multiple modules.
  • Using celery with multiple modules split across packages.

Prerequisites

You should have Celery and Redis installed. We will use Redis as our broker.

Question.objects.values('question_text').annotate(cnt=Count('question_text'))
Question.objects.annotate(avg_votes=Avg('choice__votes'))
Choice.objects.aggregate(avg=Avg('votes'))
@akshar-raaj
akshar-raaj / total_votes_cast.py
Created August 12, 2019 09:02
Total votes cast
Choice.objects.aggregate(num_votes=Sum('votes'))
@akshar-raaj
akshar-raaj / question_with_no_choices.py
Created August 12, 2019 09:01
Question with no choices
Question.objects.annotate(num_votes=Sum('choice__votes')).filter(num_votes__isnull=True)
Question.objects.annotate(num_votes=Sum('choice__votes')).filter(num_votes__isnull=False).order_by('num_votes')[0]
Question.objects.annotate(num_votes=Sum('choice__votes')).filter(num_votes__isnull=False).order_by('-num_votes')[0]