Skip to content

Commit

Permalink
Merge pull request #332 from gatewayd-io/remove-hard-and-soft-limits
Browse files Browse the repository at this point in the history
Remove hard and soft limits
  • Loading branch information
mostafa authored Sep 24, 2023
2 parents 97723e4 + 7f4a7f4 commit cb97fbe
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 61 deletions.
2 changes: 0 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ func (a *API) GetServers(context.Context, *emptypb.Empty) (*structpb.Struct, err
"network": server.Network,
"address": server.Address,
"status": uint(server.Status),
"softLimit": server.SoftLimit,
"hardLimit": server.HardLimit,
"tickInterval": server.TickInterval.Nanoseconds(),
}
}
Expand Down
7 changes: 2 additions & 5 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ var runCmd = &cobra.Command{
attribute.String("address", client.Address),
attribute.Int("receiveChunkSize", client.ReceiveChunkSize),
attribute.String("receiveDeadline", client.ReceiveDeadline.String()),
attribute.String("receiveTimeout", client.ReceiveTimeout.String()),
attribute.String("sendDeadline", client.SendDeadline.String()),
attribute.Bool("tcpKeepAlive", client.TCPKeepAlive),
attribute.String("tcpKeepAlivePeriod", client.TCPKeepAlivePeriod.String()),
Expand All @@ -460,6 +461,7 @@ var runCmd = &cobra.Command{
"address": client.Address,
"receiveChunkSize": client.ReceiveChunkSize,
"receiveDeadline": client.ReceiveDeadline.String(),
"receiveTimeout": client.ReceiveTimeout.String(),
"sendDeadline": client.SendDeadline.String(),
"tcpKeepAlive": client.TCPKeepAlive,
"tcpKeepAlivePeriod": client.TCPKeepAlivePeriod.String(),
Expand Down Expand Up @@ -554,13 +556,10 @@ var runCmd = &cobra.Command{
// Create and initialize servers.
for name, cfg := range conf.Global.Servers {
logger := loggers[name]
softLimit, hardLimit := cfg.GetRLimits(logger)
servers[name] = network.NewServer(
runCtx,
cfg.Network,
cfg.Address,
softLimit,
hardLimit,
cfg.GetTickInterval(),
[]gnet.Option{
// Scheduling options
Expand Down Expand Up @@ -597,8 +596,6 @@ var runCmd = &cobra.Command{
attribute.String("name", name),
attribute.String("network", cfg.Network),
attribute.String("address", cfg.Address),
attribute.Int64("softLimit", int64(cfg.SoftLimit)),
attribute.Int64("hardLimit", int64(cfg.HardLimit)),
attribute.String("tickInterval", cfg.TickInterval.String()),
attribute.Bool("multiCore", cfg.MultiCore),
attribute.Bool("lockOSThread", cfg.LockOSThread),
Expand Down
2 changes: 0 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ func (c *Config) LoadDefaults(ctx context.Context) {
defaultServer := Server{
Network: DefaultListenNetwork,
Address: DefaultListenAddress,
SoftLimit: 0,
HardLimit: 0,
EnableTicker: false,
TickInterval: DefaultTickInterval,
MultiCore: true,
Expand Down
25 changes: 0 additions & 25 deletions config/getters_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ package config

import (
"log/syslog"
"syscall"

"github.com/rs/zerolog"
)

var rSyslogPriorities = map[string]syslog.Priority{
Expand All @@ -28,25 +25,3 @@ func (l Logger) GetSyslogPriority() syslog.Priority {
}
return syslog.LOG_DAEMON | syslog.LOG_INFO
}

// GetSystemLimits returns the current system limits or the configured limits.
func (s Server) GetRLimits(logger zerolog.Logger) (uint64, uint64) {
var limits syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limits); err != nil {
logger.Debug().Msg("failed to get system limits")
}

if s.SoftLimit <= 0 && limits != (syscall.Rlimit{}) {
s.SoftLimit = limits.Cur
logger.Debug().Uint64("soft_limit", s.SoftLimit).Msg(
"Soft limit is not set, using system limit")
}

if s.HardLimit <= 0 && limits != (syscall.Rlimit{}) {
s.HardLimit = limits.Max
logger.Debug().Uint64("hard_limit", s.HardLimit).Msg(
"Hard limit is not set, using system limit")
}

return s.HardLimit, s.SoftLimit
}
2 changes: 0 additions & 2 deletions config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ type Server struct {
WriteBufferCap int `json:"writeBufferCap"`
SocketRecvBuffer int `json:"socketRecvBuffer"`
SocketSendBuffer int `json:"socketSendBuffer"`
SoftLimit uint64 `json:"softLimit"`
HardLimit uint64 `json:"hardLimit"`
TCPKeepAlive time.Duration `json:"tcpKeepAlive" jsonschema:"oneof_type=string;integer"`
TickInterval time.Duration `json:"tickInterval" jsonschema:"oneof_type=string;integer"`
Network string `json:"network" jsonschema:"enum=tcp,enum=udp,enum=unix"`
Expand Down
2 changes: 0 additions & 2 deletions gatewayd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ servers:
default:
network: tcp
address: 0.0.0.0:15432
softLimit: 0 # 0 means honor system limit
hardLimit: 0 # 0 means honor system limit
enableTicker: False
tickInterval: 5s # duration
multiCore: True
Expand Down
21 changes: 0 additions & 21 deletions network/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ type Server struct {
Network string // tcp/udp/unix
Address string
Options []gnet.Option
SoftLimit uint64
HardLimit uint64
Status config.Status
TickInterval time.Duration
}
Expand Down Expand Up @@ -106,22 +104,6 @@ func (s *Server) OnOpen(gconn gnet.Conn) ([]byte, gnet.Action) {
}
span.AddEvent("Ran the OnOpening hooks")

// Check if the server is at the soft or hard limit.
// TODO: Get rid the hard/soft limit.
if s.SoftLimit > 0 && uint64(s.engine.CountConnections()) >= s.SoftLimit {
s.logger.Warn().Msg("Soft limit reached")
}

if s.HardLimit > 0 && uint64(s.engine.CountConnections()) >= s.HardLimit {
s.logger.Error().Msg("Hard limit reached")
_, err := gconn.Write([]byte("Hard limit reached\n"))
if err != nil {
s.logger.Error().Err(err).Msg("Failed to write to connection")
span.RecordError(err)
}
return nil, gnet.Close
}

// Use the proxy to connect to the backend. Close the connection if the pool is exhausted.
// This effectively get a connection from the pool and puts both the incoming and the server
// connections in the pool of the busy connections.
Expand Down Expand Up @@ -417,7 +399,6 @@ func (s *Server) IsRunning() bool {
func NewServer(
ctx context.Context,
network, address string,
softLimit, hardLimit uint64,
tickInterval time.Duration,
options []gnet.Option,
proxy IProxy,
Expand All @@ -436,8 +417,6 @@ func NewServer(
Options: options,
TickInterval: tickInterval,
Status: config.Stopped,
HardLimit: hardLimit,
SoftLimit: softLimit,
proxy: proxy,
logger: logger,
pluginRegistry: pluginRegistry,
Expand Down
2 changes: 0 additions & 2 deletions network/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ func TestRunServer(t *testing.T) {
context.Background(),
"tcp",
"127.0.0.1:15432",
0,
0,
config.DefaultTickInterval,
[]gnet.Option{
gnet.WithMulticore(false),
Expand Down

0 comments on commit cb97fbe

Please sign in to comment.