Commit ce8ee831 authored by Pieter Raubenheimer's avatar Pieter Raubenheimer Committed by Pieter Raubenheimer

Add check for per-host maximum connections

parent 741d7685
...@@ -27,6 +27,7 @@ type staticUpstream struct { ...@@ -27,6 +27,7 @@ type staticUpstream struct {
FailTimeout time.Duration FailTimeout time.Duration
MaxFails int32 MaxFails int32
MaxConns int64
HealthCheck struct { HealthCheck struct {
Path string Path string
Interval time.Duration Interval time.Duration
...@@ -47,6 +48,7 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) { ...@@ -47,6 +48,7 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) {
Policy: &Random{}, Policy: &Random{},
FailTimeout: 10 * time.Second, FailTimeout: 10 * time.Second,
MaxFails: 1, MaxFails: 1,
MaxConns: 0,
} }
if !c.Args(&upstream.from) { if !c.Args(&upstream.from) {
...@@ -78,6 +80,10 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) { ...@@ -78,6 +80,10 @@ func NewStaticUpstreams(c parse.Dispenser) ([]Upstream, error) {
ExtraHeaders: upstream.proxyHeaders, ExtraHeaders: upstream.proxyHeaders,
CheckDown: func(upstream *staticUpstream) UpstreamHostDownFunc { CheckDown: func(upstream *staticUpstream) UpstreamHostDownFunc {
return func(uh *UpstreamHost) bool { return func(uh *UpstreamHost) bool {
if upstream.MaxConns != 0 &&
uh.Conns >= upstream.MaxConns {
return true
}
if uh.Unhealthy { if uh.Unhealthy {
return true return true
} }
...@@ -147,6 +153,15 @@ func parseBlock(c *parse.Dispenser, u *staticUpstream) error { ...@@ -147,6 +153,15 @@ func parseBlock(c *parse.Dispenser, u *staticUpstream) error {
return err return err
} }
u.MaxFails = int32(n) u.MaxFails = int32(n)
case "max_conns":
if !c.NextArg() {
return c.ArgErr()
}
n, err := strconv.ParseInt(c.Val(), 10, 64)
if err != nil {
return err
}
u.MaxConns = n
case "health_check": case "health_check":
if !c.NextArg() { if !c.NextArg() {
return c.ArgErr() return c.ArgErr()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment