JS transformation takes 10~15 seconds each call

  • Platform information:
    • Hardware: ARM64/3Gb/EMMC
    • OS: CentOS 7 / aarch64
    • Java Runtime Environment: OpenJDK Runtime Environment (Zulu 8.33.0.135-linux_aarch64) (build 1.8.0_192-b135)
    • openHAB version: 2.4.0

Hi,

using a javascript transformation to convert uptime into human readable format take very long time and high cpu usage (250%) on octa core cpu.

File: mqtt.things

Thing topic dummyTester “DummyTester”
{
Channels:
Type switch : switch_binary “Binary Switch” [ stateTopic="/thk/1/state", transformationPattern=“JSONPATH:$.state”, commandTopic="/thk/1/command", on=“ON”, off=“OFF” ]
Type string : uptime “Uptime” [ stateTopic="/thk/1/state", transformationPattern=“JS:switch_uptime.js” ]
Type string : freeheap “Free heap” [ stateTopic="/thk/1/state", transformationPattern=“JSONPATH:$.freeheap” ]
}

File: switch_uptime.js

‘use strict’;
load("/etc/openhab2/scripts/moment.js");
load("/etc/openhab2/scripts/moment-duration-format.js");

(function(i) {
var obj = JSON.parse(i);
var dur = moment.duration(obj.uptime);
return dur.format(“D [Days] h [Hours]”);
})(input);

File: openhab.log

2018-12-29 13:13:34.501 [DEBUG] [o.client.mqttv3.internal.ClientState] - openhab2: received bytes count=1
2018-12-29 13:13:34.502 [DEBUG] [o.client.mqttv3.internal.ClientState] - openhab2: received bytes count=42
2018-12-29 13:13:34.504 [DEBUG] [mqttv3.internal.wire.MqttInputStream] - null: Automatic Reconnect Successful: PUBLISH qos:0 retained:false dup:false topic:"/thk/1/state" payload:[hex:7b227374617465223a224f4646222c2266726565 utf8:"{“state”:“OFF”,“free” length:28]
2018-12-29 13:13:34.505 [DEBUG] [o.client.mqttv3.internal.ClientState] - openhab2: received key=0 message=PUBLISH qos:0 retained:false dup:false topic:"/thk/1/state" payload:[hex:7b227374617465223a224f4646222c2266726565 utf8:"{“state”:“OFF”,“free” length:28]
2018-12-29 13:13:34.506 [DEBUG] [client.mqttv3.internal.CommsCallback] - openhab2: new msg avail, notify workAvailable
2018-12-29 13:13:34.507 [DEBUG] [client.mqttv3.internal.CommsReceiver] - openhab2: network read message
2018-12-29 13:13:34.508 [DEBUG] [client.mqttv3.internal.CommsCallback] - openhab2: call messageArrived key=0 topic=/thk/1/state
2018-12-29 13:13:34.510 [DEBUG] [.jsonpath.internal.path.CompiledPath] - Evaluating path: $[‘state’]
— no logging output but this is the time the javascript processing occures —
2018-12-29 13:13:47.364 [DEBUG] [.jsonpath.internal.path.CompiledPath] - Evaluating path: $[‘freeheap’]

Is there a way to speedup javascript processing? Or a faster/better way to display the uptime of a thing?

Kind regards
Thomas

I don’t remember all the details but when using ARM it’s advised to use the 32 bit java version. Try installing 32 bit java version and see if that helps.

I do not see the point. Openhab2 is a headless java application. So it wont depend on the operating system nor the cpu architecture.

It looks like a bug/wrong handling of the javascript engine.

Is there a way to avoid the loading/unloading overhead? Memory is NO problem.

Kind regards
Thomas

Use the exec transformation and call “nodejs” :innocent: