Scripted API Multiple Calls

puneetgoels1
Tera Guru

I have created a scripted web service, which has put and post methods. Put method itself calls an import set API.

This scripted web service is being used by a third party application asynchronously.  Issue is if they send multiple API calls it goes into deadlock for some calls and time out after max time and cancel the transactions. I checked with ServiceNow and they said that at once 8 threads can open for the API, which is too less as we can receive around 25 of them at a particular moment.

 

How can we handle this?

 

 

 

1 ACCEPTED SOLUTION

puneetgoels1
Tera Guru

So found solution for it

 

We have 2 application nodes. Each nodes can run 4 concurrent threads and their queue depth is 50 each. Having 2 nodes for the demo instance, at given time 8 threads can run and 100 can be on queue.

In this case , when we trigger 8 more import APIs from 8 Rest APIs at the same time, we are locking all these threads.

 

Then the problem starts. Each rest API will trigger another Import API transaction towards the instance and will wait for it to complete, as all the 8 spots are already taken they will never complete and eventually the transactions will be cancelled.

To resolve this i moved the second transaction under a script include instead of calling import API, this means that all the logic will be run under the first thread, avoiding triggering a second API and will not lock the semaphores. The problem described above happens when at least 8 transactions run in parallel.


 

View solution in original post

9 REPLIES 9

Second transaction was that of an import API after fetching the data from first transaction api and saving it in staging table.

 

That means the table already exist in the service now for second transaction

 

So instead of calling import api, I used glide record to insert the data in that table.

 

Use Case : Application V has a standard API for creation of incident with a defined JSON, I was consuming that JSON in our scripted api as transaction 1 and saving its data in a staging table.

then I was using import api for incident by reading data from staging table and inserting it into incident table. 

This was causing deadlock in case of multiple parallel calls.

 

So Instead of using import API, I used glide record to insert that data in incident table from staging table

I believe while this has solved the performance issue, it has added lot of code debt and administration overhead since now everything is inside a script include vs an import set, so if there are errors and need reprocessing then it would require developer skillset vs an admin skillet to reprocess an import set.
can you not have added some kind of a chaining so that all rest api calls wont happen in parallel there by allowing enough time for threads to free up and launch import sets.

Hi  @puneetgoels1 ,

I have scenario where I have one custom table it contains diff. request . Each request has 25 task. Each task is creating from diff. application / service. It means they all have diff API call. Based on certain condition in rest API I want to update delete those task based on request ID . 

Overall I want to update those system from ServiceNow based on task  with diff application. once we get "OK " reply from those system . ServiceNow will close these task successfully.

Which will be the best approach to it in ServiceNow.


Pls help or provide any documentation if you have 

were you able to resolve this problem

Not sure if I understood correctly. You want two way communications, Rest API updating your custom table and on the basis of that update you want to do some functionality in servicenow and then you want to update the various systems from servicenow.

 

1. APIs can update the custom table directly by the response or can be done through a transform map. and then you can have a business rule which will update the system as per requirement. 

2. You can use the same business rule or create a new one which will be calling APIs to update the systems from the servicenow