How to limit bandwidth consumption for user or client device
Your web site, application, or file hosting service has finite network and server resources available to it to serve all its users. One of the most important resources is bandwidth. Substantial bandwidth consumption by only a subset of the user base can result in network congestion and reduced resource availability to other users. To prevent network congestion, you might have to limit a client’s bandwidth consumption by using temporary service denial techniques such as responding to a client request with an HTML page if it has exceeded a preconfigured bandwidth value over a fixed time period leading up to the request.
In general, you can regulate bandwidth consumption either per client device or per user. This use case demonstrates how you can limit bandwidth consumption per client to 100 MB over a time period of one hour. The use case also demonstrates how you can regulate bandwidth consumption per user to 100 MB over a time period of one hour, by using a custom header that provides the user name. In both cases, the tracking of bandwidth consumption over a moving time period of one hour is achieved by setting the interval parameter in the stream identifier to 60 minutes. The use cases also demonstrate how you can import an HTML page to send to a client that has exceeded the limit. Importing an HTML page not only simplifies the configuration of the responder action in these use cases, but also simplifies the configuration of all responder actions that need the same response.
To limit bandwidth consumption per user or client device by using the command line interface
In the command-line interface, perform the following tasks to configure action analytics for limiting a client’s or user’s bandwidth consumption. Each step includes sample commands and their output.
Set up your load balancing configuration. Configure load balancing virtual server mysitevip, and then configure all the services that you need. Bind the services to the virtual server. The following example creates ten services and binds the services to mysitevip.
> add lb vserver mysitevip HTTP 192.0.2.17 80 Done > add service service[1-10] 192.0.2.[240-249] HTTP 80 service "service1" added service "service2" added service "service3" added . . . service "service10" added Done > bind lb vserver vserver1 service[1-10] service "service1" bound service "service2" bound service "service3" bound . . . service "service10" bound Done
Configure the stream selector. Configure one of the following stream selectors:
To limit bandwidth consumption per client, configure a stream selector that identifies the client IP address.
> add stream selector myselector CLIENT.IP.SRC Done
To limit bandwidth consumption per user on the basis of the value of a request header that provides the user name, configure a stream selector that identifies the header. In the following example, the name of the header is UserHeader.
> add stream selector myselector HTTP.REQ.HEADER(“UserHeader”) Done
Configure a stream identifier. Configure a stream identifier that uses the stream selector. Set the interval parameter to 60 minutes.
> add stream identifier myidentifier myselector -interval 60 -sampleCount 1 -sort BANDWIDTH Done
Configure the responder action. Import the HTML page that you want to send to users or clients that have exceeded the bandwidth consumption limit, and then use the page in responder action crossed_limits.
> import responder htmlpage http://192.0.2.20:80/stdpages/wait.html crossed-limits.html This operation may take some time, Please wait... Done > add responder action crossed_limits respondwithhtmlpage crossed-limits.html Done
Configure the responder policies. Configure responder policy myrespol1 with the rule ANALYTICS.STREAM(“myidentifier”).COLLECT_STATS and the action NOOP. Then, configure policy myrespol2 for determining whether a client or user has crossed the 100 MB limit. The policy myrespol2 is configured with the responder action crossed_limits.
> add responder policy myrespol1 'ANALYTICS.STREAM("myidentifier").COLLECT_STATS' NOOP Done > add responder policy myrespol2 'ANALYTICS.STREAM("myidentifier").BANDWIDTH.GT(1048576)' crossed_limits Done
Bind the responder policies to the load balancing virtual server. The policy myrespol1, which only collects statistical data, must have the higher priority and a GOTO expression of NEXT.
> bind lb vserver mysitevip -policyName myrespol1 -priority 1 -gotoPriorityExpression NEXT Done > bind lb vserver mysitevip -policyName myrespol2 -priority 2 -gotoPriorityExpression END Done
Test the configuration. Test the configuration by sending test HTTP requests, from multiple clients or users, to the load balancing virtual server and using the stat stream identifier command to view the statistics that are collected for the specified identifier. The following output displays statistics for clients.
> stat stream identifier myidentifier -sortBy BandW –fullValues Stream Session statistics Req BandW 192.0.2.30 5000 3761 192.0.2.31 29 2602 192.0.2.32 25 51 RspTime Conn 192.0.2.30 2 0 192.0.2.31 0 0 192.0.2.32 0 0 Done >