Best Practice 3_Performance_TM: Use executeAsync() instead of execute()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited 2 hours ago
Within your scripts like BRs, UI action etc - you may have observed, most of the time you have used execute method() when you are using RESTMessageV2 or SOAPMessageV2 to send the Request payload.
ServiceNow recommendation is to use executeAsync() instead of execute() for outbound request.
Impact: If you don't implement it, it can impact Platform Performance
It can decrease your Platform Security Hardening score
When to use execute() and things to think about when using it:
- This method should only be used for very quick service calls and should not be called in very high volume no matter how quick the service.
- Only use execute when the timeout is very short, otherwise, the instance can be brought to a standstill. There are 2 properties to focus on for this, glide.http.timeout and glide.http.connection_timeout. By default (property not set in properties table) these are set to 175 seconds and 10 seconds respectively.
- Generally, you should not use this method if the request must go through the MID. MID requests must go through the ECC queue which is an asynchronous queue in the first place. The thread will not only be held up by the request itself but it will also be held up by waiting for the MID server to respond back to the instance. If MIDs are involved it is highly recommended to use asynchronous calls with a sensor business rule (see examples below).
When to use executeAsync() and things to think about when using:
- When you don't care about the response it is better to use executeAsync ("fire and forget")
- When your request is very large or has the potential to take a long time. From there, if you need the response then you can set up a sensor business rule to listen to the ecc_queue for the response.
- Generally, you should be using executeAsync whenever you can as it is the safer option.
- Calling waitForResponse() right after calling executeAsync() essentially turns this method into a simple execute() method and should only be used with very short wait times.
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0716391
#Article #Best Practice
