Maximum of lua scripts?

Moderator: leecollings

User avatar
JohnnySK
Posts: 25
Joined: Thursday 28 May 2015 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Slovakia
Contact:

Maximum of lua scripts?

Post by JohnnySK »

Raspberrypi 3,
latest stable release of Domoticz

I have 14 devices scripts, 6 time scripts and 3pcs of variable scripts and one of devices scripts work calculation with 10 devices (each 5seconds) .. and I'm getting delay in reactions of other lua scripts.
Is it any maximum of lua scripts?
Is it better write scripts in some other languages ? (because of performance)
Maybe python scripts running out of domoticz core and have better performance ??
thanks for help.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Maximum of lua scripts?

Post by waaren »

JohnnySK wrote: Monday 29 March 2021 20:34
I have 14 devices scripts, 6 time scripts and 3pcs of variable scripts and one of devices scripts work calculation with 10 devices (each 5seconds) .. and I'm getting delay in reactions of other lua scripts.
The Lua language interpreter by itself is very close to C and switching to another (script) language will not improve performance as such.
The way classic Lua scripts are implemented in domoticz might cause your issue.
Every device script is executed on every device update in the system and every time script is executed every minute and every variable script is executed every variable update, etc.
Every script trigger will receive a copy of the domoticz object with many sub-tables.

This is the reason why @Dannybloe and @jvandenbroek designed and integrated dzVents in domoticz. In dzVents only 1 Lua script is triggered for these events (device, time, variable, etc) and that single Lua scripts only loads the user scripts when needed.
This improves response times significantly, especially when the number of scripts rises.

You might want to have a look at the dzVents wiki
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
JohnnySK
Posts: 25
Joined: Thursday 28 May 2015 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Slovakia
Contact:

Re: Maximum of lua scripts?

Post by JohnnySK »

I have onchange condition in each script.
When I last time enabled dzVents, Domoticz freezes few times in hour :-D
I will try it again.
Thanks for now.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Maximum of lua scripts?

Post by waaren »

JohnnySK wrote: Monday 29 March 2021 23:31 I have onchange condition in each script.
That will not prevent the script from being triggered.
In my experience the script itself is hardly ever causing a response issue if you don't use blocking commands like os.execute or io.popen.

For these type of commands dzVents have async alternatives.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
JohnnySK
Posts: 25
Joined: Thursday 28 May 2015 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Slovakia
Contact:

Re: Maximum of lua scripts?

Post by JohnnySK »

Yes,
maybe this is problem.. I have os.execute in one script.. I will move this one to the dzVents.
jannl
Posts: 673
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Maximum of lua scripts?

Post by jannl »

Propably all the commandArray commands are causing the delay.

Do as suggested above, use dzVents, or create your own containerscript like I did, partly because dzVents did not exist at the time and partly because I better like the straight forward programming.


Jan
manjh
Posts: 748
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Maximum of lua scripts?

Post by manjh »

I have a script that runs for about 30 seconds, and I fully understand why (this is OK, not an error).
In LUA it throws a warning that the script runs for more than 10 seconds.
So I decided to move the function to a dzVents script, hoping to lose the error. Not so, it gives me the same error message...
Is there a way around this, or should I learn to live with it?
Hans
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Maximum of lua scripts?

Post by waaren »

manjh wrote: Tuesday 30 March 2021 21:20 Is there a way around this, or should I learn to live with it?
Best to share the script. That might help in understand why the 30 seconds are needed and to advise a possible work around (if any)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
jvdz
Posts: 2330
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Maximum of lua scripts?

Post by jvdz »

manjh wrote: Tuesday 30 March 2021 21:20 I have a script that runs for about 30 seconds, and I fully understand why (this is OK, not an error).
In LUA it throws a warning that the script runs for more than 10 seconds.
Well, it isn't really OK as you are "hanging" the whole event system due to it being single threaded.
One should really run these script in an async way by either shelling it with os.execute("command &") or running it by crontab, but it can't obviously not have an commandArray returning any updates, so those would have to be done with JSON calls in the script.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Maximum of lua scripts?

Post by waaren »

