Skip to content

Commit

Permalink
Revert "Make RPC concurrency configurable (#1214)"
Browse files Browse the repository at this point in the history
This reverts commit 2196b70.
  • Loading branch information
joshklop committed Sep 12, 2023
1 parent 2196b70 commit 9fadd74
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 37 deletions.
4 changes: 0 additions & 4 deletions cmd/juno/juno.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const (
metricsPortF = "metrics-port"
grpcF = "grpc"
grpcPortF = "grpc-port"
rpcMaxConcurrencyF = "rpc-max-concurrency"

defaultConfig = ""
defaultHTTP = false
Expand All @@ -69,7 +68,6 @@ const (
defaultMetricsPort = 9090
defaultGRPC = false
defaultGRPCPort = 6064
defaultRPCMaxConcurrency = 1024

configFlagUsage = "The yaml configuration file."
logLevelFlagUsage = "Options: debug, info, warn, error."
Expand All @@ -92,7 +90,6 @@ const (
metricsPortUsage = "The port on which the prometheus endpoint will listen for requests."
grpcUsage = "Enable the HTTP GRPC server on the default port."
grpcPortUsage = "The port on which the GRPC server will listen for requests."
rpcMaxConcurrencyUsage = "Maximum number of RPC requests to be handled concurrently"
)

var Version string
Expand Down Expand Up @@ -199,7 +196,6 @@ func NewCmd(config *node.Config, run func(*cobra.Command, []string) error) *cobr
junoCmd.Flags().Uint16(metricsPortF, defaultMetricsPort, metricsPortUsage)
junoCmd.Flags().Bool(grpcF, defaultGRPC, grpcUsage)
junoCmd.Flags().Uint16(grpcPortF, defaultGRPCPort, grpcPortUsage)
junoCmd.Flags().Int(rpcMaxConcurrencyF, defaultRPCMaxConcurrency, rpcMaxConcurrencyUsage)

return junoCmd
}
39 changes: 14 additions & 25 deletions cmd/juno/juno_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func TestConfigPrecedence(t *testing.T) {
defaultGRPCPort := uint16(6064)
defaultColour := true
defaultPendingPollInterval := time.Duration(0)
defaultRPCMaxConcurrency := 1024

tests := map[string]struct {
cfgFile bool
Expand All @@ -63,7 +62,6 @@ func TestConfigPrecedence(t *testing.T) {
MetricsPort: defaultMetricsPort,
Colour: defaultColour,
PendingPollInterval: defaultPendingPollInterval,
RPCMaxConcurrency: defaultRPCMaxConcurrency,
},
},
"config file path is empty string": {
Expand All @@ -84,7 +82,6 @@ func TestConfigPrecedence(t *testing.T) {
PprofPort: defaultPprofPort,
Colour: defaultColour,
PendingPollInterval: defaultPendingPollInterval,
RPCMaxConcurrency: defaultRPCMaxConcurrency,
},
},
"config file doesn't exist": {
Expand All @@ -109,7 +106,6 @@ func TestConfigPrecedence(t *testing.T) {
PendingPollInterval: defaultPendingPollInterval,
Pprof: defaultPprof,
PprofPort: defaultPprofPort,
RPCMaxConcurrency: defaultRPCMaxConcurrency,
},
},
"config file with all settings but without any other flags": {
Expand All @@ -136,7 +132,6 @@ pprof: true
PprofPort: defaultPprofPort,
Colour: defaultColour,
PendingPollInterval: defaultPendingPollInterval,
RPCMaxConcurrency: defaultRPCMaxConcurrency,
},
},
"config file with some settings but without any other flags": {
Expand All @@ -160,7 +155,6 @@ http-port: 4576
PprofPort: defaultPprofPort,
Colour: defaultColour,
PendingPollInterval: defaultPendingPollInterval,
RPCMaxConcurrency: defaultRPCMaxConcurrency,
},
},
"all flags without config file": {
Expand All @@ -169,21 +163,20 @@ http-port: 4576
"--db-path", "/home/.juno", "--network", "goerli", "--pprof",
},
expectedConfig: &node.Config{
LogLevel: utils.DEBUG,
HTTP: defaultHTTP,
HTTPPort: 4576,
Websocket: defaultWS,
WebsocketPort: defaultWSPort,
GRPC: defaultGRPC,
GRPCPort: defaultGRPCPort,
Metrics: defaultMetrics,
MetricsPort: defaultMetricsPort,
DatabasePath: "/home/.juno",
Network: utils.GOERLI,
Pprof: true,
PprofPort: defaultPprofPort,
Colour: defaultColour,
RPCMaxConcurrency: defaultRPCMaxConcurrency,
LogLevel: utils.DEBUG,
HTTP: defaultHTTP,
HTTPPort: 4576,
Websocket: defaultWS,
WebsocketPort: defaultWSPort,
GRPC: defaultGRPC,
GRPCPort: defaultGRPCPort,
Metrics: defaultMetrics,
MetricsPort: defaultMetricsPort,
DatabasePath: "/home/.juno",
Network: utils.GOERLI,
Pprof: true,
PprofPort: defaultPprofPort,
Colour: defaultColour,
},
},
"some flags without config file": {
Expand All @@ -207,7 +200,6 @@ http-port: 4576
PprofPort: defaultPprofPort,
Colour: defaultColour,
PendingPollInterval: defaultPendingPollInterval,
RPCMaxConcurrency: defaultRPCMaxConcurrency,
},
},
"all setting set in both config file and flags": {
Expand Down Expand Up @@ -248,7 +240,6 @@ pending-poll-interval: 5s
PprofPort: 6064,
Colour: defaultColour,
PendingPollInterval: time.Millisecond,
RPCMaxConcurrency: defaultRPCMaxConcurrency,
},
},
"some setting set in both config file and flags": {
Expand All @@ -274,7 +265,6 @@ network: goerli
PprofPort: defaultPprofPort,
Colour: defaultColour,
PendingPollInterval: defaultPendingPollInterval,
RPCMaxConcurrency: defaultRPCMaxConcurrency,
},
},
"some setting set in default, config file and flags": {
Expand All @@ -297,7 +287,6 @@ network: goerli
PprofPort: defaultPprofPort,
Colour: defaultColour,
PendingPollInterval: defaultPendingPollInterval,
RPCMaxConcurrency: defaultRPCMaxConcurrency,
},
},
}
Expand Down
7 changes: 4 additions & 3 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"reflect"
"runtime"
"time"

