Opened 13 years ago

Closed 13 years ago

#144 closed enhancement (fixed)

RFE: implement weighted ip_hash

Reported by: muayyad alsadi Owned by: somebody
Priority: major Milestone:
Component: nginx-module Version: 1.1.x
Keywords: HttpUpstreamModule Cc:
uname -a: Linux localhost.localdomain 2.6.40.4-5.fc15.x86_64 #1 SMP Tue Aug 30 14:38:32 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.0.14
built by gcc 4.6.1 20110908 (Red Hat 4.6.1-9) (GCC)
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' --with-ld-opt=-Wl,-E

Description

the doc says ip_hash can't be combined with weight

http://wiki.nginx.org/HttpUpstreamModule#ip_hash

It is not possible to combine ip_hash and weight methods for connection distribution. If one of the servers must be removed for some time, you must mark that server as *down*.

I believe it can be implemented like this (given that an ip is 32bit integer):

int upstreams_c=4;
int *weights={2,3,1,1};
int weights_sum=7;
int *upstreams={0,0, 1,1,1, 2, 3}; // constructed from weights
int get_upstream(int client_ip) {
// return 0 for first upstream, 1 for second upstream ...etc.
return upstreams[client_ip % weights_sum];
}

Change History (1)

comment:1 by Maxim Dounin, 13 years ago

Resolution: fixed
Status: newclosed

Weight support added to ip_hash in 1.3.1.

Note: See TracTickets for help on using tickets.