I don't think you will be able to do this purely in Apache.
There are quite a few Apache modules that do bandwidth limiting but I don't think any of them will match what you have described.
mod_bw can limit bandwidth based on various parts of the request. It can limit based on IP address, file extension, mime type, file size and directory (based on my reading of the docs). You achieve the directory-based limiting by placing the module's directives inside a <Directory >
block so I expect that they would work just as well inside a <Location >
block. mod_bwshare seems to go inside <Directory >
and <Location >
blocks as well.
The configuration of these Apache modules go into your Apache configuration and they don't look up values from any external source, meaning you will have to restart Apache to change any of the values. If you want to only throttle the bandwidth once a customer has gone over their quota, you will need to edit the Apache config files and restart Apache every time any of them does so and do it again when their quota usage expires.
They way I would do this is to write a small application in whatever language you use that accepts a request for a file, checks in the database for whether the customer is over quota and then sends them the file at whatever rate is appropriate. The guy who wrote mod_bw explained how he achieved the throttling: he simply divides the file into small "chunks" (say 5KB per chunk) and then has a short sleep()
in between echoing each chunk out to the client.
I would then use mod_rewrite
to make translate the original file requests (that you said look like /customer1/page1
) into something like /throttle.php?customer=customer1&file=page1
.
The app can write to the database at the start of the download to indicate that it is currently processing a file and again at the end to indicate that it is now finished. This should enable you to stop one customer from hogging all your Apache children.
The 5400zl series supports a very full feature list to provide quality of service (QoS) and traffic management. And for your specific requirement it also supports rate-limiting. Your best bet will be to upgrade to the latest version (K.15.8 at this point in time). The reference is the Advanced Traffic Management guide (current version)
What you need to do is
1. Define a class to match the traffic you wish to limit
2. Define a policy on how to treat the traffic
3. Apply the policy on a interface or VLAN
Something like the following should work:-
class ipv4 servers-to-be-slowed
match ip 1.2.3.4/32 any
match ip 1.2.3.5/32 any
exit
policy qos SlowBadServers
class servers-to-be-slowed action rate-limit kbps 1000
exit
interface all service-policy SlowBadServers in
I have written interface all
above but you probably want to apply it only to your so called head end connection
Best Answer
Probably your best chance will be something like http://bloke.org/apache/limit-apache-requests-per-ip-address-with-mod_limitipconn/
Also, since you are using ajp, I am going to assume that you are front ending tomcat. Another technique that my help is using an Async Servlet - https://plumbr.eu/blog/how-to-use-asynchronous-servlets-to-improve-performance