On Fri, Oct 6, 2017 at 8:44 PM, Ben Pfaff <b...@ovn.org> wrote: > The implementation cycles through the remotes in random order. This allows > clients to perform some load balancing across alternative implementations > of a service. > > Signed-off-by: Ben Pfaff <b...@ovn.org> > --- > lib/jsonrpc.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++----- > lib/jsonrpc.h | 6 +++++- > lib/svec.c | 18 ++++++++++++++++++ > lib/svec.h | 1 + > 4 files changed, 72 insertions(+), 6 deletions(-)
> diff --git a/lib/svec.c b/lib/svec.c > index 297a60ce14f9..c1b986bab108 100644 > --- a/lib/svec.c > +++ b/lib/svec.c > @@ -20,6 +20,7 @@ > #include <stdlib.h> > #include <string.h> > #include "openvswitch/dynamic-string.h" > +#include "random.h" > #include "util.h" > #include "openvswitch/vlog.h" > > @@ -174,6 +175,23 @@ svec_compact(struct svec *svec) > svec->n = j; > } > > +static void > +swap_strings(char **a, char **b) > +{ > + char *tmp = *a; > + *a = *b; > + *b = tmp; > +} > + > +void > +svec_shuffle(struct svec *svec) > +{ > + for (size_t i = 0; i < svec->n; i++) { > + size_t j = i + random_range(svec->n - i); > + swap_strings(&svec->names[i], &svec->names[j]); > + } > +} > + I'm not sure this is as random as we'd like. Even if there are 10 elements, the first element has a 50% chance of staying there, since it's only considered for a swap when i == 0. That extends to the general behavior that the closer an element is to the beginning, the better chance it has of staying near the beginning. Or am I reading it wrong? Thanks, -- Russell Bryant _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev