Solved

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

Posted on 2010-08-20
6
517 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 86

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 86

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 86

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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

728 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