[PATCH] Random peer selection for implicit upstream defined by proxy_pass

Maxim Dounin mdounin at mdounin.ru
Fri Sep 28 18:51:34 UTC 2012


On Wed, Sep 19, 2012 at 10:39:01PM -0700, Anton Jouline wrote:


> So, i decided instead to take a look at ngx_resolver code and
> it turned out that it's actually very simple to randomize there,
> since there is code already that copies the array from one place
> in memory to another. Looked like that was ideal place for
> changing the order via simple rotation.
> Here is the new patch:
> --- a/src/core/ngx_resolver.c
> +++ b/src/core/ngx_resolver.c
> @@ -88,6 +88,8 @@ static void *ngx_resolver_calloc(ngx_resolver_t *r,
> size_t size);
>  static void ngx_resolver_free(ngx_resolver_t *r, void *p);
>  static void ngx_resolver_free_locked(ngx_resolver_t *r, void *p);
>  static void *ngx_resolver_dup(ngx_resolver_t *r, void *src, size_t size);
> +static in_addr_t *ngx_resolver_dup_rotated(ngx_resolver_t *r, in_addr_t *src,
> +    u_short n);
>  static u_char *ngx_resolver_log_error(ngx_log_t *log, u_char *buf, size_t len);


Slightly modified version committed, thanks:


I'm a bit unsure - would you prefer Russian attribution in 
CHANGES.ru?  (We usually write names in Russian in CHANGES.ru if 
contributor is from exUSSR/speak Russian.)

Maxim Dounin

More information about the nginx-devel mailing list