Script execution delay

I encountered an issue while running my gateway script triggered by the tag value. During script execution, I experienced a time delay issue(the script usually runs in 700-800 ms. but for every 8 mints it takes 20 sec to execute).

I have attached my script here. Please check & help me to resolve ...

if you see the script the line "BandValdStart = system.date.now()" and " Bandprinted = system.date.format(Bandprinted, "yyyy-MM-dd HH:mm:ss.SSS")" got delay everytime. API is not taking time. but there is not much in between this lines, still why it takes delay to execute?

why this happens at 8 mint regular interview? If i do the script in label also i am facing the same issue.

I would appreciate your suggestions...
MyGatewayscript.py (25.4 KB)