Got a gateway here that need to do allot of API calls.
Using the system.net.httpGet() everything runs smoothly but slower.
When I use system.net.httpClient() things are moving much faster but I receive this error:
1.Error executing tag event script: java.io.IOException: java.io.IOException: Unable to GET “the url”
2.Clock drift, degraded performance, or pause-the-world detected. Max allowed deviation=1000ms, actual deviation=64534ms
I’ve created the following test tags that need to run 10k API call each.
Here I’m using system.net.httpClient(), and at about 5k I’m getting the error
if str(currentValue.quality).upper() == 'GOOD' and str(previousValue.quality).upper() == 'GOOD':
if currentValue.value == 1:
i = 1
while i < 10000:
i += 1
test = L2L.API.getAreas()
system.tag.write("[.]newAPI", i)
Gateway Scripts
L2L.API.GetAreas:
def getAreas(extraURL = None, extraParameters = None):
# Default URL
url = "%(url)s%(api)sareas/?auth=%(auth)s&site=%(site)s&fields=%(fields)s"
# Default parameters
parameters = {}
parameters["fields"] = "code"
# Adding extra values to the request, overithing if already defined
if isinstance(extraURL, str):
url = url + extraURL
if isinstance(extraParameters, dict):
parameters.update(extraParameters)
return L2L.HttpHelper.clientHttpRequest("GET", url, parameters)
L2L.HttpHelpper:
logger = system.util.getLogger('L2L-HttpHelper')
# Creating an instance of httpClient
client = system.net.httpClient()
# Define a dictionary with available methods.
requestMethods = {}
requestMethods["GET"] = client.get
requestMethods["POST"] = client.post
def getSiteVariables():
# Define a tuple with L2L parameters.
tags = ("url", "auth", "site", "api")
# Generate a list with path of parameters and read values.
tagPaths = []
for tag in tags:
tagPaths.append("Config/L2L/%s" %tag)
tagValues = system.tag.readAll(tagPaths)
# Generate a dictionary.
l2lParameters = {}
idx = 0
for tag in tags:
l2lParameters[tag] = tagValues[idx].value
idx += 1
return l2lParameters
def clientHttpRequest(method, url, paramaters):
# Cheking parameters type.
if not isinstance(method, str):
logger.error("Function clientHttpRequest recieved invalid parameter type for (method), expected str got " + str(type(method)))
return None
if not isinstance(url, str):
logger.error("Function clientHttpRequest recieved invalid parameter type for (url), expected str got " + str(type(url)))
return None
if not isinstance(paramaters, dict):
logger.error("Function clientHttpRequest recieved invalid parameter type for (paramaters), expected dict got " + str(type(paramaters)))
return None
# Generating dictionary with all parameters
l2lParameters = getSiteVariables()
l2lParameters.update(paramaters)
# Attaching parameters to url and replace spaces.
try:
l2lURL = url %l2lParameters
formatedURL = l2lURL.replace(" ", "%20")
except Exception, e:
logger.error("Function clientHttpRequest failed to generate the L2L url.")
raise Exception(str(e))
# Run the http request.
try:
response = requestMethods[method.upper()](formatedURL)
if response.isGood():
responseData = response.getJson()
if responseData["success"]:
return responseData["data"]
else:
logger.error("Function clientHttpRequest " + str(responseData["error"]))
else:
logger.error("Function clientHttpRequest response.isGood: " + str(response.isGood()))
except Exception, e:
logger.error("Function clientHttpRequest failed to run the http request: "+ str(e))
raise Exception(str(e))
return None
def l2lTimeFormat(timeStamp):
try:
return system.date.format(timeStamp, "yyyy-MM-dd HH:mm")
except Exception, e:
logger.error("Function l2lTimeFormat failed to format the timeStamp: "+ str(e))
raise Exception(str(e))
No, sorry, I can’t see anything obviously wrong. I thought maybe you were doing an async call with system.net.httpClient and allowing them to pile up in memory or something but that’s not the case.
I think you’ll have to work with support to further diagnose and maybe they will try to reproduce this.
Hi Bogdan. I'm getting the same error message today on Ignition 8.1.23. The script I'm running works when I execute it in a script console, but it fails when running from a scheduled gateway script. Did you ever contact support for an explanation?