Skip to content

Commit cb97fbe

Browse files
authored
Merge pull request #332 from gatewayd-io/remove-hard-and-soft-limits
Remove hard and soft limits
2 parents 97723e4 + 7f4a7f4 commit cb97fbe

File tree

8 files changed

+2
-61
lines changed

8 files changed

+2
-61
lines changed

api/api.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,6 @@ func (a *API) GetServers(context.Context, *emptypb.Empty) (*structpb.Struct, err
165165
"network": server.Network,
166166
"address": server.Address,
167167
"status": uint(server.Status),
168-
"softLimit": server.SoftLimit,
169-
"hardLimit": server.HardLimit,
170168
"tickInterval": server.TickInterval.Nanoseconds(),
171169
}
172170
}

cmd/run.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ var runCmd = &cobra.Command{
440440
attribute.String("address", client.Address),
441441
attribute.Int("receiveChunkSize", client.ReceiveChunkSize),
442442
attribute.String("receiveDeadline", client.ReceiveDeadline.String()),
443+
attribute.String("receiveTimeout", client.ReceiveTimeout.String()),
443444
attribute.String("sendDeadline", client.SendDeadline.String()),
444445
attribute.Bool("tcpKeepAlive", client.TCPKeepAlive),
445446
attribute.String("tcpKeepAlivePeriod", client.TCPKeepAlivePeriod.String()),
@@ -460,6 +461,7 @@ var runCmd = &cobra.Command{
460461
"address": client.Address,
461462
"receiveChunkSize": client.ReceiveChunkSize,
462463
"receiveDeadline": client.ReceiveDeadline.String(),
464+
"receiveTimeout": client.ReceiveTimeout.String(),
463465
"sendDeadline": client.SendDeadline.String(),
464466
"tcpKeepAlive": client.TCPKeepAlive,
465467
"tcpKeepAlivePeriod": client.TCPKeepAlivePeriod.String(),
@@ -554,13 +556,10 @@ var runCmd = &cobra.Command{
554556
// Create and initialize servers.
555557
for name, cfg := range conf.Global.Servers {
556558
logger := loggers[name]
557-
softLimit, hardLimit := cfg.GetRLimits(logger)
558559
servers[name] = network.NewServer(
559560
runCtx,
560561
cfg.Network,
561562
cfg.Address,
562-
softLimit,
563-
hardLimit,
564563
cfg.GetTickInterval(),
565564
[]gnet.Option{
566565
// Scheduling options
@@ -597,8 +596,6 @@ var runCmd = &cobra.Command{
597596
attribute.String("name", name),
598597
attribute.String("network", cfg.Network),
599598
attribute.String("address", cfg.Address),
600-
attribute.Int64("softLimit", int64(cfg.SoftLimit)),
601-
attribute.Int64("hardLimit", int64(cfg.HardLimit)),
602599
attribute.String("tickInterval", cfg.TickInterval.String()),
603600
attribute.Bool("multiCore", cfg.MultiCore),
604601
attribute.Bool("lockOSThread", cfg.LockOSThread),

config/config.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ func (c *Config) LoadDefaults(ctx context.Context) {
130130
defaultServer := Server{
131131
Network: DefaultListenNetwork,
132132
Address: DefaultListenAddress,
133-
SoftLimit: 0,
134-
HardLimit: 0,
135133
EnableTicker: false,
136134
TickInterval: DefaultTickInterval,
137135
MultiCore: true,

config/getters_unix.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ package config
55

66
import (
77
"log/syslog"
8-
"syscall"
9-
10-
"github.com/rs/zerolog"
118
)
129

1310
var rSyslogPriorities = map[string]syslog.Priority{
@@ -28,25 +25,3 @@ func (l Logger) GetSyslogPriority() syslog.Priority {
2825
}
2926
return syslog.LOG_DAEMON | syslog.LOG_INFO
3027
}
31-
32-
// GetSystemLimits returns the current system limits or the configured limits.
33-
func (s Server) GetRLimits(logger zerolog.Logger) (uint64, uint64) {
34-
var limits syscall.Rlimit
35-
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limits); err != nil {
36-
logger.Debug().Msg("failed to get system limits")
37-
}
38-
39-
if s.SoftLimit <= 0 && limits != (syscall.Rlimit{}) {
40-
s.SoftLimit = limits.Cur
41-
logger.Debug().Uint64("soft_limit", s.SoftLimit).Msg(
42-
"Soft limit is not set, using system limit")
43-
}
44-
45-
if s.HardLimit <= 0 && limits != (syscall.Rlimit{}) {
46-
s.HardLimit = limits.Max
47-
logger.Debug().Uint64("hard_limit", s.HardLimit).Msg(
48-
"Hard limit is not set, using system limit")
49-
}
50-
51-
return s.HardLimit, s.SoftLimit
52-
}

config/types.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ type Server struct {
9494
WriteBufferCap int `json:"writeBufferCap"`
9595
SocketRecvBuffer int `json:"socketRecvBuffer"`
9696
SocketSendBuffer int `json:"socketSendBuffer"`
97-
SoftLimit uint64 `json:"softLimit"`
98-
HardLimit uint64 `json:"hardLimit"`
9997
TCPKeepAlive time.Duration `json:"tcpKeepAlive" jsonschema:"oneof_type=string;integer"`
10098
TickInterval time.Duration `json:"tickInterval" jsonschema:"oneof_type=string;integer"`
10199
Network string `json:"network" jsonschema:"enum=tcp,enum=udp,enum=unix"`

gatewayd.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ servers:
5050
default:
5151
network: tcp
5252
address: 0.0.0.0:15432
53-
softLimit: 0 # 0 means honor system limit
54-
hardLimit: 0 # 0 means honor system limit
5553
enableTicker: False
5654
tickInterval: 5s # duration
5755
multiCore: True

network/server.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ type Server struct {
3131
Network string // tcp/udp/unix
3232
Address string
3333
Options []gnet.Option
34-
SoftLimit uint64
35-
HardLimit uint64
3634
Status config.Status
3735
TickInterval time.Duration
3836
}
@@ -106,22 +104,6 @@ func (s *Server) OnOpen(gconn gnet.Conn) ([]byte, gnet.Action) {
106104
}
107105
span.AddEvent("Ran the OnOpening hooks")
108106

109-
// Check if the server is at the soft or hard limit.
110-
// TODO: Get rid the hard/soft limit.
111-
if s.SoftLimit > 0 && uint64(s.engine.CountConnections()) >= s.SoftLimit {
112-
s.logger.Warn().Msg("Soft limit reached")
113-
}
114-
115-
if s.HardLimit > 0 && uint64(s.engine.CountConnections()) >= s.HardLimit {
116-
s.logger.Error().Msg("Hard limit reached")
117-
_, err := gconn.Write([]byte("Hard limit reached\n"))
118-
if err != nil {
119-
s.logger.Error().Err(err).Msg("Failed to write to connection")
120-
span.RecordError(err)
121-
}
122-
return nil, gnet.Close
123-
}
124-
125107
// Use the proxy to connect to the backend. Close the connection if the pool is exhausted.
126108
// This effectively get a connection from the pool and puts both the incoming and the server
127109
// connections in the pool of the busy connections.
@@ -417,7 +399,6 @@ func (s *Server) IsRunning() bool {
417399
func NewServer(
418400
ctx context.Context,
419401
network, address string,
420-
softLimit, hardLimit uint64,
421402
tickInterval time.Duration,
422403
options []gnet.Option,
423404
proxy IProxy,
@@ -436,8 +417,6 @@ func NewServer(
436417
Options: options,
437418
TickInterval: tickInterval,
438419
Status: config.Stopped,
439-
HardLimit: hardLimit,
440-
SoftLimit: softLimit,
441420
proxy: proxy,
442421
logger: logger,
443422
pluginRegistry: pluginRegistry,

network/server_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,6 @@ func TestRunServer(t *testing.T) {
172172
context.Background(),
173173
"tcp",
174174
"127.0.0.1:15432",
175-
0,
176-
0,
177175
config.DefaultTickInterval,
178176
[]gnet.Option{
179177
gnet.WithMulticore(false),

0 commit comments

Comments
 (0)