Reputation: 19552
Is there a way to configure Tomcat to reject a request after a specific threshold number? E.g. after 506 requests start rejecting.
Is there such an option or am I supposed to write code for this?
Upvotes: 3
Views: 5633
Reputation: 20837
Tomcat's connectors can be configured to only service a certain number of requests simultaneously -- that's configured as the maxConnections
attribute of a <Connector>
in server.xml
. (You can also configure the acceptCount
but that's actually a queue of connections that the OS maintains that pile-up after maxConnections
has been reached). This limits simultaneous connections to Tomcat across all URLs -- that is, it's just total connections that are being limited.
If you want to limit the number of simultaneous connections to a specific URL (or specific set of URLs for that matter), you may have to write your own code. I've heard that Spring Security has a lot of QOS (quality-of-service) features like this that you might be able to use without writing your own code.
Otherwise, you'll be forced to write your own code -- probably a Filter
that simply keeps track of how many requests are in-progress and then rejecting those that come in after some limit has been reached. Beware of synchronization issues with counters being used across threads.
Upvotes: 4