Piston Resource Limits


#1

Not a specific design or coding issue, just a question for the designers. Are there limits to piston resource usage, for example the amount of processing, total ms execution time, or memory usage, that would cause a piston to be interrupted / canceled?


#2

All SmartApps have 20 second timeout from ST.

Each piston has 100,000 bytes of storage available to it. This includes any logging but will overwrite logs as space fills up. So no need to keep logging full unless you are debugging.

I have seen errors with character limits. I believe it’s 10,000 but could be wrong.

All those listed above could result in problems. If you see any problems in the logs then check the ST IDE live logging to isolate a line number with the error.


#3

Part of the problem is the code isn’t allowing trace, so no line numbers. Full logging turned on and I usually don’t get anything there, and nothing on the IDE console. I am assuming the timeout now, maybe that’s resulting in no log data and missing Trace Toggle. I am doing a small sort on 2 lists of 24 items (plus a bunch of other stuff, but the sort takes up most of the processing). Probably not what this platform is for. I wouldn’t even have tried it if I could figure out another way to store the data to be formatted outside of webcore. Well a straightforward way, maybe i can jury rig something with IFTTT. I don’t know if this is remotely possible, but is writing to a local file system planned for webcore?


#4

Do you have a screenshot of the piston?


#5

Sure thing… and thanks for looking at this!

The sort stops somewhere around the 3rd to 4th pass (outer loop) and the piston ends with no further processing. Theres a lot of subsequent code thats disabled bur it doesn’t execute when the sort is interrupted. If you prefer I enable it so you se the whole thing let me know.


#6

@bangali is my go to for lists and arrays

But from what I see I would guess that this might be execeeding the 20 second limit.

When you run this does it produce any logs in the ST IDE live logging page?


#7

if you dont mind my asking, why are you bubble sorting the lists on battery level?


#8

Nope, nothing in Live Logging either.


#9

Bangali, when this piston is executed its from a dashboard button. It will report back tot the dashboard any devices that are low, but also produce an email with a device list sorted low to high of battery level. Its purely ascetics, if I can’t figure it out then it will just email the devices with low battery levels. I thought this looked better. Note the target audience for the dashboard and email is a completely non-technical person.


#10

Just so I’m covering all bases you are executing the piston while the live logging page is open?


#11

if you are looking for email formatting these devices from low to high battery heres a quick version to do this:

define
   device allDevices = device 1, device 2, device 3
   int maxBattery
   int minBattery
   int x
   string email = ''
end define

set variable maxBattery = max([allDevices : battery])
set variable minBattery = min([allDevices : battery])

for x = minBattery to maxBattery step 1
   for $device in allDevices
      if ([$device : battery] == x)
         set variable email = email + $device + ': ' + [$device : battery] + '% '
      end if
   end for
end for

#12

Yes, live logging page is open when I run the piston for testing.


#13

Wow, I didn’t expect this.It’s not a way I would have thought of to get the sorted list but I will give it a go and report back. Thanks! I am still interested in why I can’t seem to debug my current problem. Is it possible that once I pass 20 seconds all functions, including tracing and logging, are cancelled?


#14

sure! mind you not guaranteeing this wont run in to the 20 second boundary! probably depend on the number of devices.

very.


#15

heres a slightly optimized version of the snippet above. from trace its taking ~17 seconds to run and thats with 7 devices. once i include 10 devices it times out.


#16

Nice :slight_smile:

But yeah, the original is timing out without logs because I have 24 devices. When I reduce the devices to 10 it works and I get the Trace Toggle and the logging. Ugh.

But this has been a great lesson, I now know about the 20s limit and that confirms my assumption that this isnt the platform for generating reports. LOL. I will look into writing the data through web calls or some such method.

I also learned from your sorting technique, my mind works in old fashioned brute-force programming style. I haven’t really coded much since my mainframe programming days, and that’s a long time ago. But I’m re-learning.

Thanks for your help (and anyone else who responded), its greatly appreciated!


#17

ehh, not that great … takes too long.

right probably better not used for report generation. :slight_smile:

i can tell you that the bubble sort would run faster with punch cards :wink:


#18

And I didn’t even use an optimized bubble sort, just wanted to get it to work lol.


#19

fixed mine for you. with 26 battery devices takes under 10 seconds:

even wtih 50 or so battery devices shouldnt take more than 15 seconds so a 5 second margin.


#20

Clever!! Thanks my friend!