Forums

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

Why does my code runs 10 times slower as a post function compared to the console

Gaston November 22, 2023

I have two Jira Servers, in a workflow I have groovy code (Scriptrunner's  Custom script post-function) that calls the Jira v2 api to create an issue on the other server.

Running the code as a post-function in a workflow transition, it takes 22 seconds to complete, while running the same code in Scriptrunner's Console takes only 3.

 

Why is that happening?

 

 


def currentUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser().getUsername()
def jiraAuthenticationContext = ComponentAccessor.getJiraAuthenticationContext()
def originalUser = jiraAuthenticationContext.getLoggedInUser()
def newUser = Users.getByName('...')
def appLinkService = ComponentLocator.getComponent(ApplicationLinkService)
def appLink = appLinkService.getPrimaryApplicationLink(JiraApplicationType)
def Ambiente= appLinkService.getPrimaryApplicationLink(JiraApplicationType).getName()

def post1 = ("/rest/api/2/issue/" )
def input1 = null

input1 = new JsonBuilder([
"fields": [
"project": [
"id": "..."
],
"summary": "...",
"description": "...",
"issuetype": [
"id": "..."
],
"reporter": ["name": currentUser],
"assignee": ["name": currentUser],
"customfield_12723":"..."
]
]).toString()
}

try {
def applicationLinkRequestFactory = appLink.createAuthenticatedRequestFactory()
def request1 = applicationLinkRequestFactory.createRequest(POST, post1)
.addHeader("Content-Type", "application/json")
.setEntity(input1)
.setSoTimeout(40000)

request1.execute()
}

finally {
}

 

2 answers

1 accepted

1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
November 22, 2023

Hi @Gaston

This is a very subjective question. Firstly, how many Post-Functions do you have in the transition you are testing with?

Also, could you share the code you are using so I can review it and provide some feedback?

Looking forward to your feedback and clarification.

Thank you and Kind regards,
Ram

Gaston November 23, 2023

Sorry, I've updated the question

 

I've set log.debug before and after the execute to measure time, and it takes 23 seconds as a postfunction and 3 seconds in the scriptrunner's console

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
November 23, 2023

Hi @Gaston

When running this via the Post-Function, do you have any other Post-Functions configured for this transition? If yes, please try to move this Post-Function to the very top.

Also, from the code you shared, you are trying to create a new Issue via Post-Function. Please confirm if this is correct.

If yes, I would advise you to change your approach and simplify it using ScriptRunner's HAPI feature, as shown in this ScriptRunner Documentation.

I am looking forward to your feedback and clarification.

Thank you and Kind regards,

Ram

Gaston November 23, 2023

I just moved the post-function to the very top and it dropped to 3 seconds.

 

Why is that?

 

postfunction.png

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
November 23, 2023

Hi @Gaston

Well, it appears that the other Post-Function(s) above it were taking a bit of time, resulting in the delay. Now that you have moved it to the very top, it will be the first to execute so there won't be any more delays for it.

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

Gaston November 23, 2023

Yes, but I've set log.debug before and after 

request1.execute()

to measure time.

 

Do the transition's postfuntions run in parallel and affect each other's execution time? 

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
November 23, 2023

Hi @Gaston

In your last comment, you mentioned:-

Yes, but I've set log.debug before and after 

request1.execute()

to measure time.

What difference have you observed when placing the Post-Function at the bottom and moving it to the very top?

You also asked:

Does the transition's postfuntions run in parallel and affect each other's execution time? 

No, they don't run in parallel. It's top to bottom.

Thank you and Kind regards,

Ram

Gaston November 23, 2023
log.debug "checkpoint"
request1.execute()
log.debug "checkpoint"

With the postfunction in the last place

2023-11-20 17:03:57,320 DEBUG [groovy.CreaIssueEnJSW]: checkpoint

2023-11-20 17:04:19,376 DEBUG [groovy.CreaIssueEnJSW]: checkpoint


With the postfunction first

2023-11-23 09:27:18,818 DEBUG [groovy.CreaIssueEnJSW]: checkpoint

2023-11-23 09:27:20,800 DEBUG [groovy.CreaIssueEnJSW]: checkpoint

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
November 23, 2023

Hi @Gaston

Right, so logging the time will not be of much use since it will display the same time to execute.

But the actual execution time will only take effect if it is either placed on the very top of the Post-Function list or if the other Post-Functions don't take much time; in your case, only the former seems to work without much delay.

Thank you and Kind regards,

Ram

Gaston November 23, 2023

the whole transition in fact went down from 20 seconds to 2 after placing this postfunction first.

 

But what's the technical explanation? What's happening under the hood?

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
November 23, 2023

Hi @Gaston 

A simple test you can do is disable all other Post-Functions in that transition except for the one you are testing now, i.e. which uses ScriptRunner, and run it again. You could now even move the Post-Function to the very bottom.

This will prove that this Post-Function is not causing the delay, but another Post-Function is. Once you run the test with only the ScriptRunner Post-Function enabled, start re-enabling your other Post-Functions one by one till it slows down. Doing this you will be able to narrow down which Post-Function is actually causing the delay.

Thank you and Kind regards,

Ram

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
November 25, 2023

Hi @Gaston

Has your question been answered?

If yes, please accept the answer.

Thank you and Kind regards,

Ram

0 votes
Christopher Maxwell
Community Champion
November 23, 2023

@Ram Kumar Aravindakshan _Adaptavist_ I just read through this ticket - thanks for taking the time to share. Not only did it help Gaston, but was good information for me as well.

Suggest an answer

Log in or Sign up to answer