The test code

Sanic:

from sanic import Sanic
from sanic.response import json
from sanic.request import Request

app = Sanic("Demo Of Sanic")


@app.get("/")
async def test(request: Request):
    return json({'Hello': 'World'})


if __name__ == '__main__':
    app.run(workers=8)

Fiber:

package main

import (
    "github.com/gofiber/fiber/v2"
)

func main() {
    app := fiber.New()

    app.Get("/", func(c *fiber.Ctx) error {
        return c.JSON(map[string]string{
            "Hello": "World",
        })
    })

    app.Listen(":8000")
}

Pressure test

The program used for the pressure test is go-stress-testing, 1000 concurrency, 1000 requests per concurrency.

The corresponding fields for each column are:

Time │ Concurrency │ Success │ Failure │ QPS │ Longest Time │ Shortest Time │ Average Time │ Download bytes │ bytes per second │ error code

Sanic:

. 1, 2, 3, 3, 4, 5,0 folders,0 folders,0 folders,0 folders,0 folders,0 folders,0 folders,0 folders,0 folders,0 folders,0 folders,0 folders,0 folders,0 folders,0 folders,0 folders,0 folders,0 folders,0 folders,0 folders. The total number of files in total │ 0 folders, 0 folders, 0 folders, 0 folders, 0 folders, 0 folders, 0 folders, 0 folders 578.58│ 71.49│ 184.87, 016,919,726 │ 89,522│200:995278 │1000000│ 0, 5420.32│ 578.58│ 0.40│ 184.49, 17,000,000│ 89621 │ 200:1000000 * * * * * * * * * * * * * * * * * * * * * * * * * the stat * * * * * * * * * * * * * * * * * * * * * * * * * * * * processing coroutines quantity: 1000 the total number of requests (concurrency * * requests - c - n) : SuccessNum: 1000000 Failurenum: 0 TP90:235.000 TP95:299.000 TP99: SuccessNum: 1000000 Failurenum: 0 TP90:235.000 TP95:299.000 TP99: 387.000 * * * * * * * * * * * * * * * * * * * * * * * * * the end * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Fiber:

. 1 s 1000 4264 │ │ │ │ │ │ │ │ 202.26 103.75 428.17 4944.17 0 72488 │ │ 72486 200:4264... 100S │ 1000│ 994.53 │ 0 (6367.34, 628.17, 87.23, 157.05,863,184│ 105,394, 200:991952, 11s │ 1000│ 998890│ 0│ 6374.53 428.17│ 60.73│ ├ ─ 156.87, 16,981,130, 105,472│200:998890 161s, 1000 folders,0 folders, 6379.79 folders, 428.17 folders, 0.31 folders, 156.75 folders, 17,000,000 folders 105514 │ 200:1000000 * * * * * * * * * * * * * * * * * * * * * * * * * the stat * * * * * * * * * * * * * * * * * * * * * * * * * * * * processing coroutines quantity: 1000 the total number of requests (concurrency * * requests - c - n) : SuccessNum: 1000000 Failurenum: 0 TP90:175.000 TP95:182.000 TP99: SuccessNum: 1000000 Failurenum: 0 TP90:175.000 TP95:182.000 TP99: 198.000 * * * * * * * * * * * * * * * * * * * * * * * * * the end * * * * * * * * * * * * * * * * * * * * * * * * * * * *

As you can see, SANIC and Fiber are not very different. SANIC’s performance is almost equal to that of Fiber, which is probably the highest performing Python Web framework out there. Even the previously prominent asynchronous framework FastAPI lags behind SANIC.

Attached are the results of FastAPI:

. 1 s 1000 3140 │ │ │ │ │ │ │ │ 258.52 98.50 397.67 3868.18 0 53380 │ │ 52552 200:3140... 239S │ 1000│ 0│ 991225│ 87.20,850, 70,505, 0200 :991225, 995799│ 0│ 4257.07 557.98│ 87.20│ ├ ─ 70,535│200:995799 │1000, 00000│ 0, 4266.06, 557.98│ 0.79, 234.41, 17,000,000│ 70585 │ 200:1000000 * * * * * * * * * * * * * * * * * * * * * * * * * the stat * * * * * * * * * * * * * * * * * * * * * * * * * * * * processing coroutines quantity: 1000 the total number of requests (concurrency * * requests - c - n) : SuccessNum: 1000000 Failurenum: 0 TP90:279.000 TP95:296.000 TP99: SuccessNum: 1000000 Failurenum: 0 TP90:279.000 TP95:296.000 TP99: 348.000 * * * * * * * * * * * * * * * * * * * * * * * * * the end * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Frameworks like Flask and Django are beyond the scope of this article. They are not designed for high performance, and there is no point in comparing them.

Another advantage of SANIC is that it does not have a development server. The server running with SANIC-W 8 main.app is the production server.

If you want to develop a Web server in Python, it is recommended that SANIC be a priority, but FastAPI is quite adequate.