gnosek / nginx-upstream-fair Goto Github PK
View Code? Open in Web Editor NEWThe fair load balancer module for nginx
Home Page: http://nginx.localdomain.pl
The fair load balancer module for nginx
Home Page: http://nginx.localdomain.pl
Nginx Upstream Fair Proxy Load Balancer -- Description: -- The Nginx fair proxy balancer enhances the standard round-robin load balancer provided with Nginx so that it will track busy back end servers (e.g. Thin, Ebb, Mongrel) and balance the load to non-busy server processes. Further information can be found on http://nginx.localdomain.pl/ Ezra Zygmuntowicz has a good writeup of the fair proxy load balancer and how to use it here: http://brainspl.at/articles/2007/11/09/a-fair-proxy-balancer-for-nginx-and-mongrel Installation: -- You'll need to re-compile Nginx from source to include this module. Modify your compile of Nginx by adding the following directive (modified to suit your path of course): ./configure --with-http_ssl_module --add-module=/absolute/path/to/nginx-upstream-fair make make install Usage: -- Change your Nginx config file's upstream block to include the 'fair' directive: upstream mongrel { fair; server 127.0.0.1:5000; server 127.0.0.1:5001; server 127.0.0.1:5002; } If you encounter any issues, please report them using the bugtracker at http://nginx.localdomain.pl/ Contributing: -- Git source repositories: http://github.com/gnosek/nginx-upstream-fair/tree/master http://git.localdomain.pl/?p=nginx-upstream-fair.git;a=summary Please feel free to fork the project at GitHub and submit pull requests or patches.
In ngx_http_upstream_fair_module.c, beginning on line 604
/* setup our wrapper around rr */
peers = ngx_palloc(cf->pool, sizeof *peers);
if (peers == NULL) {
return NGX_ERROR;
}
peers = us->peer.data;
Looks like a bug to allocate memory to peers then immediately re-assign peers to something else. I'm not familiar with nginx code base, so I apologize if this is correct and I am misunderstanding something.
If you have a configuration like this:
upstream testing {
fair;
server foo.com:9000;
server bar.com:9000;
}
you would expect that upstream_fair would uniformly distribute requests to foo.com and bar.com. However, if foo.com resolves to multiple IP addresses then each address for foo.com will count as a different server.
I confirmed this behavior on Ubuntu by creating two entries for localhost within /etc/hosts
127.0.0.1 localhost
127.0.0.1 localhost
then when you configure upstream_fair with
upstream testing {
fair;
server localhost:9000;
server 127.0.0.1:9001;
}
then the backend on 9000 receives twice as many requests as 9001
The documentation for upstream_fair does not reflect this behavior. If this behavior is intentional then it seems worthwhile to update the documentation to reflect the behavior of the module. If you want to change the behavior of the module, see the ngx_http_upstream_init_fair_rr function. In particular see lines 464 and 465
for (i = 0; i < us->servers->nelts; i++) { // iterate over each host
for (j = 0; j < server[i].naddrs; j++) { // iterate over each address associated with each host
Hi, fair method load balancing kills nginx processes
/var/log/nginx/error.log
nginx worker process 10089 exited on signal 8
nginx worker process 10090 exited on signal 8
nginx worker process 10091 exited on signal 8
and more more infinity.
Please help me to run fair module.
Hi, please help,
compiling errors to make command:
/path/nginx/nginx-upstream-fair/ngx_http_upstream_fair_module.c:543:28: error: «ngx_http_upstream_srv_conf_t» element contains the name «default_port»
if one server node is down and restart ,nginx will not call it ,and I tried restart another node ,it will call this again but only one will be called. unless I restart nginx.
Hi!
This was captured from one of our high-traffic servers using the upstream-fair module on nginx/1.4.7, where child workers were continually segfaulting.
Core was generated by `nginx: worker process '.
Program terminated with signal 11, Segmentation fault.
#0 ngx_http_upstream_fair_walk_shm (shpool=0x7f2ab19ff000, node=0x0, sentinel=0x7f2ab1a17000,
peers=0x9c999a0) at ../nginx-upstream-fair/ngx_http_upstream_fair_module.c:1010
1010 ../nginx-upstream-fair/ngx_http_upstream_fair_module.c: No such file or directory.
in ../nginx-upstream-fair/ngx_http_upstream_fair_module.c
(gdb) bt
#0 ngx_http_upstream_fair_walk_shm (shpool=0x7f2ab19ff000, node=0x0, sentinel=0x7f2ab1a17000,
peers=0x9c999a0) at ../nginx-upstream-fair/ngx_http_upstream_fair_module.c:1010
#1 0x0000000000485882 in ngx_http_upstream_fair_walk_shm (shpool=0x7f2ab19ff000, node=0x7f2ab1a1c100,
sentinel=0x7f2ab1a17000, peers=0x9c999a0)
at ../nginx-upstream-fair/ngx_http_upstream_fair_module.c:1011
#2 0x0000000000485882 in ngx_http_upstream_fair_walk_shm (shpool=0x7f2ab19ff000, node=0x7f2ab1a1ba00,
sentinel=0x7f2ab1a17000, peers=0x9c999a0)
at ../nginx-upstream-fair/ngx_http_upstream_fair_module.c:1011
#3 0x00000000004858a5 in ngx_http_upstream_fair_walk_shm (shpool=0x7f2ab19ff000, node=0x7f2ab1a1b900,
sentinel=0x7f2ab1a17000, peers=0x9c999a0)
at ../nginx-upstream-fair/ngx_http_upstream_fair_module.c:1020
#4 0x0000000000485882 in ngx_http_upstream_fair_walk_shm (shpool=0x7f2ab19ff000, node=0x7f2ab1a18000,
sentinel=0x7f2ab1a17000, peers=0x9c999a0)
at ../nginx-upstream-fair/ngx_http_upstream_fair_module.c:1011
#5 0x0000000000485882 in ngx_http_upstream_fair_walk_shm (shpool=0x7f2ab19ff000, node=0x7f2ab1a19d00,
sentinel=0x7f2ab1a17000, peers=0x9c999a0)
at ../nginx-upstream-fair/ngx_http_upstream_fair_module.c:1011
#6 0x00000000004858a5 in ngx_http_upstream_fair_walk_shm (shpool=0x7f2ab19ff000, node=0x7f2ab1a19000,
sentinel=0x7f2ab1a17000, peers=0x9c999a0)
at ../nginx-upstream-fair/ngx_http_upstream_fair_module.c:1020
#7 0x0000000000485ae6 in ngx_http_upstream_fair_shm_alloc (r=0x2c308e0, us=)
at ../nginx-upstream-fair/ngx_http_upstream_fair_module.c:1058
#8 ngx_http_upstream_init_fair_peer (r=0x2c308e0, us=)
at ../nginx-upstream-fair/ngx_http_upstream_fair_module.c:1132
#9 0x000000000044f2da in ngx_http_upstream_init_request (r=0x2c308e0) at src/http/ngx_http_upstream.c:667
#10 0x0000000000444490 in ngx_http_read_client_request_body (r=0x7f2ab19ff000,
post_handler=0x44f620 <ngx_http_upstream_init>) at src/http/ngx_http_request_body.c:84
#11 0x0000000000472a0c in ngx_http_proxy_handler (r=0x2c308e0)
at src/http/modules/ngx_http_proxy_module.c:704
#12 0x0000000000433874 in ngx_http_core_content_phase (r=0x7f2ab19ff000, ph=0x71e7160)
at src/http/ngx_http_core_module.c:1408
#13 0x000000000042f95d in ngx_http_core_run_phases (r=0x2c308e0) at src/http/ngx_http_core_module.c:888
#14 0x000000000043b492 in ngx_http_process_request (r=0x2c308e0) at src/http/ngx_http_request.c:1828
#15 0x000000000043c36c in ngx_http_process_request_line (rev=0x8ea6b78) at src/http/ngx_http_request.c:940
#16 0x000000000041cd64 in ngx_event_process_posted (cycle=0x3917b10, posted=0x874588)
at src/event/ngx_event_posted.c:40
#17 0x0000000000424025 in ngx_worker_process_cycle (cycle=0x3917b10, data=)
at src/os/unix/ngx_process_cycle.c:807
#18 0x0000000000422324 in ngx_spawn_process (cycle=0x3917b10, proc=,
data=<value optimized out>, name=0x5bbb1b "worker process", respawn=-4)
at src/os/unix/ngx_process.c:198
#19 0x000000000042334c in ngx_start_worker_processes (cycle=0x3917b10, n=10, type=-4)
at src/os/unix/ngx_process_cycle.c:362
#20 0x0000000000424b10 in ngx_master_process_cycle (cycle=0x3917b10)
at src/os/unix/ngx_process_cycle.c:249
#21 0x0000000000405d3b in main (argc=, argv=)
at src/core/nginx.c:412
Nginx version data:
nginx -V
nginx version: nginx/1.4.7
built by gcc 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1)
TLS SNI support enabled
configure arguments: --prefix=/etc/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 --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/mnt/nginx/cache/client_temp --http-proxy-temp-path=/mnt/nginx/cache/proxy_temp --http-fastcgi-temp-path=/mnt/nginx/cache/fastcgi_temp --http-uwsgi-temp-path=/mnt/nginx/cache/uwsgi_temp --http-scgi-temp-path=/mnt/nginx/cache/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-file-aio --with-openssl-opt=no-krb5 --with-openssl=../openssl-1.0.1h --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security' --with-ld-opt=' -lossp-uuid -Wl,-Bsymbolic-functions -Wl,-z,relro' --add-module=../nginx-upstream-fair --add-module=../nginx-x-rid-header --with-ld-opt=-lossp-uuid --with-debug
Looks like a NULL dereference on node->left.
Please let me know if you need access to a core file; any help would be useful. Thank you!
seems module did not restore broken upstream server after fail recover.
I configured my upstream for load balancer.
upstream mysite {
fair;
ip_hash;
server 10.0.0.7:80;
server 10.0.0.153:80;
}
Btw, i got issue with sessions. I tried to comment out fair, then i didnt get the issue again. But upstream didn't deliver the requests to the second server. All requests came to the first server.
Do you have any idea? Any fixes? Thanks
2 ways to choose a best peer, but I'm having some problems as my peer connection was full due to slow response time, so I have some idea, is to choose the best peer-based on two factors:
Plase. help me.
If possible, please guide me how to write ideas on.
I am getting a build failure attempting to build the module on Ubuntu 11.10 (gcc 4.6).
gcc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Wunused-function -Wunused-variable -Wunused-value
-Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules -I src/mail
-o objs/addon/nginx-upstream-fair-7171df84c5/ngx_http_upstream_fair_module.o
These are the build errors I'm getting:
ngx_http_upstream_fair_module.c: In function ‘ngx_http_upstream_fair_update_nreq’:
ngx_http_upstream_fair_module.c:649:16: error: variable ‘total_nreq’ set but not used [-Werror=unused-but-set-variable]
ngx_http_upstream_fair_module.c:648:16: error: variable ‘nreq’ set but not used [-Werror=unused-but-set-variable]
cc1: all warnings being treated as errors
It only appears to occur if '--enable-debug' is not passed as a command-line option when building nginx.
Hi, we are trying to solve load-balancing imbalance on a heavily web-socket based system and require that individual sessions stay sticky.
upstream mongrel {
fair;
server cname1.abc.com:5000;
server cname2.abc.com:5001;
server 127.0.0.1:5002;
}
so why don't use the peer->shared-nreq as score directly to determine best_peer?
I can't see reason why using sched_socre function
becasuse the more nreq peer gets ,the high socre it gets.
besides,the what does the req_delta denote?
all back-end servers cur-connection or other(except this peer) servers cur-connection?
thanks
We have two Hybris Nodes and Apache on the same server of each as the reverse proxy - when one of the Hybris services brought down deliberately we found that Nginx keeps sending traffic to the down node.
Hello!
Is it possible to provide a LICENCE file with your module (perhaps 2-clause bsd like nginx source code)?
We are packaging nginx-upstream-fair in debian and we need to provide a licence in order to redistribute it.
Thank you,
chris
del
/root/nginx-upstream-fair-master/ngx_http_upstream_fair_module.c:553:51: 错误:ngx_http_upstream_srv_conf_t’没有名为‘default_port’的成员
I dont know why nginx does not know fair option :
unknown directive "fair" in /etc/nginx/sites-enabled/default:6
module "/usr/lib64/nginx/modules/ngx_http_geoip_module.so" is not binary compatible in /usr/share/nginx/modules/mod-http-geoip.conf
I have nginx running without upstream-fair. When compiling with upstream-fair, I get the following output: http://files.bradcater.webfactional.com/nginx_upstream_errors.txt (I tried pasting this in, but the formatting was terrible.)
What have I overlooked?
Hello,
I am looking for some help.
I tried to compile the balance fair module and receive the following error when run “make”
./configure --add-module=/usr/local/nginx/modules/nginx-upstream-fair-master
make
Assembler messages:
Fatal error: can't create objs/addon/nginx-upstream-fair-master/ngx_http_upstream_fair_module.o: Permission denied
/usr/local/nginx/modules/nginx-upstream-fair-master/ngx_http_upstream_fair_module.c: In function ângx_http_upstream_init_fair_rrâ:
/usr/local/nginx/modules/nginx-upstream-fair-master/ngx_http_upstream_fair_module.c:543:28: error: ângx_http_upstream_srv_conf_tâ has no member named âdefault_portâ
if (us->port == 0 && us->default_port == 0) {
^
/usr/local/nginx/modules/nginx-upstream-fair-master/ngx_http_upstream_fair_module.c:553:51: error: ângx_http_upstream_srv_conf_tâ has no member named âdefault_portâ
u.port = (in_port_t) (us->port ? us->port : us->default_port);
^
make[1]: *** [objs/addon/nginx-upstream-fair-master/ngx_http_upstream_fair_module.o] Error 2
make[1]: Leaving directory `/home/ece700/build/nginx-1.23.4'
make: *** [build] Error 2
I would appreciate any help and advice.
Thanks,
Martin
Hi,
I am trying to test nginx-upstream-fair. I setup a test vm with 2 additional vm's that serve up some content, I have it working already with haproxy, just testing various frontends. I setup this:
worker_processes 1;
events {
worker_connections 1024;
}
http {
upstream backend {
server node2.test123.com:5001;
server node3.test123.com:5001;
fair;
}
server {
listen 80;
server_name node1.test123.com;
location / {
proxy_pass http://backend;
}
}
}
for some reason when I try to access node1.test123.com from a browser it tries to do a web search on www.servers.com which I don't understand, is my syntax ok?
I maintain the nginx-naxsi package for Alpine Linux. Can you create a 0.10 release please so the build script stays consistent ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.