"github.com/Masterminds/semver/v3"
Expand Down Expand Up @@ -62,8 +63,6 @@ type Config struct {
P2P bool `mapstructure:"p2p"`
P2PAddr string `mapstructure:"p2p-addr"`
P2PBootPeers string `mapstructure:"p2p-boot-peers"`

RPCMaxConcurrency int `mapstructure:"rpc-max-concurrency"`
}

type Node struct {
Expand Down Expand Up @@ -114,7 +113,9 @@ func New(cfg *Config, version string) (*Node, error) { //nolint:gocyclo,funlen
gatewayClient := gateway.NewClient(cfg.Network.GatewayURL(), log).WithUserAgent(ua)

rpcHandler := rpc.New(chain, synchronizer, cfg.Network, gatewayClient, client, vm.New(log), version, log)
jsonrpcServer := jsonrpc.NewServer(cfg.RPCMaxConcurrency, log).WithValidator(validator.Validator())
// to improve RPC throughput we double GOMAXPROCS
maxGoroutines := 2 * runtime.GOMAXPROCS(0)
jsonrpcServer := jsonrpc.NewServer(maxGoroutines, log).WithValidator(validator.Validator())
for _, method := range methods(rpcHandler) {
if err = jsonrpcServer.RegisterMethod(method); err != nil {
return nil, err
Expand Down
8 changes: 3 additions & 5 deletions node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ func TestDefaultDbPath(t *testing.T) {

for _, n := range networks {
t.Run(n.String(), func(t *testing.T) {
cfg := &node.Config{Network: n, DatabasePath: "", RPCMaxConcurrency: 1}
cfg := &node.Config{Network: n, DatabasePath: ""}
expectedCfg := node.Config{
Network: n,
DatabasePath: filepath.Join(defaultDataDir, n.String()),
RPCMaxConcurrency: cfg.RPCMaxConcurrency,
Network: n,
DatabasePath: filepath.Join(defaultDataDir, n.String()),
}
snNode, err := node.New(cfg, "1.2.3")
require.NoError(t, err)
Expand Down Expand Up @@ -55,7 +54,6 @@ func TestNewNode(t *testing.T) {
P2P: true,
P2PAddr: "",
P2PBootPeers: "",
RPCMaxConcurrency: 1,
}

_, err := node.New(config, "v0.3")
Expand Down

0 comments on commit 9fadd74

Please sign in to comment.