Sync vs Async Django servers - Load testing
Tags: django, gunicorn, server, testing
Published: 2020-12-27 18:06:52

If you are using **Gunicorn** as **API server Gateway** and you want to reduce the **response time** drastically. then you are in the right place.

A while ago our application experienced a surge in the number of active users and our API **response time** started to rise up and then **Asynchronous server** came to our rescue.

This post covers the **Load testing** result comparison between **Sync and Async Gunicorn servers**.

**Load testing** was done using [Locust](https://locust.io/). one of the best tools out there IMO
 

#Synchronous Gunicorn Server
![Sync Gunicorn server](https://dev-to-uploads.s3.amazonaws.com/i/50qhk61t0jpvne6j4sdx.jpeg)
######[credits](https://medium.com/@nhudinhtuan/gunicorn-worker-types-practice-advice-for-better-performance-7a299bb8f929)

##100 concurrent Users

###RPS(Requests per second): **12**
###Response time: 
--> median: **11000** ms
--> 95 %tile: **17000** ms (95% requests finish before this time)

####RPS
![RPS 100 users Sync Gunicorn](https://dev-to-uploads.s3.amazonaws.com/i/kljtptd43uxoffr146gv.png)

####Response Time
![Response time 100 users Sync Gunicorn](https://dev-to-uploads.s3.amazonaws.com/i/3lgvj3l2dyfah5e5uqs3.png)

##350 concurrent Users *(max supported with synchronous server)*

###RPS: **6**
###Response time: 
--> median: **25000** ms
--> 95 %tile: **30000** ms (95% requests finish before this time)

####RPS
![RPS 350 users Sync Gunicorn](https://dev-to-uploads.s3.amazonaws.com/i/of8zf6t2ods6l86i8lal.png)
####Response time
![Response time 350 users Sync Gunicorn](https://dev-to-uploads.s3.amazonaws.com/i/02o6s07hm937vwk7o9sp.png)

##400 concurrent users

*server started to respond with **ConnectionError** for 100% for requests*

#Asynchronous Gunicorn Server(*Gevent*) 
![Asynchronous Gunicorn Server](https://dev-to-uploads.s3.amazonaws.com/i/0gi1wvmav0snlos99djb.jpeg)
######[credits](https://medium.com/@nhudinhtuan/gunicorn-worker-types-practice-advice-for-better-performance-7a299bb8f929)
##*100 concurrent Users*

###RPS: **50**
###Response time: 
--> median: **2200** ms
--> 95 %tile: **5000** ms (95% requests finish before this time)

####RPS:
![RPS 100 users Async Gunicorn](https://dev-to-uploads.s3.amazonaws.com/i/a8sk2e2jot7sds3ug5dv.png)

####Response time:
![Response time 100 users Async Gunicorn](https://dev-to-uploads.s3.amazonaws.com/i/22beuhk65fgszuv5mp9i.png)

##*500 concurrent Users*

###RPS: **50**
###Response time: 
--> median: **6500** ms
--> 95 %tile: **18000** ms (95% requests finish before this time)

####RPS:
![RPS 500 users Async Gunicorn](https://dev-to-uploads.s3.amazonaws.com/i/qy3sz0z1zrvzjjtwr11q.png)

####Response time:
![Response time 500 users Async Gunicorn](https://dev-to-uploads.s3.amazonaws.com/i/24e38x2391a7rurltapr.png)

##*1000 concurrent Users*

###RPS: **~25-30**
###Response time: 
--> median: **20000** ms
--> 95 %tile: **50000** ms (95% requests finish before this time)

####RPS:
![RPS 1000 users Async Gunicorn](https://dev-to-uploads.s3.amazonaws.com/i/k0f33ylb7plnyp404lry.png)

####Response time:
![Response time 1000 users Async Gunicorn](https://dev-to-uploads.s3.amazonaws.com/i/yb23y10ygryps7ycvcyu.png)


#Observations:
1) **RPS** starts to **decrease** with **increased load**.
2) **RPS** **increased** by at least **400%** in **Async** server.
3) With the **same** number of **users** response time was just **20%** in the case of the async server (**500%** better performance).
4) with the **same** response time **async** server was able to serve **400%** more users than **sync** server. (**500** users in async vs **100** users in sync).