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

Anton Jouline juce66 at gmail.com
Mon Aug 27 15:45:24 UTC 2012


Just realized the patch in the previous message was not
in the most-readable form... Here is the shorter version of the diff
with new files omitted. (If anyone's interested, you can see the new
files in the full diff, attached to the original message. These files -
ngx_http_upstream_random.h and ngx_http_upstream_random.c -
are, for the most part, pretty much copies of ngx_http_upstream_round_robin.*,
with some slight changes).

====

diff -u -r nginx-1.2.2-org/auto/sources nginx-1.2.2/auto/sources
--- nginx-1.2.2-org/auto/sources 2012-07-02 09:41:13.000000000 -0700
+++ nginx-1.2.2/auto/sources 2012-08-27 08:31:45.000000000 -0700
@@ -291,6 +291,7 @@
           src/http/ngx_http_script.h \
           src/http/ngx_http_upstream.h \
           src/http/ngx_http_upstream_round_robin.h \
+           src/http/ngx_http_upstream_random.h \
           src/http/ngx_http_busy_lock.h"

HTTP_SRCS="src/http/ngx_http.c \
@@ -307,6 +308,7 @@
           src/http/ngx_http_script.c \
           src/http/ngx_http_upstream.c \
           src/http/ngx_http_upstream_round_robin.c \
+           src/http/ngx_http_upstream_random.c \
           src/http/ngx_http_parse_time.c \
           src/http/modules/ngx_http_static_module.c \
           src/http/modules/ngx_http_index_module.c \
diff -u -r nginx-1.2.2-org/src/http/ngx_http.h nginx-1.2.2/src/http/ngx_http.h
--- nginx-1.2.2-org/src/http/ngx_http.h 2012-01-18 07:07:43.000000000 -0800
+++ nginx-1.2.2/src/http/ngx_http.h 2012-08-27 08:31:45.000000000 -0700
@@ -29,6 +29,7 @@
#include <ngx_http_request.h>
#include <ngx_http_upstream.h>
#include <ngx_http_upstream_round_robin.h>
+#include <ngx_http_upstream_random.h>
#include <ngx_http_config.h>
#include <ngx_http_busy_lock.h>
#include <ngx_http_script.h>
diff -u -r nginx-1.2.2-org/src/http/ngx_http_upstream.c
nginx-1.2.2/src/http/ngx_http_upstream.c
--- nginx-1.2.2-org/src/http/ngx_http_upstream.c 2012-07-02
08:43:50.000000000 -0700
+++ nginx-1.2.2/src/http/ngx_http_upstream.c 2012-08-27 08:31:45.000000000 -0700
@@ -895,7 +895,7 @@
    }
#endif

-    if (ngx_http_upstream_create_round_robin_peer(r, ur) != NGX_OK) {
+    if (ngx_http_upstream_create_random_peer(r, ur) != NGX_OK) {
        ngx_http_upstream_finalize_request(r, u,
                                           NGX_HTTP_INTERNAL_SERVER_ERROR);
        return;
Only in nginx-1.2.2/src/http: ngx_http_upstream_random.c
Only in nginx-1.2.2/src/http: ngx_http_upstream_random.h



More information about the nginx-devel mailing list