Skip to content

Fix #862: replaced Daphne by Gunicorn/Uvicorn

Agate requested to merge 862-uvicorn into develop

Closes #862 (closed)

In addition to the advantages described in the release notes, here is a small benchmark I've run on open.audio, with both Gunicorn/Uvicorn and Daphne. Gunicorn/Uvicorn perform significantly better and faster. Note that existing instances running with Daphne will continue to work.

cc @funkwhale/reviewers-python

Benchmark setup

  • Load-testing tool: Locust
  • Number of requests: 30 requests par second, dispatched between /api/v1/artists, /.well-known/nodeinfo and /api/v1/instance/nodeinfo/2.0/
  • Total requests: ~3000
  • Run on a VM with 1 CPU and 4GB of memory (CPU wasn't maxed in any test)

Benchmark code

# locust.py

from locust import HttpLocust, TaskSet, task

class WebsiteTasks(TaskSet):
    
    @task
    def artists(self):
        self.client.get("/api/v1/artists/")
        
    @task
    def wellknown(self):
        self.client.get("/.well-known/nodeinfo")

    @task
    def nodeinfo(self):
        self.client.get("/api/v1/instance/nodeinfo/2.0/")


class WebsiteUser(HttpLocust):
    task_set = WebsiteTasks
    min_wait = 3000
    max_wait = 10000

Run with locust -f locust.py -H https://yourfunkwhale.domain.

Benchmark results

Daphne

Web process run with: daphne -b 127.0.0.1 -p 5000 config.asgi:application --proxy-headers

Results:

 Name                                                          # reqs      # fails     Avg     Min     Max  |  Median   req/s
--------------------------------------------------------------------------------------------------------------------------------------------
 GET /.well-known/nodeinfo                                       1036     0(0.00%)     226      32    1631  |      90    7.30
 GET /api/v1/artists/                                            1055     0(0.00%)     565     110    3162  |     300    9.40
 GET /api/v1/instance/nodeinfo/2.0/                              1070     0(0.00%)     264      36    1768  |     120    9.40
--------------------------------------------------------------------------------------------------------------------------------------------
 Total                                                           3161     0(0.00%)                                      26.10

Percentage of the requests completed within given times
 Name                                                           # reqs    50%    66%    75%    80%    90%    95%    98%    99%   100%
--------------------------------------------------------------------------------------------------------------------------------------------
 GET /.well-known/nodeinfo                                        1036     90    160    210    270    680   1100   1300   1500   1600
 GET /api/v1/artists/                                             1055    300    400    540    740   1600   2300   2600   2800   3200
 GET /api/v1/instance/nodeinfo/2.0/                               1070    120    200    270    340    760   1100   1500   1600   1800
--------------------------------------------------------------------------------------------------------------------------------------------
 Total                                                            3161    180    270    360    450    980   1400   2100   2500   3200

Gunicorn/Uvicorn

Web process run with: gunicorn config.asgi:application -w 1 -k uvicorn.workers.UvicornWorker -b 127.0.0.1:5000

Results:


 Name                                                          # reqs      # fails     Avg     Min     Max  |  Median   req/s
--------------------------------------------------------------------------------------------------------------------------------------------
 GET /.well-known/nodeinfo                                       1016     0(0.00%)      88      32     375  |      61   10.10
 GET /api/v1/artists/                                            1030     0(0.00%)     253     107     753  |     220   10.20
 GET /api/v1/instance/nodeinfo/2.0/                               940     0(0.00%)     105      36     474  |      73   10.00
--------------------------------------------------------------------------------------------------------------------------------------------
 Total                                                           2986     0(0.00%)                                      30.30

Percentage of the requests completed within given times
 Name                                                           # reqs    50%    66%    75%    80%    90%    95%    98%    99%   100%
--------------------------------------------------------------------------------------------------------------------------------------------
 GET /.well-known/nodeinfo                                        1016     61     85    110    120    170    230    290    330    380
 GET /api/v1/artists/                                             1030    220    280    320    340    420    490    560    610    750
 GET /api/v1/instance/nodeinfo/2.0/                                940     73    110    140    150    210    270    320    360    470
--------------------------------------------------------------------------------------------------------------------------------------------
 Total                                                            2986    120    170    210    240    320    380    480    530    750

Results

As you can see, based on those results, Gunicorn/Uvicorn perform significantly better than Daphne:

Aggregated response time (lower is better)

Server Median 95% time 99% time
Daphne 180ms 1400ms 2500ms
Gunicorn/Uvicorn 120ms 380ms 530ms

Median response time per url (lower is better)

URL Gunicorn/Uvicorn Daphne
/.well-known/nodeinfo 71ms 90ms
/api/v1/artists/ 220ms 300ms
/api/v1/instance/nodeinfo/2.0/ 73ms 120ms
Edited by Agate

Merge request reports

Loading