github.com/decred/dcrlnd@v0.7.6/lncfg/workers.go (about)

     1  package lncfg
     2  
     3  import "fmt"
     4  
     5  const (
     6  	// DefaultReadWorkers is the default maximum number of concurrent
     7  	// workers used by the daemon's read pool.
     8  	DefaultReadWorkers = 100
     9  
    10  	// DefaultWriteWorkers is the default maximum number of concurrent
    11  	// workers used by the daemon's write pool.
    12  	DefaultWriteWorkers = 8
    13  
    14  	// DefaultSigWorkers is the default maximum number of concurrent workers
    15  	// used by the daemon's sig pool.
    16  	DefaultSigWorkers = 8
    17  )
    18  
    19  // Workers exposes CLI configuration for turning resources consumed by worker
    20  // pools.
    21  type Workers struct {
    22  	// Read is the maximum number of concurrent read pool workers.
    23  	Read int `long:"read" description:"Maximum number of concurrent read pool workers. This number should be proportional to the number of peers."`
    24  
    25  	// Write is the maximum number of concurrent write pool workers.
    26  	Write int `long:"write" description:"Maximum number of concurrent write pool workers. This number should be proportional to the number of CPUs on the host. "`
    27  
    28  	// Sig is the maximum number of concurrent sig pool workers.
    29  	Sig int `long:"sig" description:"Maximum number of concurrent sig pool workers. This number should be proportional to the number of CPUs on the host."`
    30  }
    31  
    32  // Validate checks the Workers configuration to ensure that the input values are
    33  // sane.
    34  func (w *Workers) Validate() error {
    35  	if w.Read <= 0 {
    36  		return fmt.Errorf("number of read workers (%d) must be "+
    37  			"positive", w.Read)
    38  	}
    39  	if w.Write <= 0 {
    40  		return fmt.Errorf("number of write workers (%d) must be "+
    41  			"positive", w.Write)
    42  	}
    43  	if w.Sig <= 0 {
    44  		return fmt.Errorf("number of sig workers (%d) must be "+
    45  			"positive", w.Sig)
    46  	}
    47  
    48  	return nil
    49  }
    50  
    51  // Compile-time constraint to ensure Workers implements the Validator interface.
    52  var _ Validator = (*Workers)(nil)