Home

Awesome

limiter (This is a community driven project)

Adaptive Algorithm for Hertz

This project is inspired by kratos limiter. Thanks to their project.

Algorithm core

      The CPU load is collected by reading /proc/stat, and the CPU load is judged to trigger the flow restriction condition.

How to use?

  1. Set middleware
    h := server.Default()
    h.Use(limiter.AdaptiveLimit())
  1. Run example code
import (
	"context"

	"github.com/cloudwego/hertz/pkg/app"
	"github.com/cloudwego/hertz/pkg/app/server"
	"github.com/cloudwego/hertz/pkg/protocol/consts"
	"github.com/hertz-contrib/limiter"
)

func main() {
	h := server.Default(server.WithHostPorts(":1000"))
	h.Use(limiter.AdaptiveLimit())
	h.GET("/hello", func(c context.Context, ctx *app.RequestContext) {
		ctx.String(consts.StatusOK, "hello")
	})
	h.Spin()
}