jvdz wrote: Tuesday 30 March 2021 22:16 Well, it isn't really OK as you are "hanging" the whole event system due to it being single threaded.
One should really run these script in an async way by either shelling it with os.execute("command &") or running it by crontab
Or even better use dzVents async executeShellCommand() in combination with shellCommandResponses (available in domoticz >= build 12771)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
JohnnySK
Posts: 25
Joined: Thursday 28 May 2015 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Slovakia
Contact:

Re: Maximum of lua scripts?

Post by JohnnySK »

waaren wrote: Tuesday 30 March 2021 22:25
jvdz wrote: Tuesday 30 March 2021 22:16 Well, it isn't really OK as you are "hanging" the whole event system due to it being single threaded.
One should really run these script in an async way by either shelling it with os.execute("command &") or running it by crontab
Or even better use dzVents async executeShellCommand() in combination with shellCommandResponses (available in domoticz >= build 12771)
build 12771 ... I must update to latest beta.. aaand when I last time tried it.. lot of energy devices doesn't have any value and part of house not worked anymore :-D so I reverted back to backup of release..
When I see issue list in latest beta.. it's little bit risky.. or not ??
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Maximum of lua scripts?

Post by waaren »

JohnnySK wrote: Wednesday 31 March 2021 0:32 it's little bit risky.. or not ??
Risk can be mitigated by ensuring you have a recent and tested backup of your domoticz directory and subdirectory's (exclude the backups subdirectory)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
JohnnySK
Posts: 25
Joined: Thursday 28 May 2015 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Slovakia
Contact:

Re: Maximum of lua scripts?

Post by JohnnySK »

Update looks good but I have this in log and I'm trying to search at forum but without success..

2021-03-31 21:17:40.579 Error: unable to remove file /home/pi/domoticz/scripts/dzVents/data/domscript1017.out
2021-03-31 21:17:40.580 Error: unable to remove file /home/pi/domoticz/scripts/dzVents/data/domscript1017.err
2021-03-31 21:19:28.442 Error: unable to remove file /home/pi/domoticz/scripts/dzVents/data/domscript1062.out
2021-03-31 21:19:28.442 Error: unable to remove file /home/pi/domoticz/scripts/dzVents/data/domscript1062.err
2021-03-31 21:23:40.904 Error: unable to remove file /home/pi/domoticz/scripts/dzVents/data/domscript1163.out
2021-03-31 21:23:40.904 Error: unable to remove file /home/pi/domoticz/scripts/dzVents/data/domscript1163.err
2021-03-31 21:24:17.896 Error: unable to remove file /home/pi/domoticz/scripts/dzVents/data/domscript1177.out
2021-03-31 21:24:17.896 Error: unable to remove file /home/pi/domoticz/scripts/dzVents/data/domscript1177.err
2021-03-31 21:28:18.573 Error: unable to remove file /home/pi/domoticz/scripts/dzVents/data/domscript1274.out
2021-03-31 21:28:18.573 Error: unable to remove file /home/pi/domoticz/scripts/dzVents/data/domscript1274.err
2021-03-31 21:30:13.902 Error: unable to remove file /home/pi/domoticz/scripts/dzVents/data/domscript1321.out
2021-03-31 21:30:13.902 Error: unable to remove file /home/pi/domoticz/scripts/dzVents/data/domscript1321.err
2021-03-31 21:32:11.882 Error: unable to remove file /home/pi/domoticz/scripts/dzVents/data/domscript1368.out
2021-03-31 21:32:11.882 Error: unable to remove file /home/pi/domoticz/scripts/dzVents/data/domscript1368.err
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Maximum of lua scripts?

Post by waaren »

JohnnySK wrote: Wednesday 31 March 2021 21:36 Update looks good but I have this in log and I'm trying to search at forum but without success..

2021-03-31 21:17:40.579 Error: unable to remove file /home/pi/domoticz/scripts/dzVents/data/domscript1017.out
2021-03-31 21:17:40.580 Error: unable to remove file /home/pi/domoticz/scripts/dzVents/data/domscript1017.err
...
2021-03-31 21:32:11.882 Error: unable to remove file /home/pi/domoticz/scripts/dzVents/data/domscript1368.err
Seems to be an authorisation issue. These files should not be in /home/pi/domoticz/scripts/dzVents/data/ and can be removed from the command line using

Code: Select all

