|
| 1 | +# Load Testing with Locust |
| 2 | + |
| 3 | +This directory contains Locust load testing scripts for the Hackathon Registration Platform. |
| 4 | + |
| 5 | +## Setup |
| 6 | + |
| 7 | +1. **Install Python** (if not already installed) |
| 8 | + |
| 9 | + - Download from https://www.python.org/downloads/ |
| 10 | + |
| 11 | +2. **Install Locust:** |
| 12 | + ```bash |
| 13 | + pip install -r requirements.txt |
| 14 | + ``` |
| 15 | + |
| 16 | +## Running Load Tests |
| 17 | + |
| 18 | +### Basic Load Test (Web UI) |
| 19 | + |
| 20 | +Run Locust with web interface: |
| 21 | + |
| 22 | +```bash |
| 23 | +locust -f locustfile.py --host=https://frontend-2qaml73oq-amanraz-thakurs-projects.vercel.app |
| 24 | +``` |
| 25 | + |
| 26 | +Then open http://localhost:8089 in your browser and configure: |
| 27 | + |
| 28 | +- **Number of users**: Start with 10-50 |
| 29 | +- **Spawn rate**: 5 users per second |
| 30 | +- **Host**: Pre-filled with your deployment URL |
| 31 | + |
| 32 | +### Headless Load Test (Command Line) |
| 33 | + |
| 34 | +Run without web UI: |
| 35 | + |
| 36 | +```bash |
| 37 | +locust -f locustfile.py --host=https://frontend-2qaml73oq-amanraz-thakurs-projects.vercel.app --users 50 --spawn-rate 5 --run-time 2m --headless |
| 38 | +``` |
| 39 | + |
| 40 | +Parameters: |
| 41 | + |
| 42 | +- `--users 50`: Simulate 50 concurrent users |
| 43 | +- `--spawn-rate 5`: Add 5 users per second |
| 44 | +- `--run-time 2m`: Run for 2 minutes |
| 45 | +- `--headless`: No web UI |
| 46 | + |
| 47 | +### Test Specific User Type |
| 48 | + |
| 49 | +Test only regular users: |
| 50 | + |
| 51 | +```bash |
| 52 | +locust -f locustfile.py HackathonUser --host=https://frontend-2qaml73oq-amanraz-thakurs-projects.vercel.app |
| 53 | +``` |
| 54 | + |
| 55 | +Test only admin users: |
| 56 | + |
| 57 | +```bash |
| 58 | +locust -f locustfile.py AdminUser --host=https://frontend-2qaml73oq-amanraz-thakurs-projects.vercel.app |
| 59 | +``` |
| 60 | + |
| 61 | +## What Gets Tested |
| 62 | + |
| 63 | +### HackathonUser (Regular Visitors) |
| 64 | + |
| 65 | +- ✅ Homepage visits (30% of actions) |
| 66 | +- ✅ Registration page visits (20%) |
| 67 | +- ✅ Team registration submissions (10%) |
| 68 | +- ✅ Contact form submissions (10%) |
| 69 | +- ✅ Team lead status checks (10%) |
| 70 | +- ✅ Dashboard visits (10%) |
| 71 | + |
| 72 | +### AdminUser |
| 73 | + |
| 74 | +- ✅ Admin page access (50%) |
| 75 | +- ✅ Fetching all registrations (50%) |
| 76 | + |
| 77 | +## Understanding Results |
| 78 | + |
| 79 | +### Key Metrics to Watch: |
| 80 | + |
| 81 | +- **RPS (Requests Per Second)**: Higher is better |
| 82 | +- **Response Time**: Should be <1s for most requests |
| 83 | +- **Failure Rate**: Should be <1% |
| 84 | +- **95th Percentile**: 95% of requests complete within this time |
| 85 | + |
| 86 | +### Expected Performance: |
| 87 | + |
| 88 | +- Homepage: <500ms |
| 89 | +- API endpoints: <1000ms |
| 90 | +- Database operations: <2000ms |
| 91 | + |
| 92 | +## Sample Test Scenarios |
| 93 | + |
| 94 | +### Light Load (Development Testing) |
| 95 | + |
| 96 | +```bash |
| 97 | +locust -f locustfile.py --host=https://frontend-2qaml73oq-amanraz-thakurs-projects.vercel.app --users 10 --spawn-rate 2 --run-time 1m --headless |
| 98 | +``` |
| 99 | + |
| 100 | +### Medium Load (Typical Usage) |
| 101 | + |
| 102 | +```bash |
| 103 | +locust -f locustfile.py --host=https://frontend-2qaml73oq-amanraz-thakurs-projects.vercel.app --users 50 --spawn-rate 5 --run-time 5m --headless |
| 104 | +``` |
| 105 | + |
| 106 | +### Heavy Load (Stress Testing) |
| 107 | + |
| 108 | +```bash |
| 109 | +locust -f locustfile.py --host=https://frontend-2qaml73oq-amanraz-thakurs-projects.vercel.app --users 200 --spawn-rate 10 --run-time 10m --headless |
| 110 | +``` |
| 111 | + |
| 112 | +### Spike Test (Sudden Traffic) |
| 113 | + |
| 114 | +```bash |
| 115 | +locust -f locustfile.py --host=https://frontend-2qaml73oq-amanraz-thakurs-projects.vercel.app --users 500 --spawn-rate 50 --run-time 3m --headless |
| 116 | +``` |
| 117 | + |
| 118 | +## Export Results |
| 119 | + |
| 120 | +Save results to CSV: |
| 121 | + |
| 122 | +```bash |
| 123 | +locust -f locustfile.py --host=https://frontend-2qaml73oq-amanraz-thakurs-projects.vercel.app --users 50 --spawn-rate 5 --run-time 2m --headless --csv=results --html=report.html |
| 124 | +``` |
| 125 | + |
| 126 | +This generates: |
| 127 | + |
| 128 | +- `results_stats.csv` - Request statistics |
| 129 | +- `results_failures.csv` - Failed requests |
| 130 | +- `results_stats_history.csv` - Time-series data |
| 131 | +- `report.html` - Visual HTML report |
| 132 | + |
| 133 | +## Troubleshooting |
| 134 | + |
| 135 | +### Connection Errors |
| 136 | + |
| 137 | +- Check if the deployment URL is correct |
| 138 | +- Ensure the site is accessible |
| 139 | +- Verify Vercel isn't rate-limiting |
| 140 | + |
| 141 | +### High Failure Rates |
| 142 | + |
| 143 | +- Reduce number of users |
| 144 | +- Increase spawn rate delay |
| 145 | +- Check MongoDB connection limits |
| 146 | +- Review Vercel function execution limits (free tier: 10s timeout) |
| 147 | + |
| 148 | +### Database Issues |
| 149 | + |
| 150 | +- MongoDB Atlas free tier has connection limits (500 max) |
| 151 | +- Consider upgrading if testing with >100 concurrent users |
| 152 | + |
| 153 | +## Best Practices |
| 154 | + |
| 155 | +1. **Start Small**: Begin with 10 users, gradually increase |
| 156 | +2. **Monitor Server**: Watch Vercel logs during tests |
| 157 | +3. **Test Off-Peak**: Avoid testing during actual registrations |
| 158 | +4. **Clean Test Data**: Remove test registrations after load tests |
| 159 | +5. **Respect Limits**: Vercel free tier has bandwidth/execution limits |
| 160 | + |
| 161 | +## Security Note |
| 162 | + |
| 163 | +The `locustfile.py` includes the admin token for testing. This is acceptable for load testing but ensure: |
| 164 | + |
| 165 | +- Don't commit sensitive tokens to public repos |
| 166 | +- Use test environments when possible |
| 167 | +- Clean up test data after testing |
0 commit comments