cmd/strelaypoolsrv: Configurable request processors & queue len
This commit is contained in:
parent
362da59396
commit
d1db7e3dd2
|
@ -94,25 +94,27 @@ type result struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
testCert tls.Certificate
|
testCert tls.Certificate
|
||||||
knownRelaysFile = filepath.Join(os.TempDir(), "strelaypoolsrv_known_relays")
|
knownRelaysFile = filepath.Join(os.TempDir(), "strelaypoolsrv_known_relays")
|
||||||
listen = ":80"
|
listen = ":80"
|
||||||
dir string
|
dir string
|
||||||
evictionTime = time.Hour
|
evictionTime = time.Hour
|
||||||
debug bool
|
debug bool
|
||||||
getLRUSize = 10 << 10
|
getLRUSize = 10 << 10
|
||||||
getLimitBurst = 10
|
getLimitBurst = 10
|
||||||
getLimitAvg = 2
|
getLimitAvg = 2
|
||||||
postLRUSize = 1 << 10
|
postLRUSize = 1 << 10
|
||||||
postLimitBurst = 2
|
postLimitBurst = 2
|
||||||
postLimitAvg = 2
|
postLimitAvg = 2
|
||||||
getLimit time.Duration
|
getLimit time.Duration
|
||||||
postLimit time.Duration
|
postLimit time.Duration
|
||||||
permRelaysFile string
|
permRelaysFile string
|
||||||
ipHeader string
|
ipHeader string
|
||||||
geoipPath string
|
geoipPath string
|
||||||
proto string
|
proto string
|
||||||
statsRefresh = time.Minute / 2
|
statsRefresh = time.Minute / 2
|
||||||
|
requestQueueLen = 10
|
||||||
|
requestProcessors = 1
|
||||||
|
|
||||||
getMut = sync.NewRWMutex()
|
getMut = sync.NewRWMutex()
|
||||||
getLRUCache *lru.Cache
|
getLRUCache *lru.Cache
|
||||||
|
@ -120,7 +122,7 @@ var (
|
||||||
postMut = sync.NewRWMutex()
|
postMut = sync.NewRWMutex()
|
||||||
postLRUCache *lru.Cache
|
postLRUCache *lru.Cache
|
||||||
|
|
||||||
requests = make(chan request, 10)
|
requests chan request
|
||||||
|
|
||||||
mut = sync.NewRWMutex()
|
mut = sync.NewRWMutex()
|
||||||
knownRelays = make([]*relay, 0)
|
knownRelays = make([]*relay, 0)
|
||||||
|
@ -133,6 +135,9 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
log.SetOutput(os.Stdout)
|
||||||
|
log.SetFlags(log.Lshortfile)
|
||||||
|
|
||||||
flag.StringVar(&listen, "listen", listen, "Listen address")
|
flag.StringVar(&listen, "listen", listen, "Listen address")
|
||||||
flag.StringVar(&dir, "keys", dir, "Directory where http-cert.pem and http-key.pem is stored for TLS listening")
|
flag.StringVar(&dir, "keys", dir, "Directory where http-cert.pem and http-key.pem is stored for TLS listening")
|
||||||
flag.BoolVar(&debug, "debug", debug, "Enable debug output")
|
flag.BoolVar(&debug, "debug", debug, "Enable debug output")
|
||||||
|
@ -148,9 +153,13 @@ func main() {
|
||||||
flag.StringVar(&geoipPath, "geoip", "GeoLite2-City.mmdb", "Path to GeoLite2-City database")
|
flag.StringVar(&geoipPath, "geoip", "GeoLite2-City.mmdb", "Path to GeoLite2-City database")
|
||||||
flag.StringVar(&proto, "protocol", "tcp", "Protocol used for listening. 'tcp' for IPv4 and IPv6, 'tcp4' for IPv4, 'tcp6' for IPv6")
|
flag.StringVar(&proto, "protocol", "tcp", "Protocol used for listening. 'tcp' for IPv4 and IPv6, 'tcp4' for IPv4, 'tcp6' for IPv6")
|
||||||
flag.DurationVar(&statsRefresh, "stats-refresh", statsRefresh, "Interval at which to refresh relay stats")
|
flag.DurationVar(&statsRefresh, "stats-refresh", statsRefresh, "Interval at which to refresh relay stats")
|
||||||
|
flag.IntVar(&requestQueueLen, "request-queue", requestQueueLen, "Queue length for incoming test requests")
|
||||||
|
flag.IntVar(&requestProcessors, "request-processors", requestProcessors, "Number of request processor routines")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
requests = make(chan request, requestQueueLen)
|
||||||
|
|
||||||
getLimit = 10 * time.Second / time.Duration(getLimitAvg)
|
getLimit = 10 * time.Second / time.Duration(getLimitAvg)
|
||||||
postLimit = time.Minute / time.Duration(postLimitAvg)
|
postLimit = time.Minute / time.Duration(postLimitAvg)
|
||||||
|
|
||||||
|
@ -166,7 +175,9 @@ func main() {
|
||||||
|
|
||||||
testCert = createTestCertificate()
|
testCert = createTestCertificate()
|
||||||
|
|
||||||
go requestProcessor()
|
for i := 0; i < requestProcessors; i++ {
|
||||||
|
go requestProcessor()
|
||||||
|
}
|
||||||
|
|
||||||
// Load relays from cache in the background.
|
// Load relays from cache in the background.
|
||||||
// Load them in a serial fashion to make sure any genuine requests
|
// Load them in a serial fashion to make sure any genuine requests
|
||||||
|
|
Loading…
Reference in New Issue