[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 522
  • Last Modified:

Time stamping events in c# using TimeOfDay results in intervalised results


I wrote a simple console app in c# that outputs record updates of streaming data that can be handled through different real-time APIs . I wanted to timestamp to atleast milisec granularity as per below

 static void OnRecord.Update(Record rec, bool stale, int index, ref System.Array indexArr, ref System.Array valueArr)
        {
           


           for (int i = 0; i < valueArr.Length; i++)
            {
                try
                {
                    Console.WriteLine(rec[index].Name + ":"+ valueArr.GetValue(i) + ":" + DateTime.Now.TimeOfDay);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception: {0}", ex.Message);
                }
            }

the output looked at first glance fine giving name:new value:timestamp as per below

GBL:+20592322:11:41:42.2629255
GBL:+20593312:11:41:42.2629255
GBL:+20594302:11:41:42.4816839
GBL:+20595292:11:41:42.5910631
GBL:+20595677:11:41:43.2629639
GBL:+20596685:11:41:43.2785895
GBL:+20597675:11:41:43.8567367
GBL:+20598402:11:41:46.5599655
GBL:+20599061:11:41:46.5912167
GBL:+20600305:11:41:51.4976551
GBL:+20601096:11:41:51.5132807
GBL:+20601992:11:42:07.8576583
GBL:+20603992:11:42:13.6391303
GBL:+20605992:11:42:13.6391303
GBL:+20608992:11:42:13.6391303
GBL:+20609420:11:42:13.7485095
GBL:+20609520:11:42:13.7485095
GBL:+20609609:11:42:45.8434919
GBL:+20610009:11:42:45.8591175

however on inspection the timestamp are always intervalise by a factor of 0.0156256
Even if I run seperate instances of the app with diffrent record feeds,using diffrent apis for the record event handling then compare the results, the difference in timestamps is stll a factor of this value.
 It's as though running  TimeOfday irrespective if which instance of the app and event  it's calling  only returns results after so many clock cycles.  As the data is coming over the network I also can verify the events through wireshark so know its not the data itself causing this intervalising behaviour.I could understand it if the value was much lower but wouldn't expect it to be 15.6 msec on a modern processor. Perhaps my understanding of the windows Timeofday call  is completely wrong ?
0
windymillermc
Asked:
windymillermc
  • 3
  • 3
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
That's standard behavior...

Don't forget that WINDOWS itself gives the illusion of "multi-tasking" by allocating only a small time-slice to each process and its threads.  The "intervalised" gap in-between is probably due to the operation system allowing other processes to do their thing.

If your app was running on specialized hardware where one app was able to monopolize the operating system then perhaps you might see what you expect where the values change smoothly.  (this is theoretical!)

FYI, Windows hasn't been non-preemptive  since version 3.1 back in 1992!
http://en.wikipedia.org/wiki/Preemption_(computing)
http://technet.microsoft.com/en-us/library/cc767883.aspx
0
 
windymillermcAuthor Commented:
But if that was the case I would see similar behaviour with wireshark which runs and timestamps packets on the same machine
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
What language was WireShark written in?  It might lower level optimized code...

.Net is one of the most bloated pieces of framework on the planet!
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
windymillermcAuthor Commented:
The answer was correct in why the behaviour was happeing abut it was't a solution as to how to fix the code.
Found the real solution by using DateTimePrecise class written by James Brock
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
0
 
windymillermcAuthor Commented:
ummm well I have now build the project class and used it but it may slightly more granularity but the 15millisec interval is still there. Have you tried it ?
Actually, re-reading the dialogue carefully it does say it has an accuracy of 15 miilisecond but I thought that was a typo as otherwise what's the point of it. So it doesn't do what I expected.
So I'm still searching for a solution
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now