I found a snippet of code in the iFW Wiki that allows one to generate time stamps with millisecond resolution. Aside from an issue with its ability to format the resulting number with the appropriate number of trailing zeros (a fix for which I’ll be passing along shortly), I’ve found that it doesn’t seem to really have true millisecond resolution, even of the ’emulated’ variety.
I was hoping to use the resulting timestamp as a unique identifier for database inserts coming from a CSV file; this would allow me to retrieve the records in chronological order (something I’ve since rethought, but I digress). I noticed that even across a very small number of inserts (and even after introducing artificial delays between inserts with util.sleep()!), I was seeing duplicate keys.
I’m not entirely convinced that the issue is with Iguana or Lua; my test environment for this code is a Ubuntu 11 virtual machine running on my laptop. While performance is pretty great overall, I wouldn’t be surprised if the OS isn’t getting accurate clock information.
Has anyone else run into a similar problem on something other than a VM?
Here’s the modified code:
function GetSequence() local a,b = math.modf(os.clock()) b = tostring(b) b = string.sub(b, 3, 5) local blen = string.len(b) if blen == 0 then b = '000' elseif blen == 1 then b = b..'00' elseif blen == 2 then b = b..'0' end local tnf=os.date('%Y%m%d%H%M%S',os.time()) -- iguana.logInfo('timestamp is '..tnf..' and b is '..b) tnf=tnf..b trace(tnf) return tnf end
Jeff Drumm ◊ VP and COO ◊ HICG, LLC. ◊ http://www.hicgrp.com
You must be logged in to reply to this topic.