cmd/strelaypoolsrv: Configurable request processors & queue len

This commit is contained in:
Jakob Borg
2020-04-04 13:31:42 +02:00
parent 362da59396
commit d1db7e3dd2
+12 -1
View File
@@ -113,6 +113,8 @@ var (
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()
for i := 0; i < requestProcessors; i++ {
go requestProcessor() 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