From e1622cd22c282eb752fb783ba791b994b0ca3714 Mon Sep 17 00:00:00 2001 From: Brian Akins Date: Tue, 7 Apr 2015 15:40:29 -0400 Subject: [PATCH 1/2] proxy: shuffle endpoints Shuffle endpoitns to avoid being "stuck" to a single cluster member. --- Documentation/proxy.md | 2 ++ proxy/director.go | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/Documentation/proxy.md b/Documentation/proxy.md index ab9c8a1b5..cbf63e4e2 100644 --- a/Documentation/proxy.md +++ b/Documentation/proxy.md @@ -4,6 +4,8 @@ etcd can now run as a transparent proxy. Running etcd as a proxy allows for easi etcd currently supports two proxy modes: `readwrite` and `readonly`. The default mode is `readwrite`, which forwards both read and write requests to the etcd cluster. A `readonly` etcd proxy only forwards read requests to the etcd cluster, and returns `HTTP 501` to all write requests. +etcd will shuffle the list of cluster members periodically to avoid sending all connections to a single member. + ### Using an etcd proxy To start etcd in proxy mode, you need to provide three flags: `proxy`, `listen-client-urls`, and `initial-cluster` (or `discovery`). diff --git a/proxy/director.go b/proxy/director.go index 862690d4d..e795b27fb 100644 --- a/proxy/director.go +++ b/proxy/director.go @@ -16,6 +16,7 @@ package proxy import ( "log" + "math/rand" "net/url" "sync" "time" @@ -65,6 +66,13 @@ func (d *director) refresh() { } endpoints = append(endpoints, newEndpoint(*uu)) } + + // shuffle array to avoid connections being "stuck" to a single endpoint + for i := range endpoints { + j := rand.Intn(i + 1) + endpoints[i], endpoints[j] = endpoints[j], endpoints[i] + } + d.ep = endpoints } From 1fa511b9952d49befba9cb69383f36c82700f37c Mon Sep 17 00:00:00 2001 From: Brian Akins Date: Tue, 7 Apr 2015 17:05:17 -0400 Subject: [PATCH 2/2] Clarify that it is the proxy doing the shuffle. --- Documentation/proxy.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/proxy.md b/Documentation/proxy.md index cbf63e4e2..7e2e8b4da 100644 --- a/Documentation/proxy.md +++ b/Documentation/proxy.md @@ -4,7 +4,7 @@ etcd can now run as a transparent proxy. Running etcd as a proxy allows for easi etcd currently supports two proxy modes: `readwrite` and `readonly`. The default mode is `readwrite`, which forwards both read and write requests to the etcd cluster. A `readonly` etcd proxy only forwards read requests to the etcd cluster, and returns `HTTP 501` to all write requests. -etcd will shuffle the list of cluster members periodically to avoid sending all connections to a single member. +The proxy will shuffle the list of cluster members periodically to avoid sending all connections to a single member. ### Using an etcd proxy To start etcd in proxy mode, you need to provide three flags: `proxy`, `listen-client-urls`, and `initial-cluster` (or `discovery`).