Solved

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

Posted on 2010-08-20
6
510 Views
Last Modified: 2013-12-17

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
Comment
Question by:windymillermc
  • 3
  • 3
6 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 33487390
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
 

Author Comment

by:windymillermc
ID: 33487457
But if that was the case I would see similar behaviour with wireshark which runs and timestamps packets on the same machine
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 33487514
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Closing Comment

by:windymillermc
ID: 33541016
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 33541433
0
 

Author Comment

by:windymillermc
ID: 33545659
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now