more G-Labs products

Author Topic: Speed benchmark for HG  (Read 2065 times)

January 15, 2015, 06:00:38 PM
Read 2065 times

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I had a discussion with a HG user on PM the other day about my Advanced Smart Lights code to help him get things set up.  When everything was working correctly, he noticed that there was a large delay (or at least perceived delay) from the time a motion detector sensed motion and when the light turned on.  Part of this is due to X10 protocol being utilized.  The other part is HG overhead.  This got me thinking that maybe some systems run faster than others and that it might be nice to know what kind of a performance hit might be experienced by using a Raspberry Pi versus a 12 core PC.

To understand this, I thought a simple test that could be easily run on multiple systems would be useful.  I was hoping that a few people with different systems could run the attached code and post the mono output.  I have attached an example of my output for reference.

To use the hgx script:
  • download script (hgx)
  • go to configure->automation->[any group]
  • actions->import
  • select new script and edit
  • select program tab and compile (upper left)
  • select back to exit the script
  • select the script again
  • enter the name of a module that you want to test with (ideally a switch, light, dimmer)
  • control the module with either RF, PLC, or HG itself

For reference:
The script will watch for a module with the given name to turn on.  When it sees that command, it will immediately turn it off.  I don't even have a module hooked up to actuate, I just used address A1.  With the official release of HG (not using the updated XTenLib posted yesterday), the command sequence will be (assuming A1):
Code: [Select]
A1
AON
HG runs code
A1
AOFF
If you run some calculations, a sequence of 4 commands will take a minimum of 1.67 seconds.

If you are using the updated XTenLib file:
Code: [Select]
A1
AON
HG runs code
AOFF
This version uses 1 less command, so it would take a minimum of 1.25 seconds.

This test is VERY basic as far as HG goes, so I would anticipate each system taking very close to this minimum time.  If so, I'll construct a more rigorous test to see if more complex code takes more/less time on different systems.  Thanks for considering running this test!

January 15, 2015, 08:21:48 PM
Reply #1

RoChess

  • ***
  • Information
  • Full Member
  • Posts: 61
Could actually automate this.

Certain motion sensors, such as the Aeon-Labs or Fibaro 4-in-1 models can also report Luminance values.

By placing sensor close to light source, you can automate the timing. Have the motion sensor trigger the scene (and start clock), then after complex scene finishes, turn the light on. Then on Luminance value you turn the light back off and stop the clock.

Result will be an interesting "benchmark" value, that can be compared between different systems. Perhaps use a powerful 12-core system to get a theoretical base value of say 10 seconds. That way it is easy to compare against.

Could even do a stress test, by having the scene activate based on luminance value as well, so it goes into a constant loop of on/off. The motion sensor could be used to abort the stress test or configure like X amount of test runs.
« Last Edit: January 15, 2015, 08:24:05 PM by RoChess »

January 15, 2015, 10:12:45 PM
Reply #2

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
That would certainly be a next step that could be considered!

I reviewed my results that I posted this morning and found that there is a large lag between the commands that seems to last for between 0.5-1.2 seconds.  I'm not clear what's happening in this period, but that extra second would explain why the sequence which should take ~1.67 seconds takes closer to 2.5-3 seconds.

The first tab of the spreadsheet contains primarily the raw mono output for each test.  The second tab tabulates delta times between different events.  As seen in the 3rd table, there is a large time gap between when HG sets A1 to ON and when the script sends the OFF command.  I do have quite a few widgets enabled in HG (though significantly less than are available).  I'll try rerunning with only the script enabled to see if that makes any difference.
« Last Edit: January 15, 2015, 10:15:53 PM by bkenobi »

January 16, 2015, 08:16:41 AM
Reply #3

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I updated HG to the current committed code on github (compile required), turned off all programs except the test module, and tried the test procedure again.  The attached data shows that the transmission time might be slower.  The RF code was hard to say what was happening since HG now sees both the RF and PLC communication from the CM15A.  The AON only command seemed to be slightly slower (~0.4  seconds slower).  The full command set (A1, AON) seemed much slower (4 versus 2.3 seconds) and certainly slower than the minimum theoretical needed time (1.67 seconds).  I didn't run the HG test this time.
« Last Edit: January 16, 2015, 08:18:12 AM by bkenobi »

