github.com/uchennaokeke444/nomad@v0.11.8/nomad/structs/config/limits.go (about)

     1  package config
     2  
     3  import "github.com/hashicorp/nomad/helper"
     4  
     5  const (
     6  	// LimitsNonStreamingConnsPerClient is the number of connections per
     7  	// peer to reserve for non-streaming RPC connections. Since streaming
     8  	// RPCs require their own TCP connection, they have their own limit
     9  	// this amount lower than the overall limit. This reserves a number of
    10  	// connections for Raft and other RPCs.
    11  	//
    12  	// TODO Remove limit once MultiplexV2 is used.
    13  	LimitsNonStreamingConnsPerClient = 20
    14  )
    15  
    16  // Limits configures timeout limits similar to Consul's limits configuration
    17  // parameters. Limits is the internal version with the fields parsed.
    18  type Limits struct {
    19  	// HTTPSHandshakeTimeout is the deadline by which HTTPS TLS handshakes
    20  	// must complete.
    21  	//
    22  	// 0 means no timeout.
    23  	HTTPSHandshakeTimeout string `hcl:"https_handshake_timeout"`
    24  
    25  	// HTTPMaxConnsPerClient is the maximum number of concurrent HTTP
    26  	// connections from a single IP address. nil/0 means no limit.
    27  	HTTPMaxConnsPerClient *int `hcl:"http_max_conns_per_client"`
    28  
    29  	// RPCHandshakeTimeout is the deadline by which RPC handshakes must
    30  	// complete. The RPC handshake includes the first byte read as well as
    31  	// the TLS handshake and subsequent byte read if TLS is enabled.
    32  	//
    33  	// The deadline is reset after the first byte is read so when TLS is
    34  	// enabled RPC connections may take (timeout * 2) to complete.
    35  	//
    36  	// The RPC handshake timeout only applies to servers. 0 means no
    37  	// timeout.
    38  	RPCHandshakeTimeout string `hcl:"rpc_handshake_timeout"`
    39  
    40  	// RPCMaxConnsPerClient is the maximum number of concurrent RPC
    41  	// connections from a single IP address. nil/0 means no limit.
    42  	RPCMaxConnsPerClient *int `hcl:"rpc_max_conns_per_client"`
    43  }
    44  
    45  // DefaultLimits returns the default limits values. User settings should be
    46  // merged into these defaults.
    47  func DefaultLimits() Limits {
    48  	return Limits{
    49  		HTTPSHandshakeTimeout: "5s",
    50  		HTTPMaxConnsPerClient: helper.IntToPtr(100),
    51  		RPCHandshakeTimeout:   "5s",
    52  		RPCMaxConnsPerClient:  helper.IntToPtr(100),
    53  	}
    54  }
    55  
    56  // Merge returns a new Limits where non-empty/nil fields in the argument have
    57  // precedence.
    58  func (l *Limits) Merge(o Limits) Limits {
    59  	m := *l
    60  
    61  	if o.HTTPSHandshakeTimeout != "" {
    62  		m.HTTPSHandshakeTimeout = o.HTTPSHandshakeTimeout
    63  	}
    64  	if o.HTTPMaxConnsPerClient != nil {
    65  		m.HTTPMaxConnsPerClient = helper.IntToPtr(*o.HTTPMaxConnsPerClient)
    66  	}
    67  	if o.RPCHandshakeTimeout != "" {
    68  		m.RPCHandshakeTimeout = o.RPCHandshakeTimeout
    69  	}
    70  	if o.RPCMaxConnsPerClient != nil {
    71  		m.RPCMaxConnsPerClient = helper.IntToPtr(*o.RPCMaxConnsPerClient)
    72  	}
    73  
    74  	return m
    75  }
    76  
    77  // Copy returns a new deep copy of a Limits struct.
    78  func (l *Limits) Copy() Limits {
    79  	c := *l
    80  	if l.HTTPMaxConnsPerClient != nil {
    81  		c.HTTPMaxConnsPerClient = helper.IntToPtr(*l.HTTPMaxConnsPerClient)
    82  	}
    83  	if l.RPCMaxConnsPerClient != nil {
    84  		c.RPCMaxConnsPerClient = helper.IntToPtr(*l.RPCMaxConnsPerClient)
    85  	}
    86  	return c
    87  }