2
votes

I am using wso2-am 2.0.0 to achieve rate limiting for APIs. I have published an API with one user and it is then subscribed by another user. While subscribing, I am selecting a subscription tier of 20 requests per minute for that API. Also, the Application used to subscribe to the API, has a limit of 50 requests per minute. Now, when I am testing the API, only Application level rate limiting is happening after around 50 requests. The API level limit is not applied. Ideally the user should not be able to access the API after 20 requests. I am using windows machine to setup the wso2 server and Apache JMeter to send requests to the server. What am I missing here? Need some help...

1
Are you using default advanced throttling? - Bee
While publishing the API, I have set this... Advanced Throttling Policies: I have selected "Apply to API level" and have put the value as "Unlimited" from the dropdown. - siddhesh
If you created new subscription policy (which is 20 per min) properly, it should throttle as expected. Can you post the corresponding policy file in wso2am-2.0.0/repository/deployment/server/executionplans? - Bee
Is this the location from where policies are picked up by server while checking for limits for incoming API requests? Actually the newly created tier is not present at that location. I was getting a backend error on wso2 console while trying to save a new tier (either subscription or application). For this issue, I have already raised a question here link. The entry for the tier is there in WSO2CARBON_DB. - siddhesh
One more thing, the Application level and API level limiting is working for default tiers available. I am not sure the issue for newly created tiers is because of the backend error I am getting while saving it... - siddhesh

1 Answers

0
votes

Here is a 4MB/s policy.

    @Plan:name('carbon.super_app_BandwidthPolicy')
    @Plan:description('ExecutionPlan for app_BandwidthPolicy')

    @Import('org.wso2.throttle.processed.request.stream:1.0.0')
    define stream RequestStream (messageID string, appKey string, appTier string, subscriptionKey string, apiKey string, apiTier string, subscriptionTier string, resourceKey string, resourceTier string, userId string,  apiContext string, apiVersion string, appTenant string, apiTenant string, appId string, apiName string, propertiesMap string);

    @Export('org.wso2.throttle.globalThrottle.stream:1.0.0')
    define stream GlobalThrottleStream (throttleKey string, isThrottled bool, expiryTimeStamp long);

    FROM RequestStream
    SELECT messageID, (appTenant == 'carbon.super' and appTier == 'BandwidthPolicy') AS isEligible, appKey AS throttleKey, propertiesMap
    INSERT INTO EligibilityStream;

            FROM EligibilityStream[isEligible==true]#throttler:timeBatch(1 min, 0)
            select throttleKey, (sum(cast(map:get(propertiesMap,'messageSize'),'long')) >= 4194304) as isThrottled, expiryTimeStamp group by throttleKey
            INSERT ALL EVENTS into ResultStream;

    from ResultStream#throttler:emitOnStateChange(throttleKey, isThrottled)
    select *
    insert into GlobalThrottleStream;