January 24, 2015, 03:00:43 AM
Reply #4

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I've been thinking about this for a few weeks now (well, months really).  I originally posted that HG seemed to take significantly longer than necessary to turn on a module than necessary when triggered from an outside command (X10 to X10).  I just realized that there is still an issue to some degree even if the first command isn't X10.  I switched my front motion sensor from using an X10 transmitter (PowerFlash) to using a GPIO input.  Since HG should see the GPIO change nearly instantly and the X10 transmitter should take around a second there should be a noticeable difference in speed.  However, it still seems to take around the same time to have a light turn on whether it's via GPIO or via X10 (indirect) command.

I'm going to post data comparing the following:

TriggerControlledTime
X10 PLCX10 PLC?
X10 RFX10 PLC?
GPIOX10 PLC?
HG webX10 PLC?
HG AndroidX10 PLC?

If there's a significant difference that's repeatable, I'd really hope that we could look at tracking down the source.  I was willing to let the slow response go as an artifact of X10 being used.  But, now that other users see it as an issue and the fact that GPIO seems to have the same issue, I think it's worth investigating.
« Last Edit: January 24, 2015, 03:10:15 AM by bkenobi »

January 24, 2015, 06:50:43 AM
Reply #5

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
TestTriggerControlledMin TimeAverage TimeMax Time
1HG web (direct)X10 PLC0.8661.21411.863
2X10 PLCX10 PLC1.7712.10822.672
3X10 RFX10 PLC2.6242.98123.068
4GPIOX10 PLC0.8681.18211.888
5HG webX10 PLC1.7332.04612.606
6HG AndroidX10 PLC0.8731.82032.309
7ASL X10 PLCX10 PLC3.3443.3443.344
8ASL GPIOX10 PLC2.2822.2822.282

Notes:
  • Case 1 is a baseline controlling the light from HG by sending the command directly.
  • All non-needed modules were disabled.  X10 HC/UC A1 was used for all tests.  GPIO 25 used.
  • Tests 1-6 had 10 instances run.  Reduced instances was run for cases 7 and 8.
  • All test performed on Raspberry Pi model B
  • ASL = Advanced Smart Lights
  • HG web page was loaded for all tests which could add some overhead
  • Logging was turned on within ASL for all but tests 11 and 12
  • Mono logging was enabled for all testing to make it possible to generate times
  • All log files were written to a network file share which could add some overhead

Based on these results, I'd say that GPIO is definitely faster than X10 in any form (which it should be).  GPIO is basically the same speed as sending a direct command via the web or android.  Sending a command via X10 should take approximately 0.835 seconds.  So it appears that in the best case runs for GPIO, HG web, and HG Android the response was excellent.  In the case of trigger via X10, the minimum time should be approximately 1.67 seconds.  So it appears that X10 PLC can react in that amount of time.

That being said, I see a lot of variation in the results and each of the tests showed that HG could take over twice as long as theoretically minimum for no apparent reason.

Finally, when using my real world code (Advance Smart Lights), I find that there is a massive performance hit when using loops at least on the Raspi.  I'd appreciate a recommendation at this point.  Would I be better served upgrading the Raspi to something more powerful?  Or, would I find some benefit to optimizing the code somehow?  If optimizing would be best, any recommendations on how?
« Last Edit: January 24, 2015, 04:36:29 PM by bkenobi »

January 25, 2015, 06:33:32 AM
Reply #6

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I've rerun some testing and updated the table.  This includes all the same data as before with a few new tests.

TestTriggerControlledMin TimeAverage TimeMax Time
1HG web (direct)X10 PLC0.8661.2141.863
2X10 PLCX10 PLC1.7712.1082.672
3X10 RFX10 PLC2.6242.9813.068
4GPIOX10 PLC0.8681.1821.888
5HG webX10 PLC1.7332.0462.606
6HG AndroidX10 PLC0.8731.8202.309
7ASL X10 PLCX10 PLC2.0852.6273.344
8ASL GPIOX10 PLC2.2822.2822.282
9ASL X10 PLCX10 PLC1.8142.0312.453
10ASL HG X10 PLCX10 PLC2.2302.5383.335
11ASL X10 PLC NoLogX10 PLC1.8072.2262.914
12ASL GPIO NoLogX10 PLC1.3491.7072.270

It appears that the logging of data (writing to a network drive) makes a difference, so I'll disable it in the default config and upload a new copy of Advanced Smart Lights to the Contributions thread.  But, I'm still a bit confused how sometimes it can take an extra second to execute for no apparent reason.  I'm curious if there's a reason for this.  And, if so, is there a way to eliminate it.