Lua/Luup performance

Code (entered in “Test Luup Code (Lua)” window)

luup.log(‘BB0’)
tmp_filename = os.tmpname()
luup.log(‘BB1’)
os.execute('curl “http://127.0.0.1:49451/data_request?id=lu_variableget&DeviceNum=9&serviceId=urn:micasaverde-com:serviceId:ZWaveDevice1&Variable=VariablesSet” > '…tmp_filename)
luup.log(‘BB2’)
infile = io.open( tmp_filename, ‘r’ )
luup.log(‘BB3’)
luup.log(‘AAA1 ‘…infile:read(’*all’))
luup.log(‘BB4’)
infile:close()
luup.log(‘BB5’)
os.remove( tmp_filename )
luup.log(‘BB6’)

Log:

50 09/15/09 21:50:39.617 luup_log:0: BB0 <0xb409>
50 09/15/09 21:50:39.618 luup_log:0: BB1 <0xb409>
50 09/15/09 21:52:17.933 luup_log:0: BB2 <0xb409>
50 09/15/09 21:52:17.970 luup_log:0: BB3 <0xb409>
50 09/15/09 21:52:17.972 luup_log:0: AAA1 176,m,177,m,178,m,179,m,180,m,181,m,182,m,183,m,184,m,185,m,186,m, <0xb409>
50 09/15/09 21:52:17.973 luup_log:0: BB4 <0xb409>
50 09/15/09 21:52:17.974 luup_log:0: BB5 <0xb409>
50 09/15/09 21:52:17.975 luup_log:0: BB6 <0xb409>

Why does os.execute take more than one minute to finish?

PS:
The code above is equivalent to:

luup.log(‘BB0’)
luup.log('BB1 '…luup.variable_get(“urn:micasaverde-com:serviceId:ZWaveDevice1”,“VariablesSet”,9))
luup.log(‘BB2’)

Log:

50 09/15/09 23:04:59.065 luup_log:0: BB0 <0x13415>
50 09/15/09 23:04:59.066 luup_log:0: BB1 176,m,177,m,178,m,179,m,180,m,181,m,182,m,183,m,184,m,185,m,186,m, <0x13415>
50 09/15/09 23:04:59.067 luup_log:0: BB2 <0x13415>

The problem is os.tmpname() creates a filename in / (root directory), which is part of the firmware, so every time curl has to write to it, it’s re-flashing the whole 6MB firmware image. Instead, put temporary files in /tmp. That’s a ram drive and doesn’t persist after a reboot. For small files that you want to persist through a reboot, there’s about 1MB of space in /etc/cmh you can write to.

@MCV, is there a way to make [tt]os.tmpname()[/tt] “default” to using the [tt]/tmp[/tt] directory when it creates these temporary filenames?

ie. does it, or can it, be made to respect the env [tt]TMPDIR[/tt]

Folks are likely going to fall over this problem by accident, and not really know. To them, it’ll just look like their code is slow (or worry when they burn out their flash with too many re-writes)