Java heap space when running asynchronous script


I’m getting the following error when running a script from the client.

The avaiable memory for the client is set to the maximum value, 4096M, in the Project Properties. On the other hand my equipment has a 24 GB RAM which is quite far from reaching the 100% usage when I launch the script.

Traceback (most recent call last):
File “event:internalFrameActivated”, line 33, in longProcess
File “module:CHE”, line 10, in pred
java.lang.OutOfMemoryError: Java heap space
java.lang.OutOfMemoryError: java.lang.OutOfMemoryError: Java heap space

at org.python.core.Py.JavaError(
at org.python.core.Py.JavaError(
at org.python.core.PyReflectedFunction.__call__(
at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction.__call__(
at org.python.core.PyObject.__call__(
at org.python.core.PyObject.__call__(
at org.python.pycode._pyx10.pred$1(<module:CHE>:23)
at org.python.pycode._pyx10.call_function(<module:CHE>)
at org.python.core.PyFunction.__call__(
at org.python.pycode._pyx9.longProcess$1(<event:internalFrameActivated>:57)
at org.python.pycode._pyx9.call_function(<event:internalFrameActivated>)
at org.python.core.PyFunction.function___call__(
at org.python.core.PyFunction.__call__(
at org.python.core.PyFunction.__call__(
at org.python.core.PyFunction.__call__(
at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(
at com.inductiveautomation.ignition.client.script.DesignerSystemUtilities.lambda$_invokeAsyncImpl$1(
at java.base/ Source)

Caused by: java.lang.OutOfMemoryError: Java heap space

Ignition v8.0.12 (b2020042115)
Java: Azul Systems, Inc. 11.0.6

What’s the script doing that uses so much memory? It sounds like it needs some tweaking

Share your code. We can’t tell what might be happening without it.


This is the function:

> def pred(estacion):
> 	#la estación de Logroño es A280L67QRIO2
> 	api_key="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImlhdCI6MTU2MzQzODkyNTg4LCJkYXRhIjp7ImlkIjoxLCJuYW1lIjoiam9zZS5ncmFuZXJvIn19.ayJb-jGbEKg9ifEMy1fflJbI9rnnTv6ouHPLRHO3LwE"
> 	path=""+api_key
> 	obj = system.util.jsonDecode(source)
> 	data=[]
> 	for lista in obj['datos']:
> 		if lista['MS_TAG']==estacion:
> 			if t_stamp>
> 				data.append([t_stamp,lista['MS_VALOR']])
> 	headers=["t_stamp","value"]
> 	flow_forecast=system.dataset.toDataSet(headers,data)
> 	return flow_forecast

And this is the script from which we invoke it:

import CHE as m

	system.gui.getParentWindow(event).getComponentForPath('Root Container').vis_timer=1

	def longProcess(rootContainer = event.source.parent.parent):
		import system
		system.gui.getParentWindow(event).getComponentForPath('Root Container').Data=m.pred('A280L67QRIO2')
		system.gui.getParentWindow(event).getComponentForPath('Root Container').vis_timer=0
	print("Error de comunicación con CHE")

Remove that API key ASAP, you shouldn’t be sharing that with anyone everyone.
Also, what line is this: File “module:CHE”, line 10, in pred in the code you supplied?

Hi Jose,

Please edit your comment so the code blocks have the proper formatting marks (three reverse single quotes on a line by themselves, above and below), so it looks like this in the forum’s edit panel:
pasted code lines

The number of lines of code posted don’t match the line numbers in your original post’s error listing. Please clearly identify which line of code is failing (in the “pred” function).

That said, I suspect it is in jsonDecode, which can be very resource-intensive when the data from the service is malformed.

I already modified it, the key is not valid :smirk:

CHE is a library I created where the function “pred” is defined.

Hi Phil,

I’ve already edited the text, the two lines mentioned in the warning message are the following:

Line 33 in longProcess:


Line 10 in pred:

	obj = system.util.jsonDecode(source)

Thank you.

I think we’ll need to see the payload being passed to jsonDecode.

Hi Kevin,

Please find enclosed the file. (217.0 KB)

Yeah, I think @pturmel guessed somewhat correctly on this… you’re trying to parse 10MB of JSON and it’s running out of memory while doing so.

I’m not really sure what the workaround here is. You’d have to parse the JSON in a streaming manner somehow…

Ah, also, the payload you attached is not valid JSON. I don’t know if you truncated it intentionally or what, but it terminates early.

Thank you Kevin,

I truncated it by mistake.

I can’t figure out how to solve it.

Can you upload the non-truncated version? Might give us something to play around with and test.

1 Like

Hi Kevin,

Here you (461.9 KB)

Okay… now you’ve uploaded a word document for some reason?

Yes indeed, Kevin, I guess that because of the size, I couldn’t paste it in a txt file.

For anyone playing along I’ve attached a plain text file containing all the JSON (formatted / pretty printed). (544.9 KB)

Modifying your script to read the payload as a file, I had no issue.

I don’t know what your use case is, but you may want to consider processing this entirely on the gateway, and output all the sensor values to dataset tags, instead of running an api call every time and filtering out the ones you want.

Thank you Jordan, it is a valid workaround for our Central gateway but not for the Edge gateways where this information must be available.