Testing Maximum Concurrent Request count in WSO2 Throttle Mediator for HTTP Transport
The Throttle Mediator can be used to restrict access to services. It is useful when it needs to avoid heavy loads which can cause performance issues.
This example tests for maximum number of concurrent requests that can pass through synapse in a single unit of time.
My proxy service is as below.
<?xml version="1.0" encoding="UTF-8"?><proxy xmlns="http://ws.apache.org/ns/synapse" name="Proxy1" startOnLoad="true" statistics="disable" trace="disable" transports="http,https">
<target>
<inSequence>
<throttle id="A">
<policy>
<wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:throttle="http://www.wso2.org/products/wso2commons/throttle">
<throttle:ThrottleAssertion>
<throttle:MaximumConcurrentAccess>100</throttle:MaximumConcurrentAccess>
</throttle:ThrottleAssertion>
</wsp:Policy>
</policy>
<onReject>
<log level="custom">
<property name="text" value="**Access Denied**"/>
</log>
<makefault response="true" version="soap11">
<code xmlns:tns="http://www.w3.org/2003/05/soap-envelope" value="tns:Receiver"/>
<reason value="**Access Denied**"/>
</makefault>
<send/>
<drop/>
</onReject>
<onAccept>
<log level="custom">
<property name="text" value="**Access Accept**"/>
</log>
<send>
<endpoint>
<address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
</endpoint>
</send>
</onAccept>
</throttle>
</inSequence>
<outSequence>
<throttle id="A"/>
<send/>
</outSequence>
</target>
<description/>
</proxy>
The MaximumConcurrentAccess is 10 which implies only 10 requests can pass through the synapse concurrently and others will be rejected. It will be printed a log as denied for the rejected messages.
Testing on Jmeter
We can test the above scenario in Jmeter as below.
- SimpleStockQuote backend should be started.
- Start Jmeter.
- Create a Test Plan which has a Thread Group
- Add a Sampler to Thread Group: HTTP Request
- Add HTTP Header Manager and set Content-Type as application/soap+xml
- Add a Synchronising Timer: This removes any latency in concurrent messaging.
- Add a Result Tree as a listener
- Configurations in HTTP Request as below.
- HTTP header Manager configs as below.
- Thread Group Configs should be set as below. It will send 110 concurrent requests to the proxy service.
Synchronizing Timer configs are as below.
As per our throttle policy, it only accepts only 10 concurrent requests. Here we are sending 25 requests. Therefore 15 requests need to be denied.
You can check the carbon logs and in the Results Tree in Jmeter.
For further reading please refer: