<div dir="ltr">Yesterday once I got the traffic going to the backend servers from nginx I noticed that I was pinned to "backend3", which is last in the order. And since I am the one setting this up I am the only user. So I changed up my order just to see the effects of calculating a new hash. Instead of:<div><br></div><div><span style="font-size:12.8px">upstream backend {</span><br></div><div>backend1</div><div>backend2</div><div>backend3</div><div>}</div><div><br></div><div>I listed them in the order:</div><div><br></div><div><span style="font-size:12.8px">upstream backend {</span><br></div><div>backend2</div><div>backend3</div><div>backend1 </div><div>}</div><div><br></div><div>then restarted nginx. At that point my traffic was pinned to backend1. This seems a bit odd to me in that it seems to be always choosing the last server in the order. Any thoughts on what might be happening and why it did not pin me to backend1 the first time and backend2 the second time?</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 27, 2016 at 8:44 PM, Robert Paprocki <span dir="ltr"><<a href="mailto:rpaprocki@fearnothingproductions.net" target="_blank">rpaprocki@fearnothingproductions.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div><br></div>I'm not as concerned with what server its routed to as much as I am concerned with the client session "sticking" to the server it was routed to. And I really do not know enough about how to use cookie based hashing. In order to have cookie bashed hashing would the cookie need to be common among all pages at the target URL in order to stick the session to a particular server for the duration of that session?</div></div></blockquote><div><br></div></span><div>Assuming you're using a cookie to track the session, the cookie shouldn't change depending on what URI the user is accessing.</div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div> (And, I assume cookie bashed hashing is not like ip hash in that you are only stuck to a particular server for the duration of that browser session?)<br></div></div></blockquote><div><br></div></span><div>Depends on how long the cookie lives on the browser. If the cookie never changes and doesn't expire when the browser closes, the backend wouldn't change (again, assuming nothing changed about the backend servers).</div><div><br></div><div>It doesn't matter what is used to build the hash key - cookie, ip, whatever. As long as that value doesn't change, and nothing changes about your backends, the client will hit the same backend every time. Guaranteed.</div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Also, what is the logic behind "round-robin" or is that the same as ip_hash? For instance, If I have a client at 192.168.100.10 that's assigned to backend 3, then, 100 more clients come along on the same subnet, they will all land on backend 3. Next client 192.168.200.10 comes along, what determines whether it lands on backend1 or backend2? Or, is there a chance it could also land on backend3?</div></blockquote><div><br></div></span><div>Round robin means that each backend will be used in turn, regardless of the client. For example, if you have 3 backends:</div><div><br></div><div>request 1 -> backend1</div><div>request 2 -> backend2</div><div>request 3 -> backend3</div><div>request 4 -> backend1</div><div>request 5 -> backend2</div><div><br></div><div>This goes on forever, regardless of the client IP. (Of course, this is relative if you are using server weights - see the example at <a href="http://nginx.org/en/docs/http/ngx_http_upstream_module.html#upstream" target="_blank">http://nginx.org/en/docs/http/ngx_http_upstream_module.html#upstream</a> for a round robin example with weights). If you want session persistence, then round robin balancing is not for you.</div></div></div></div>
<br>_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" rel="noreferrer" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br></blockquote></div><br></div>