Skip to content

Commit

Permalink
Improved throttling
Browse files Browse the repository at this point in the history
  • Loading branch information
ironbeer committed Feb 15, 2024
1 parent 1d4d529 commit d377fff
Show file tree
Hide file tree
Showing 6 changed files with 456 additions and 215 deletions.
57 changes: 35 additions & 22 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ var (
defaults = map[string]interface{}{
"verse_layer.discovery.refresh_interval": time.Hour,

"p2p.publish_interval": 5 * time.Minute,
"p2p.stream_timeout": 10 * time.Second,
"p2p.no_announce": []string{
"/ip4/127.0.0.1/ipcidr/8",
"/ip4/10.0.0.0/ipcidr/8",
Expand All @@ -32,14 +30,19 @@ var (
"/ip4/172.16.0.0/ipcidr/12",
"/ip4/192.168.0.0/ipcidr/16",
},
"p2p.transports.tcp": true,
"p2p.transports.quic": true,
"p2p.nat.upnp": true,
"p2p.nat.autonat": true,
"p2p.nat.holepunch": true,
"p2p.relay_client.enable": true,
"p2p.experimental.concurrency": 40,
"p2p.experimental.sig_send_throttling": 2000,
"p2p.transports.tcp": true,
"p2p.transports.quic": true,
"p2p.nat.upnp": true,
"p2p.nat.autonat": true,
"p2p.nat.holepunch": true,
"p2p.relay_client.enable": true,
"p2p.publish_interval": 5 * time.Minute,
"p2p.stream_timeout": 10 * time.Second,
"p2p.outbound_limits.concurrency": 10,
"p2p.outbound_limits.throttling": 500,
"p2p.inbound_limits.concurrency": 10,
"p2p.inbound_limits.throttling": 500,
"p2p.inbound_limits.max_send_time": 30 * time.Second,

"ipc.sockname": "oasvlfy",

Expand Down Expand Up @@ -240,12 +243,6 @@ type P2P struct {
// Deprecated: Address and port to listen.
Listen string `json:"listen" validate:"omitempty,hostname_port"`

// Interval to publish own signature status.
PublishInterval time.Duration `json:"publish_interval" mapstructure:"publish_interval"`

// Timeout for P2P stream communication.
StreamTimeout time.Duration `json:"stream_timeout" mapstructure:"stream_timeout"`

// Initial node list.
Bootnodes []string `json:"bootnodes"`

Expand Down Expand Up @@ -290,14 +287,30 @@ type P2P struct {
RelayNodes []string `json:"relay_nodes" mapstructure:"relay_nodes"`
} `json:"relay_client" mapstructure:"relay_client"`

// Configuration for experimental features.
Experimental struct {
// Number of concurrent executions.
// Interval to publish own signature status.
PublishInterval time.Duration `json:"publish_interval" mapstructure:"publish_interval"`

// Timeout for P2P stream communication.
StreamTimeout time.Duration `json:"stream_timeout" mapstructure:"stream_timeout"`

OutboundLimits struct {
// Maximum number of concurrent signature requests from oneself to peers.
Concurrency int `json:"concurrency"`

// Number of signatures that can be sent per second.
SigSendThrottling int `json:"sig_send_throttling" mapstructure:"sig_send_throttling"`
} `json:"experimental"`
// The number of signatures that can be sent to peers per second.
Throttling int `json:"throttling"`
} `json:"outbound_limits" mapstructure:"outbound_limits"`

InboundLimits struct {
// Maximum number of concurrent signature requests from peers to oneself.
Concurrency int `json:"concurrency"`

// The number of signatures that can be sent to peers per second.
Throttling int `json:"throttling"`

// Maximum time to send signatures to a peer.
MaxSendTime time.Duration `json:"max_send_time" mapstructure:"max_send_time"`
} `json:"inbound_limits" mapstructure:"inbound_limits"`
}

type IPC struct {
Expand Down
39 changes: 24 additions & 15 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ func (s *ConfigTestSuite) TestParseConfig() {
- noann0
connection_filter:
- connfil0
publish_interval: 5s
stream_timeout: 5s
bootnodes:
- /ip4/127.0.0.1/tcp/20002/p2p/12D3KooWCNqRgVdwAhGrurCc8XE4RsWB8S2T83yMZR9R7Gdtf899
relay_service:
Expand All @@ -69,7 +67,6 @@ func (s *ConfigTestSuite) TestParseConfig() {
max_reservations_per_asn: 9
relay_client:
relay_nodes: ["relay-0", "relay-1"]
enable_hole_punching: true
ipc:
sockname: testsock
Expand Down Expand Up @@ -177,9 +174,7 @@ func (s *ConfigTestSuite) TestParseConfig() {
TCP: true,
QUIC: true,
},
Listen: "",
PublishInterval: 5 * time.Second,
StreamTimeout: 5 * time.Second,
Listen: "",
Bootnodes: []string{
"/ip4/127.0.0.1/tcp/20002/p2p/12D3KooWCNqRgVdwAhGrurCc8XE4RsWB8S2T83yMZR9R7Gdtf899",
},
Expand Down Expand Up @@ -222,12 +217,23 @@ func (s *ConfigTestSuite) TestParseConfig() {
Enable: true,
RelayNodes: []string{"relay-0", "relay-1"},
},
Experimental: struct {
Concurrency int "json:\"concurrency\""
SigSendThrottling int "json:\"sig_send_throttling\" mapstructure:\"sig_send_throttling\""
PublishInterval: 5 * time.Minute,
StreamTimeout: 10 * time.Second,
OutboundLimits: struct {
Concurrency int "json:\"concurrency\""
Throttling int "json:\"throttling\""
}{
Concurrency: 40,
SigSendThrottling: 2000,
Concurrency: 10,
Throttling: 500,
},
InboundLimits: struct {
Concurrency int "json:\"concurrency\""
Throttling int "json:\"throttling\""
MaxSendTime time.Duration "json:\"max_send_time\" mapstructure:\"max_send_time\""
}{
Concurrency: 10,
Throttling: 500,
MaxSendTime: 30 * time.Second,
},
}, got.P2P)

Expand Down Expand Up @@ -399,13 +405,16 @@ func (s *ConfigTestSuite) TestDefaultValues() {
}, got.P2P.ConnectionFilter)
s.Equal(true, got.P2P.Transports.TCP)
s.Equal(true, got.P2P.Transports.QUIC)
s.Equal(5*time.Minute, got.P2P.PublishInterval)
s.Equal(10*time.Second, got.P2P.StreamTimeout)
s.Equal(true, got.P2P.NAT.UPnP)
s.Equal(true, got.P2P.NAT.AutoNAT)
s.Equal(true, got.P2P.NAT.HolePunch)
s.Equal(40, got.P2P.Experimental.Concurrency)
s.Equal(2000, got.P2P.Experimental.SigSendThrottling)
s.Equal(5*time.Minute, got.P2P.PublishInterval)
s.Equal(10*time.Second, got.P2P.StreamTimeout)
s.Equal(10, got.P2P.OutboundLimits.Concurrency)
s.Equal(500, got.P2P.OutboundLimits.Throttling)
s.Equal(10, got.P2P.InboundLimits.Concurrency)
s.Equal(500, got.P2P.InboundLimits.Throttling)
s.Equal(30*time.Second, got.P2P.InboundLimits.MaxSendTime)

s.Equal("oasvlfy", got.IPC.Sockname)

Expand Down
Loading

0 comments on commit d377fff

Please sign in to comment.