cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Best way to implement 5000 api calls in a single service execution

SP_10199785
4-Participant

Best way to implement 5000 api calls in a single service execution

I am calling an API 5000 times in a for loop with separate key id's , its taking sometime to fetch the data and update in the datatable and is getting script timeout after 10 minute(600 seconds). 

Can anyone suggest an efficient way to handle this scenario and for an optimized solution.

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @SP_10199785 

 

I have 2 ideas to optimize your case

1. You can try to make the service an async service by ticking Async on the left-hand side script editor. This way ThingWorx would create another thread 
https://www.ptc.com/en/support/article/CS261852
https://www.ptc.com/en/support/article/CS222280

2. Optimize your script by following JavaScript best practices
https://support.ptc.com/help/thingworx/platform/r9/en/index.html#page/ThingWorx/Help/Best_Practices_for_Developing_Applications/JavaScriptCodingBestPractices.html

Hope this answer helps you

Thanks

View solution in original post

5 REPLIES 5

@SP_10199785 ,

 

How often do you need to run this service?  Once a day? Once a minute/hour? If you don't have to run it very often, you can just set up a scheduler and increase your script timeout in the ThingWorx configuration.

 

-Nick

SP_10199785
4-Participant
(To:nmilleson)

Hi,

 

I need to run this service every 2hrs and sometimes manually triggered by user on updations. 

Increasing the timeout to 30min would cause an impact on the thingworx performance and others services too.

 

Thank You

 

Hi @SP_10199785 

 

I have 2 ideas to optimize your case

1. You can try to make the service an async service by ticking Async on the left-hand side script editor. This way ThingWorx would create another thread 
https://www.ptc.com/en/support/article/CS261852
https://www.ptc.com/en/support/article/CS222280

2. Optimize your script by following JavaScript best practices
https://support.ptc.com/help/thingworx/platform/r9/en/index.html#page/ThingWorx/Help/Best_Practices_for_Developing_Applications/JavaScriptCodingBestPractices.html

Hope this answer helps you

Thanks

SP_10199785
4-Participant
(To:danmorin)

Hi 

 

The Async service is causing the server to be down as async service is fetching the data from the API and updating the datatable in a synchronous manner which is creating a deadlock.

Can you please suggest 

 

Thanks

Sonali

Hi @SP_10199785 

 

In that case, you need to look down at this table, 5000 API Calls mean 5000 HTTP requests per second. You need to queue it manually to match this RPS base on your ThingWorx Server Size.

 

https://support.ptc.com/help/thingworx/platform/r9/en/index.html#page/ThingWorx/Help/Installation/Sizing/compare_sizing_criteria_to_guidelines.html#

danmorin_0-1663165814182.png

 

Thanks

 

Top Tags