From 7f4a7f45fc1d4c2594448b936dd5a43f0edceb52 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Sun, 24 Sep 2023 13:00:13 +0200 Subject: [PATCH] Remove soft and hard limits --- api/api.go | 2 -- cmd/run.go | 5 ----- config/config.go | 2 -- config/getters_unix.go | 25 ------------------------- config/types.go | 2 -- gatewayd.yaml | 2 -- network/server.go | 21 --------------------- network/server_test.go | 2 -- 8 files changed, 61 deletions(-) diff --git a/api/api.go b/api/api.go index 1e476555..d7e8915b 100644 --- a/api/api.go +++ b/api/api.go @@ -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(), } } diff --git a/cmd/run.go b/cmd/run.go index fcf15d62..ea0bfaf3 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -556,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 @@ -599,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), diff --git a/config/config.go b/config/config.go index 7632294c..c1abc8d1 100644 --- a/config/config.go +++ b/config/config.go @@ -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, diff --git a/config/getters_unix.go b/config/getters_unix.go index feb28302..a4904a5a 100644 --- a/config/getters_unix.go +++ b/config/getters_unix.go @@ -5,9 +5,6 @@ package config import ( "log/syslog" - "syscall" - - "github.com/rs/zerolog" ) var rSyslogPriorities = map[string]syslog.Priority{ @@ -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 -} diff --git a/config/types.go b/config/types.go index 9f7ddcbe..a4785e37 100644 --- a/config/types.go +++ b/config/types.go @@ -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"` diff --git a/gatewayd.yaml b/gatewayd.yaml index f02eabaa..174343c2 100644 --- a/gatewayd.yaml +++ b/gatewayd.yaml @@ -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 diff --git a/network/server.go b/network/server.go index bfa7a48d..cfba1da2 100644 --- a/network/server.go +++ b/network/server.go @@ -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 } @@ -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. @@ -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, @@ -436,8 +417,6 @@ func NewServer( Options: options, TickInterval: tickInterval, Status: config.Stopped, - HardLimit: hardLimit, - SoftLimit: softLimit, proxy: proxy, logger: logger, pluginRegistry: pluginRegistry, diff --git a/network/server_test.go b/network/server_test.go index 676e9cb6..2a3028c6 100644 --- a/network/server_test.go +++ b/network/server_test.go @@ -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),