zrpc: bound concurrency, and close idle connections before the node does
Review follow-ups to 73a93f1. Bound in-flight calls. rpcclient's single sendPostHandler goroutine imposed an accidental ceiling of one concurrent RPC; removing it without putting anything in its place left no bound at all. grpc-go supplies none either -- this server sets no MaxConcurrentStreams, so the default is math.MaxUint32 -- and dragonxd answers RPC with 8 worker threads behind a 4096-deep queue, shared on the pool node with getblocktemplate. Overload would therefore surface as mining latency rather than as an error we could back off on. MaxConnsPerHost blocks the caller at the limit instead of dialling more, which is the backpressure wanted; MaxIdleConnsPerHost alone would only cap reuse and let us exceed the limit while churning connections. Default 8, matching the node's DEFAULT_HTTP_THREADS, tunable with -rpc-max-concurrent. Even 8 removes all of the head-of-line blocking this work set out to fix. IdleConnTimeout 90s -> 20s. dragonxd closes idle connections at 30s (DEFAULT_HTTP_SERVER_TIMEOUT, applied via evhttp_set_timeout and not overridden in DRAGONX.conf). At 90s we were always the second to close, so a request could be written into a connection the server had already sent a FIN for, and Go will not retry a POST once bytes are on the wire. Closing first removes the race. Reject a negative -rpc-timeout, which silently meant "unbounded", the same as the documented 0. The check has to run after flag.Parse(); it was initially placed before it and never fired. Also correct the coinsupply note: hush_coinsupply walks the block index back to genesis, loading each block from disk and memoising newcoins and zfunds into the CBlockIndex, so the first call pays for the whole chain and later ones are nearly free. It is not a UTXO-set scan, as the earlier comment claimed. The measured 48s/3s figures are unchanged. Verified: five concurrent GetLightdInfo calls all return grpc-status 0 with no errors, 46 blocks ingested, and the daemon holds 2 sockets to the node rather than one per request; a negative timeout exits 1. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FU87LdsJZiZkfq1eXubpeo
This commit is contained in:
@@ -91,7 +91,8 @@ type Options struct {
|
||||
lagMax int `json:"lag_max,omitempty"`
|
||||
lagWindowMin int `json:"lag_window_min,omitempty"`
|
||||
|
||||
rpcTimeout time.Duration `json:"rpc_timeout,omitempty"`
|
||||
rpcTimeout time.Duration `json:"rpc_timeout,omitempty"`
|
||||
rpcMaxConcurrent int `json:"rpc_max_concurrent,omitempty"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -110,7 +111,8 @@ func main() {
|
||||
flag.IntVar(&opts.lagMin, "lag-min", 1, "minimum confirmation lag in blocks (applied when the chain is stable)")
|
||||
flag.IntVar(&opts.lagMax, "lag-max", 12, "maximum confirmation lag in blocks (cap during heavy reorgs)")
|
||||
flag.IntVar(&opts.lagWindowMin, "lag-window", 30, "minutes of recent reorg history used to size the adaptive lag")
|
||||
flag.DurationVar(&opts.rpcTimeout, "rpc-timeout", frontend.DefaultRPCTimeout, "bound a single dragonxd JSON-RPC call; 0 disables. One stuck call otherwise blocks every other caller, because HTTP POST mode serialises all RPC through one goroutine")
|
||||
flag.DurationVar(&opts.rpcTimeout, "rpc-timeout", frontend.DefaultRPCTimeout, "bound a single dragonxd JSON-RPC call; 0 disables. Without it one stuck call blocks every other caller")
|
||||
flag.IntVar(&opts.rpcMaxConcurrent, "rpc-max-concurrent", frontend.DefaultRPCMaxConcurrent, "maximum dragonxd JSON-RPC calls in flight at once; matches the node's RPC worker threads")
|
||||
|
||||
// creating --version as a requirement of help2man
|
||||
if len(os.Args) > 1 && (os.Args[1] == "--version" || os.Args[1] == "-v") {
|
||||
@@ -122,6 +124,13 @@ func main() {
|
||||
// TODO support config from file and env vars
|
||||
flag.Parse()
|
||||
|
||||
// A negative duration silently means "no timeout", the same as the
|
||||
// documented 0, so reject it rather than quietly running unbounded.
|
||||
if opts.rpcTimeout < 0 {
|
||||
fmt.Fprintln(os.Stderr, "-rpc-timeout must not be negative; use 0 to disable the timeout")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if opts.confPath == "" {
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
@@ -175,13 +184,13 @@ func main() {
|
||||
// sending transactions, but in the future it could back a different type
|
||||
// of block streamer.
|
||||
|
||||
rpcClient, err := frontend.NewZRPCFromConf(opts.confPath, opts.rpcTimeout)
|
||||
rpcClient, err := frontend.NewZRPCFromConf(opts.confPath, opts.rpcTimeout, opts.rpcMaxConcurrent)
|
||||
if err != nil {
|
||||
log.WithFields(logrus.Fields{
|
||||
"error": err,
|
||||
}).Warn("DRAGONX.conf failed, will try empty credentials for rpc")
|
||||
|
||||
rpcClient, err = frontend.NewZRPCFromCreds("127.0.0.1:21769", "", "", opts.rpcTimeout)
|
||||
rpcClient, err = frontend.NewZRPCFromCreds("127.0.0.1:21769", "", "", opts.rpcTimeout, opts.rpcMaxConcurrent)
|
||||
|
||||
if err != nil {
|
||||
log.WithFields(logrus.Fields{
|
||||
|
||||
Reference in New Issue
Block a user