5 ms·
I'm curious why would you enforce that from nginx itself, rather than put the app / nginx under a cgroup with appropriate limits.
by viraptor 10y ago
I'm curious why would you enforce that from nginx itself, rather than put the app / nginx under a cgroup with appropriate limits.
- vozlt 10y agoFirst of all, you can use "average of request processing times" which are not possible using other methods. Second of all this is a port of the tengine module used by Alibaba modified nginx, and I think it is more easy to use than other methods. Also when the load is to high, you can control what to do, what error/page will be shown. From a system engineering standpoint it is more easy, flexible, and appropriate to use.
- viraptor 10y agoI'm just trying to figure out tradeoffs here. The way I understand sysguard now, it will find out that the load is too high, after the load is too high. You can set the threshold lower to start limiting the traffic early on, but usage spikes will still get you. I'm trying to compare it to alternative solution which prevents the high load in the first place (puts limit on the CPU/mem shares). By limiting the app rather than nginx itself, you can still set the error page for the case where the backend is too busy (handle 502 bad gateway). The nice part of doing that at system level is that you can prioritise other processes over nginx, but otherwise ensure the app can take 100% CPU if nothing else is interested in using it.
- highclass 10y agoHave you personally tried other methods when having an overload of server traffic? Do you have a link showing a real setup of a better method? Of note, the module is a port from the nginx tuned by alibaba which is quite a credible source. I have served over a billion pageviews/month, and cutting off requests at a certain load threshold with a custom error page to users is a good idea. Otherwise the users will just get a huge slowdown or a backlog of requests which will cause a prolonged server recovery. Also as the author vozlt mentioned, you can use "average of request processing times" and custom http errors. Also, it is much easier to use than the methods you suggest.
- zzzcpan 10y agoThink how you can limit the load, but have as few users affected, as possible. And I mean users that make requests and are quick to leave if latency feels high for them, not system users. System doesn't make limiting decisions on per request basis to be useful for this.
- tokenizerrr 10y agoImplement once in nginx vs reimplement in dozens of (possibly third party) applications? Sounds good to me.
- Filligree 10y agoWhat do you expect the cgroup to do? It's the "throttle" step here which is important. When overloaded, drop requests; otherwise your server will overload and crash, which can be difficult to recover from.
- viraptor 10y agoYou can limit both the CPU shares and memory available to the app. (And network rate of it matters for the app) The result for the app server would be the same -> a throttle on the maximum number of requests it can serve. Your server will not overload and crash if your cgroup config prevents applications from taking all available resources.
- tyingq 10y agoServing up http errors is more polite to the end clients. Also, probably results in fewer people trying reload to get it working.
- viraptor 10y agoThat part already exists in nginx. Set up backend timeout and make a custom 502 page. It will kick in when the app is too busy.
- tyingq 10y agoThere's an avalanche problem though. Serving them up immediately when you know you're unhealthy shortens the recovery time. I don't know that this module is perfect for every situation, but I do know that timeouts don't work great when there's a general overload. Timeouts leave a higher number of concurrent connections there. I'd prefer a sort of priority queue setup where http clients that already "got in", "stay in", and newer connections are pushed away. Rate limiting per client first might be better as well.
- viraptor 10y ago
- skyde 10y agoActually you can still put nginx inside a cgroup and have nginx read the loadAvg inside the CGROUP instead of the global host loadAVG by calling getloadavg();