sudo rm /home/pi/domoticz/scripts/dzVents/data/*.out /home/pi/domoticz/scripts/dzVents/data/*.err 
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
JohnnySK
Posts: 25
Joined: Thursday 28 May 2015 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Slovakia
Contact:

Re: Maximum of lua scripts?

Post by JohnnySK »

I tried change permissions on whole folder.
Files create domoticz and removing them too.. They are connected to my first dzVents skript where I'm using domoticz.executeShellCommand().
But I don't know why domoticz wont again remove already removed files.
manjh
Posts: 748
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Maximum of lua scripts?

Post by manjh »

waaren wrote: Tuesday 30 March 2021 21:39
manjh wrote: Tuesday 30 March 2021 21:20 Is there a way around this, or should I learn to live with it?
Best to share the script. That might help in understand why the 30 seconds are needed and to advise a possible work around (if any)
Script is very simple. It starts a speedtest to measure line speeds.

Code: Select all

return {
	on = {
		devices = {
			'Utrecht speedtest trigger'
		}
	},
	execute = function(domoticz, device)
	    if (device.state =='On') then
	        print ("speedtest_device_dzvents starting speedtest measurement")
	        os.execute ("sudo bash /home/pi/domoticz/scripts/speedtest2.sh")
           end
	end
}
As you can see, there is no result flowing back from this script. The speedtest2.sh bash file stores results straight into virtual devices.

I tried to use this:

Code: Select all

domoticz.executeShellCommand('/home/pi/domoticz/scripts/speedtest2.sh')
but am getting an error:

Code: Select all

2021-03-31 22:28:41.852 Error: dzVents: Error: (3.0.2) An error occurred when calling event handler Speedtest_device
2021-03-31 22:28:41.852 Error: dzVents: Error: (3.0.2) ...z/scripts/dzVents/generated_scripts/Speedtest_device.lua:11: attempt to call a nil value (field 'executeShellCommand')
Last edited by manjh on Wednesday 31 March 2021 22:30, edited 2 times in total.
Hans
User avatar
JohnnySK
Posts: 25
Joined: Thursday 28 May 2015 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Slovakia
Contact:

Re: Maximum of lua scripts?

Post by JohnnySK »

I have it similar

Code: Select all

return {
        on = {
                devices = {
                        'Batt Napatie'
                }
        },
        execute = function(domoticz, device)
                domoticz.executeShellCommand('/home/pi/domoticz/scripts/pv_fpv1.sh &')
                domoticz.executeShellCommand('/home/pi/domoticz/scripts/pv_fpv2.sh &')
        end
}
scripts have --silent parameter in each call.. so doesn't have output.. but files appear and disappear in data folder and errors still comming
User avatar
JohnnySK
Posts: 25
Joined: Thursday 28 May 2015 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Slovakia
Contact:

Re: Maximum of lua scripts?

Post by JohnnySK »

I tried to use this:

Code: Select all

domoticz.executeShellCommand('/home/pi/domoticz/scripts/speedtest2.sh')
but am getting an error:

Code: Select all

2021-03-31 22:28:41.852 Error: dzVents: Error: (3.0.2) An error occurred when calling event handler Speedtest_device
2021-03-31 22:28:41.852 Error: dzVents: Error: (3.0.2) ...z/scripts/dzVents/generated_scripts/Speedtest_device.lua:11: attempt to call a nil value (field 'executeShellCommand')
Update domticz.. dzVents have executeShellCommand from 12771 build
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Maximum of lua scripts?

Post by waaren »

JohnnySK wrote: Wednesday 31 March 2021 22:23 scripts have --silent parameter in each call.. so doesn't have output.. but files appear and disappear in data folder and errors still comming
You should not use the background operator (&) with domoticz.executeShellCommand()
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Maximum of lua scripts?

Post by waaren »

manjh wrote: Wednesday 31 March 2021 22:05 As you can see, there is no result flowing back from this script. The speedtest2.sh bash file stores results straight into virtual devices.
when using os.execute you should use the background operator

Code: Select all

os.execute('/home/pi/domoticz/scripts/speedtest2.sh &')
I tried to use this:

Code: Select all

domoticz.executeShellCommand('/home/pi/domoticz/scripts/speedtest2.sh')
but am getting an error:
domoticz.executeShellCommand is available in dzVents >= 3.1
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest