AnsweredAssumed Answered

RateLimit for PI Web API batch

Question asked by ckarras on May 8, 2019
Latest reply on May 8, 2019 by gregor

I'm using the /piweb/batch controller to retrieve a list of elements including their attributes. In a AF database with more than 998 elements, I get an error "429 Rate limit reached. The client sent more requests than the RateLimitMaxRequests within the RateLimitDuration.", even after doing a single batch request. 

 

Here is my request:

{
   "GetElements": {
   "Method": "GET",
   "Resource": "https://piserver/piwebapi/assetdatabases/{webId}/elements?searchFullHierarchy=true&selectedFields=Links.Next;Items.WebId;Items.Id;Items.Name;Items.Description;Items.Path;Items.Links.TemplateName;Items.Links.Attributes;Items.TemplateName&maxCount=1000"
},
"GetAttributesOfElements": {
   "Method": "GET",
   "RequestTemplate": {
   "Resource": "$.GetElements.Content.Items[*].Links.Attributes"
   },
   "ParentIds": [
     "GetElements"
   ]
},
}

And the response:

{
"GetAttributesOfElements": {
   "Status": 429,
   "Headers": {},
   "Content": "Rate limit reached. The client sent more requests than the RateLimitMaxRequests within the RateLimitDuration."
},
"GetElements": {
   "Status": 200,
   "Headers": {
   "Content-Type": "application/json; charset=utf-8",
   "Content": {
     "Links": /*...*/,
     "Items": /* List of the first 1000 items */
   }
},

 

If I change the maxCount to 999, I also get this error, but if I reduce it to 998, then I don't get the error anymore. So as I understand, this single batch request is counted as 1000 independent requests from the Rate Limiter's point of view:

- 1 request for the batch itself

- 1 request for "GetElements"

- 998 requests for "GetAttributesOfElements" for each individual element

 

This is a problem because I hoped using the batch API would improve performance and avoid reaching these rate limits. In the PI Web API 2018 User Guide, I see that RateLimitMaxRequests and RateLimitDuration can be configured to higher limits, but would there be a separate rate limit configuration that could be used for batch requests (I would like the default rate limits to be applied for individual HTTP calls, but a higher limit to be applied for multiple calls bundled into a single HTTP call)

 

Alternatively, this could be avoided by having an option in the Elements APIs to also retrieve all attributes of the returned elements, including nested attributes. More specifically, I'm using the "assetdatabases/{webId}/elements" and "elements/multiple" APIs for elements.

 

What would be the recommended solution, and can my suggested solutions be considered for a future version?

Outcomes