[web-devel] new fast-logger and date-cache

Kazu Yamamoto ( 山本和彦 ) kazu at iij.ad.jp
Mon Sep 3 04:56:27 CEST 2012


Hello,

I have changed the API of fast-logger and changed its version to v0.3.
fast-logger v0.3 and related packages are alreay on Hackage.  Since
wai-extra requires v0.2, I believe this change does not effect to
Yesod. I have already sent a pull request of wai-extra to catch up
this change.

The old fast-logger implements the caching algorithm of formatted date
which was discussed this ML. The assumption at that time is: 1)
formatting time to date string is a heavy job, and 2) issuing
gettimeofday() is a light job.

So, old algorithm is as follows:

- When a formatted date is required, first issues getttimeofday().
  Then compare it with a cached time.
- If they are equal, return its cached formatted date.
- Otherwise, format the new time to a new formatted date,
  cache them, and return the new formatted date.

To my experience, the assumption 2) is not right. getttimeofday()
is implemented in user land in Linux 3 but it is a system call
in Linux 2.

So, I fixed fast-logger so that it can choose caching strategy.  The
pull request above does not change behavior. That is, its strategy is
the algorithm above.

I also implemented a new strategy. Designated Haskell thread issues
gettimeofday() every second, formats the resut time to a date, and
cache it.

I know that people here pointed out that a Haskell thread is not waken
up correctly in heavy load situation. But I think that generating a
incorrect date in a log file is not a big problem.

The package to implement these two algorithm is "date-cache".  This
package can be used not only for logging but also generating the Date:
header in HTTP Response.  Mighty now uses the new algorithm of
date-chace both for logging and generating Date:.

--Kazu



More information about the web-devel mailing list