gofiber / adaptor

🧬 Adaptor middleware to convert net/http handlers from/to Fiber request handlers
MIT License
181 stars 11 forks source link

Does adaptor.FiberApp(app) incur heavy performance penalties? #133

Closed figuerom16 closed 1 year ago

figuerom16 commented 1 year ago

I'm interested in using NGINX Unit as the app server https://unit.nginx.org/. The handler is expecting the net/http handler so the adaptor.FiberApp(app) is needed. The question is does the adaptor create a small consistent overhead or does the adaptor negate all the benefits of fasthttp?

Example: https://unit.nginx.org/howto/samples/#sample-go

package main

import (
    "github.com/gofiber/adaptor/v2"
    "github.com/gofiber/fiber/v2"
    unit "unit.nginx.org/go"
)

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

    app.Get("/", func(c *fiber.Ctx) error {
        return c.SendString("Hello, World!")
    })

    unit.ListenAndServe(":80", adaptor.FiberApp(app))
}
leonklingele commented 1 year ago

does the adaptor create a small consistent overhead

Yeah, there is a bit of an overhead involved. See the relevant ConvertRequest func (which btw. is now part of the fiber adaptor middleware as well) to convert a fiber.Ctx request to a (net/http).Request: https://github.com/valyala/fasthttp/blob/9bc8e480c444fa6bf54a4cd79091692ceff6011c/fasthttpadaptor/request.go#L18

The overhead is not big, but if performance is crucial, you need to set up benchmarks.