Skip to content

Commit

Permalink
remove server max_concurrent_queries_pre_client
Browse files Browse the repository at this point in the history
  • Loading branch information
IrineSistiana committed Feb 8, 2021
1 parent 473da64 commit 7a1bca9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 34 deletions.
27 changes: 1 addition & 26 deletions dispatcher/pkg/server_handler/server_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,8 @@ type DefaultServerHandlerConfig struct {
// If ConcurrentLimit <= 0, means no limit.
// When calling DefaultServerHandler.ServeDNS(), if a query exceeds the limit, it will wait on a FIFO queue until
// - its ctx is done -> The query will be dropped silently.
// - it can be proceed -> Normal procedure.
// - it can be proceeded -> Normal procedure.
ConcurrentLimit int

// ConcurrentLimitPreClient controls the max concurrent queries for the pre client.
// If ConcurrentLimitPreClient <= 0, means no limit.
// It uses qCtx.From() as the identification of clients.
// When calling DefaultServerHandler.ServeDNS(), if a client query exceeds the limit,
// an REFUSED response will be returned to client.
ConcurrentLimitPreClient int
}

// NewDefaultServerHandler
Expand All @@ -73,9 +66,6 @@ func NewDefaultServerHandler(config *DefaultServerHandlerConfig) *DefaultServerH
h.limiter = concurrent_limiter.NewConcurrentLimiter(config.ConcurrentLimit)
}

if config.ConcurrentLimitPreClient > 0 {
h.clientLimiter = concurrent_limiter.NewClientQueryLimiter(config.ConcurrentLimitPreClient)
}
return h
}

Expand All @@ -89,21 +79,6 @@ func (h *DefaultServerHandler) ServeDNS(ctx context.Context, qCtx *handler.Conte
}
}

if h.clientLimiter != nil {
addr := qCtx.From()
if addr != nil {
key := addr.String()
if h.clientLimiter.Acquire(key) != true {
r := new(dns.Msg)
r.SetReply(qCtx.Q())
r.Rcode = dns.RcodeRefused
write(r)
return
}
defer h.clientLimiter.Done(key)
}
}

if h.limiter != nil {
select {
case <-h.limiter.Wait():
Expand Down
14 changes: 6 additions & 8 deletions dispatcher/plugin/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ type ServerGroup struct {
}

type Args struct {
Server []*Server `yaml:"server"`
Entry []interface{} `yaml:"entry"`
MaxConcurrentQueries int `yaml:"max_concurrent_queries"`
MaxConcurrentQueriesPreClient int `yaml:"max_concurrent_queries_pre_client"`
Server []*Server `yaml:"server"`
Entry []interface{} `yaml:"entry"`
MaxConcurrentQueries int `yaml:"max_concurrent_queries"`
}

// Server is not safe for concurrent use.
Expand Down Expand Up @@ -106,10 +105,9 @@ func newServerPlugin(bp *handler.BP, args *Args) (*ServerGroup, error) {
}

sh := server_handler.NewDefaultServerHandler(&server_handler.DefaultServerHandlerConfig{
Logger: bp.L(),
Entry: ecs,
ConcurrentLimit: args.MaxConcurrentQueries,
ConcurrentLimitPreClient: args.MaxConcurrentQueriesPreClient,
Logger: bp.L(),
Entry: ecs,
ConcurrentLimit: args.MaxConcurrentQueries,
})

sg := NewServerGroup(bp, sh, args.Server)
Expand Down

0 comments on commit 7a1bca9

Please sign in to comment.