Lua implementation of “faster first” of NGINX load balancing strategy
Recently I implemented a load balancing strategy on NGINX, giving priority to backend services with the “shortest response time”. It is actually not very accurate to say that it is Nginx, because I actually used many modules packaged into NGINX in Openresty to achieve it, so it is more accurate to say that it is based on Openresty. The “fastest first” Lua implementation is available as part of my Nginx configuration at dynamic-upstream-weight.lua. In addition to Lua, we also need two global Key-Value caches as the data basis for adjusting the load strategy. For configuration details, see my NGINX site configuration blog.jamespan.me. In order to achieve this load balancing feature, I modified lua-upstream-nginx-module and added a Lua API to modify the weight of upstream server. For details, see commit 6b40d40a4 of JamesPan/lua-upstream-nginx-module. The “fastest first” load balancing strategy is actually a kind of “unbalanced load” strategy. Projected into reality, it seems that the more capable a person is, the more work he needs to do in the end, until one day he is overwhelmed. It is the legendary “those who can do more work”. I am trying to write an NGINX module in C to implement this “faster first” strategy.…