-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sync: enable rate limiting for servers (#5151)
closes: #4977 closes: #4603 this change introduces two configuration parameter for every server: - requests per interval pace, for example 10 req/s, this caps the maximum bandwidth that every server can use - queue size, it is set to serve requests within expected latency. every other request is dropped immediately so that client can retry with different node. currently the timeout is set to 10s, so the queue should be roughly 10 times larger then rps it doesn't provide global limit for bandwidth, but we have limit for the number of peers. and honest peer doesn't run many concurrent queries. so what we really want to handle is peers with intentionally malicious behavior, but thats not a pressing issue example configuration: ```json "fetch": { "servers": { "ax/1": {"queue": 10, "requests": 1, "interval": "1s"}, "ld/1": {"queue": 1000, "requests": 100, "interval": "1s"}, "hs/1": {"queue": 2000, "requests": 200, "interval": "1s"}, "mh/1": {"queue": 1000, "requests": 100, "interval": "1s"}, "ml/1": {"queue": 100, "requests": 10, "interval": "1s"}, "lp/2": {"queue": 10000, "requests": 1000, "interval": "1s"} } } ``` https://github.com/spacemeshos/go-spacemesh/blob/3cf02146bf27f53c001bffcacffbda05933c27c4/fetch/fetch.go#L130-L144 metrics are per server: https://github.com/spacemeshos/go-spacemesh/blob/3cf02146bf27f53c001bffcacffbda05933c27c4/p2p/server/metrics.go#L15-L52 have to be enabled for all servers with ```json "fetch": { "servers-metrics": true } ```
- Loading branch information
Showing
9 changed files
with
496 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package server | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
|
||
"github.com/spacemeshos/go-spacemesh/metrics" | ||
) | ||
|
||
const ( | ||
namespace = "server" | ||
protoLabel = "protocol" | ||
) | ||
|
||
var ( | ||
targetQueue = metrics.NewGauge( | ||
"target_queue", | ||
namespace, | ||
"target size of the queue", | ||
[]string{protoLabel}, | ||
) | ||
queue = metrics.NewGauge( | ||
"queue", | ||
namespace, | ||
"actual size of the queue", | ||
[]string{protoLabel}, | ||
) | ||
targetRps = metrics.NewGauge( | ||
"rps", | ||
namespace, | ||
"target requests per second", | ||
[]string{protoLabel}, | ||
) | ||
requests = metrics.NewCounter( | ||
"requests", | ||
namespace, | ||
"requests counter", | ||
[]string{protoLabel, "state"}, | ||
) | ||
clientLatency = metrics.NewHistogramWithBuckets( | ||
"client_latency_seconds", | ||
namespace, | ||
"latency since initiating a request", | ||
[]string{protoLabel, "result"}, | ||
prometheus.ExponentialBuckets(0.01, 2, 10), | ||
) | ||
serverLatency = metrics.NewHistogramWithBuckets( | ||
"server_latency_seconds", | ||
namespace, | ||
"latency since accepting new stream", | ||
[]string{protoLabel}, | ||
prometheus.ExponentialBuckets(0.01, 2, 10), | ||
) | ||
) | ||
|
||
func newTracker(protocol string) *tracker { | ||
return &tracker{ | ||
targetQueue: targetQueue.WithLabelValues(protocol), | ||
queue: queue.WithLabelValues(protocol), | ||
targetRps: targetRps.WithLabelValues(protocol), | ||
completed: requests.WithLabelValues(protocol, "completed"), | ||
accepted: requests.WithLabelValues(protocol, "accepted"), | ||
dropped: requests.WithLabelValues(protocol, "dropped"), | ||
serverLatency: serverLatency.WithLabelValues(protocol), | ||
clientLatency: clientLatency.WithLabelValues(protocol, "success"), | ||
clientLatencyFailure: clientLatency.WithLabelValues(protocol, "failure"), | ||
} | ||
} | ||
|
||
type tracker struct { | ||
targetQueue prometheus.Gauge | ||
queue prometheus.Gauge | ||
targetRps prometheus.Gauge | ||
completed prometheus.Counter | ||
accepted prometheus.Counter | ||
dropped prometheus.Counter | ||
serverLatency prometheus.Observer | ||
clientLatency, clientLatencyFailure prometheus.Observer | ||
} |
Oops, something went wrong.