Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 The process bootstrap slow when many routes #1081

Closed
huangciyin opened this issue Dec 18, 2020 · 5 comments
Closed

🐛 The process bootstrap slow when many routes #1081

huangciyin opened this issue Dec 18, 2020 · 5 comments

Comments

@huangciyin
Copy link

Fiber version
2.0.0
Issue description
When we have many routes(eg >1000), the process start very slow(>10s).
Bootstrap speed is important for serverless environment.
Code snippet

package main

import (
	"fmt"
	"log"
	"strconv"

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

func main() {
	// Fiber instance
	app := fiber.New()

	for i := 0; i < 1000; i++ {
		url := "/b/" + strconv.Itoa(i)
		fmt.Println(url)
		app.Get(url, hello)
	}

	for i := 0; i < 1000; i++ {
		url := "/c/" + strconv.Itoa(i)
		fmt.Println(url)
		app.Get(url, hello)
	}

	// Routes
	app.Get("/", hello)

	// Start server
	log.Fatal(app.Listen(":3000"))
}

// Handler
func hello(c *fiber.Ctx) error {
	return c.SendString("Hello")
}
@huangciyin huangciyin changed the title 🐛 start slow when many routes, 🐛 start slow when many routes Dec 18, 2020
@huangciyin huangciyin changed the title 🐛 start slow when many routes 🐛 The process bootstrap slow when many routes Dec 18, 2020
@ReneWerner87
Copy link
Member

thanks for the report, we will have a look at it and already have an idea where the problem might be, if this is confirmed we can serve with a pull request in a few days, so it should probably be fixed in the next release.

@ReneWerner87
Copy link
Member

We will work on it in the new year(january)

@ReneWerner87
Copy link
Member

with 4002 handlers
image

with 2 handlers
image

you are right with the 4000 routes the start process takes quite a bit longer

I will try to optimize this

@ReneWerner87
Copy link
Member

ReneWerner87 commented Jan 24, 2021

After my changed:
with 4002 handler -> from ~2.3seconds to ~4ms

PR here: #1134

with 4002 handlers:
image

with 2 handlers:
image

Fenny added a commit that referenced this issue Jan 25, 2021
…_routes

⚡ Accelerate start process for many routes #1081
@Fenny
Copy link
Member

Fenny commented Jan 31, 2021

@Fenny Fenny closed this as completed Jan 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants