Page 1 of 1

Debugging 100% CPU

Posted: 11 Feb 2016 09:10
by bogr
I've probably written some logical rules that trigger constantly and therefore send the CPU usage to the roof. Can I configure some logging or is the only alternative to add console loggings explicitly in the module?

Re: Debugging 100% CPU

Posted: 11 Feb 2016 15:25
by bogr
A "nice to have"-feature would be to be able to configure the "core" module with throttling/damping so that X number of events from the same module in Y number of seconds, should throw an error (+info in GUI) and make a delay. In this way the server would still be responsive and possible to shut it down, instead of having to kill the process? Or is it not that usual to mess up a logical rule? I'd guess that the more rules the bigger risk. The "ultimate" solution is a generated graph that shows the dependencies between devices and modules in logical rules, if-statements...wishing ;)

Re: Debugging 100% CPU

Posted: 11 Feb 2016 16:04
by pz1
bogr wrote:I've probably written some logical rules that trigger constantly and therefore send the CPU usage to the roof. Can I configure some logging or is the only alternative to add console loggings explicitly in the module?
Disable/re-enable your rules one by one to find the offender.
Do not make complex rules, try to split in multiple simple rules if possible. ("Industrial grade" rule engines like Drools do split-up complex rules at compile time. ZWay doesn't)

Re: Debugging 100% CPU

Posted: 11 Feb 2016 16:35
by bogr
Yes, they are quite simple actually, but I'm a bit lazy to go over them one by one ;). I think I'll add a console.log to the logical rule module and then I can easily see which rule(s) is/are triggered over and over. I have some virtual switches to be able to handle different cases in my alarm, and I've probably messed up some rule that triggers one switch and another that triggers it back - I think at least.
Thanx for your input.

Re: Debugging 100% CPU

Posted: 11 Feb 2016 20:05
by bogr
Hmm, it doesn't seem like my assumption was correct. I have a code switch and I've configured ON like:

Code: Select all

system('aplay /home/pi/sounds/larmOn.wav; curl http://ip:8083/ZAutomation/api/v1/devices/LightScene_51/command/on')
The LightScene_51 works if I trigger it from the GUI, but it does not seem to be triggered from the code switch. It actually makes the server go berserk :x . I've put it in a room with anonymous access, so it can't have anything to do with access right, and I can actually trigger it from another raspi. I've also put curl in .syscommands so I can't understand why it does not work. Trying:

Code: Select all

http://ip:8083/ZWaveAPI/Run/system('curl http://ip:8083/ZAutomation/api/v1/devices/LightScene_51/command/on')
does not give any errors - in the browser the output is [1536,""], but the scene is not triggered.

Re: Debugging 100% CPU

Posted: 11 Feb 2016 22:25
by bogr
Don't know why it didn't work, I tried to replace the url with just google.com, and the server did not hang in that case. I gave up the curl-nuisance and replaced it with:

Code: Select all

controller.devices.get('LightScene_51').performCommand('on')
so now it finally works. Even "feels" like a better solution.

Re: Debugging 100% CPU

Posted: 22 Feb 2016 21:30
by PoltoS
Why do you call HTTP from the server itself, while you can do it via JS command (in your last message).

Note that HTTP server is synchronous, so JS hangs on serving messages. If you do it from system, you also block the process until system is returned, but system can not return until HTTP answers, while HTTP can not answer until system() is over. Classical deadlock ;)

Re: Debugging 100% CPU

Posted: 22 Feb 2016 23:47
by bogr
ahaaaa, didn't think of that :o . Thanx for the great clarification ;)