kazu-yamamoto/logger

Higher time resolution for newTimeCache?

Opened this issue · 3 comments

As far as I can see, the whole TimedFastLogger thing is primarily intended for the case when one wants to print time to log with precision of one second only. But, I have some experience with applications where a thousand events in a millisecond is not an exceptional situation. In such applications, it becomes essential to log time with precision of at least a millisecond.

Questions are

  1. Am I right that newTimeCache creates a "cache" that refreshes not more often than one time in a second?

  2. Do you have any practical insights, if a similar time caching mechanism with update interval of 1 millisecond will give any advantage comparing to directly formatting time each time?

The suggestion is to add new function newTimeCache', which would take one additional argument - update interval.

@portnov

  1. Yes you are right, IIRC newTimeCache use auto-update package to achieve this.

  2. The time cost are:

  • syscall to fetch time, average 1~10 microsecond.
  • the formatting processing which convert time to string, average 10~100 microsecond.

It's quite costly if you update the cache every millisecond. auto-update package use a complicated locking system to avoid unnecessary update(when you don't fetch the cache), but that also add some overhead, especially on multi-ghc-threaded programs.

Thanks for the information.