0

I have a server with a 30TB traffic allowance hosting (mostly) history images and would like to throttle one particular directory (the download image sizes) when necessary to avoid going over the limit. My thinking was that I could use either lighttpd with server.kbytes-per-second or create eth0:0 and then use wondershaper for simplicity and measure the traffic using netstat -i but putting this altogether is a bit complicated. I am (reasonably) sure there's already a ready made solution for ISPs but I can't find it.

chx
  • 1,665
  • 1
  • 16
  • 25
  • What behavior do you want when that limit is hit? Stop serving content, redirect somewhere else, give an error page, stop responding all together? – Aaron Jul 18 '16 at 17:35
  • Slow down gradually during the month so the limit is not hit. For example, if we hit 15TB then cut off to 15TB/(seconds left of the month), when we hit 14tB then cut off to 14TB/(seconds left of the month) and so on. – chx Jul 18 '16 at 19:24
  • [Here](http://serverfault.com/questions/30149/alternative-to-mod-throttle) are some ways you can limit traffic in apache. You could also put the specific URL on a different port and use `tc` to do traffic shaping, but that isn't meant to deal with quotas. What you are describing is a quota. I know this isn't the answer you are looking for, but really you should just add more nodes and load balance to increase your quota to avoid a bad user experience. – Aaron Jul 18 '16 at 21:14
  • I am already doing a favor by sponsoring the hosting of this site and throwing in more money is not exactly what I'd like to do... also, 30TB is an awful lot, even if people would download at 100mbit day and night it'd be enough. – chx Jul 18 '16 at 22:18
  • In that case, for limiting bw and even the number of connections, I would use [nginx access restrictions](https://www.nginx.com/resources/admin-guide/restricting-access/) and tune it to try to keep your total bw under your limit. There is also the [limit req module](http://nginx.org/en/docs/http/ngx_http_limit_req_module.html). To get much more accurate quota limits, you might need to serve the content through a cgi and track the bytes per interval in a file or db. – Aaron Jul 19 '16 at 14:52

0 Answers0