Skip to content

Commit

Permalink
Make number of VM related requests to queue configurable
Browse files Browse the repository at this point in the history
before starting to reject new incoming requests
  • Loading branch information
omerfirmak committed Nov 20, 2023
1 parent b86bf46 commit c575b82
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions cmd/juno/juno.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const (
grpcHostF = "grpc-host"
grpcPortF = "grpc-port"
maxVMsF = "max-vms"
maxVMQueueF = "max-vm-queue"
remoteDBF = "remote-db"
rpcMaxBlockScanF = "rpc-max-block-scan"

Expand Down Expand Up @@ -109,6 +110,7 @@ const (
grpcHostUsage = "The interface on which the GRPC server will listen for requests."
grpcPortUsage = "The port on which the GRPC server will listen for requests."
maxVMsUsage = "Maximum number for VM instances to be used for RPC calls concurrently"
maxVMQueueUsage = "Maximum number for requests to queue after reaching max-vms before starting to reject incoming requets"
remoteDBUsage = "gRPC URL of a remote Juno node"
rpcMaxBlockScanUsage = "Maximum number of blocks scanned in single starknet_getEvents call"
)
Expand Down Expand Up @@ -232,6 +234,7 @@ func NewCmd(config *node.Config, run func(*cobra.Command, []string) error) *cobr
junoCmd.Flags().String(grpcHostF, defaulHost, grpcHostUsage)
junoCmd.Flags().Uint16(grpcPortF, defaultGRPCPort, grpcPortUsage)
junoCmd.Flags().Uint(maxVMsF, uint(defaultMaxVMs), maxVMsUsage)
junoCmd.Flags().Uint(maxVMQueueF, 2*uint(defaultMaxVMs), maxVMQueueUsage)
junoCmd.Flags().String(remoteDBF, defaultRemoteDB, remoteDBUsage)
junoCmd.Flags().Uint(rpcMaxBlockScanF, defaultRPCMaxBlockScan, rpcMaxBlockScanUsage)

Expand Down
10 changes: 10 additions & 0 deletions cmd/juno/juno_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func TestConfigPrecedence(t *testing.T) {
Colour: defaultColour,
PendingPollInterval: defaultPendingPollInterval,
MaxVMs: defaultMaxVMs,
MaxVMQueue: 2 * defaultMaxVMs,
RPCMaxBlockScan: defaultRPCMaxBlockScan,
},
},
Expand Down Expand Up @@ -104,6 +105,7 @@ func TestConfigPrecedence(t *testing.T) {
Colour: defaultColour,
PendingPollInterval: defaultPendingPollInterval,
MaxVMs: defaultMaxVMs,
MaxVMQueue: 2 * defaultMaxVMs,
RPCMaxBlockScan: defaultRPCMaxBlockScan,
},
},
Expand Down Expand Up @@ -136,6 +138,7 @@ func TestConfigPrecedence(t *testing.T) {
PprofPort: defaultPprofPort,
DatabasePath: defaultDBPath,
MaxVMs: defaultMaxVMs,
MaxVMQueue: 2 * defaultMaxVMs,
RPCMaxBlockScan: defaultRPCMaxBlockScan,
},
},
Expand Down Expand Up @@ -170,6 +173,7 @@ pprof: true
Colour: defaultColour,
PendingPollInterval: defaultPendingPollInterval,
MaxVMs: defaultMaxVMs,
MaxVMQueue: 2 * defaultMaxVMs,
RPCMaxBlockScan: defaultRPCMaxBlockScan,
},
},
Expand Down Expand Up @@ -201,6 +205,7 @@ http-port: 4576
Colour: defaultColour,
PendingPollInterval: defaultPendingPollInterval,
MaxVMs: defaultMaxVMs,
MaxVMQueue: 2 * defaultMaxVMs,
RPCMaxBlockScan: defaultRPCMaxBlockScan,
},
},
Expand Down Expand Up @@ -230,6 +235,7 @@ http-port: 4576
PprofPort: defaultPprofPort,
Colour: defaultColour,
MaxVMs: defaultMaxVMs,
MaxVMQueue: 2 * defaultMaxVMs,
RPCMaxBlockScan: defaultRPCMaxBlockScan,
},
},
Expand Down Expand Up @@ -260,6 +266,7 @@ http-port: 4576
Colour: defaultColour,
PendingPollInterval: defaultPendingPollInterval,
MaxVMs: defaultMaxVMs,
MaxVMQueue: 2 * defaultMaxVMs,
RPCMaxBlockScan: defaultRPCMaxBlockScan,
},
},
Expand Down Expand Up @@ -312,6 +319,7 @@ pending-poll-interval: 5s
Colour: defaultColour,
PendingPollInterval: time.Millisecond,
MaxVMs: defaultMaxVMs,
MaxVMQueue: 2 * defaultMaxVMs,
RPCMaxBlockScan: defaultRPCMaxBlockScan,
},
},
Expand Down Expand Up @@ -345,6 +353,7 @@ network: goerli
Colour: defaultColour,
PendingPollInterval: defaultPendingPollInterval,
MaxVMs: defaultMaxVMs,
MaxVMQueue: 2 * defaultMaxVMs,
RPCMaxBlockScan: defaultRPCMaxBlockScan,
},
},
Expand Down Expand Up @@ -374,6 +383,7 @@ network: goerli
Colour: defaultColour,
PendingPollInterval: defaultPendingPollInterval,
MaxVMs: defaultMaxVMs,
MaxVMQueue: 2 * defaultMaxVMs,
RPCMaxBlockScan: defaultRPCMaxBlockScan,
},
},
Expand Down
6 changes: 3 additions & 3 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ type Config struct {
P2PAddr string `mapstructure:"p2p-addr"`
P2PBootPeers string `mapstructure:"p2p-boot-peers"`

MaxVMs uint `mapstructure:"max-vms"`

MaxVMs uint `mapstructure:"max-vms"`
MaxVMQueue uint `mapstructure:"max-vm-queue"`
RPCMaxBlockScan uint `mapstructure:"rpc-max-block-scan"`
}

Expand Down Expand Up @@ -122,7 +122,7 @@ func New(cfg *Config, version string) (*Node, error) { //nolint:gocyclo,funlen
services = append(services, synchronizer)
gatewayClient := gateway.NewClient(cfg.Network.GatewayURL(), log).WithUserAgent(ua)

throttledVM := NewThrottledVM(vm.New(log), cfg.MaxVMs, int32(cfg.MaxVMs))
throttledVM := NewThrottledVM(vm.New(log), cfg.MaxVMs, int32(cfg.MaxVMQueue))
rpcHandler := rpc.New(chain, synchronizer, cfg.Network, gatewayClient, client, throttledVM, version, log)
rpcHandler = rpcHandler.WithFilterLimit(cfg.RPCMaxBlockScan)
services = append(services, rpcHandler)
Expand Down

0 comments on commit c575b82

Please sign in to comment.