
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

On Sun, Sep 2, 2012 at 7:56 PM, Kazu Yamamoto
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.
Just a nit: your history here is not correct. gettimeofday has been implemented as a vsyscall for a long time, maybe 5 years. And while it's faster than int 0x80, it's not that much faster: 2x or so on modern hardware.

Bryan,
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.
Just a nit: your history here is not correct. gettimeofday has been implemented as a vsyscall for a long time, maybe 5 years. And while it's faster than int 0x80, it's not that much faster: 2x or so on modern hardware.
Thank you for your correction. To whose who are interested in, additional information can be found from: http://en.chys.info/2009/01/linux%E2%80%99s-vsyscall/ Anyway, I believe we should avoid gettimeofday as much as possible to implement fast servers. --Kazu

On recent (>2009) Linux, you can call clock_gettime() with
CLOCK_REALTIME_COARSE which is about 6x faster:
https://gist.github.com/3634708
On my workstation calling clock_gettime(CLOCK_REALTIME, ...) and poking the
value into a Haskell struct takes about 70ns, with CLOCK_REALTIME_COARSE
it's about 19ns (with a much lower stddev). Worth using for this
application if it's available. Of course, in Snap we do the "update the
clock every second in a thread" trick also.
G
On Wed, Sep 5, 2012 at 4:10 AM, Kazu Yamamoto
Bryan,
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.
Just a nit: your history here is not correct. gettimeofday has been implemented as a vsyscall for a long time, maybe 5 years. And while it's faster than int 0x80, it's not that much faster: 2x or so on modern hardware.
Thank you for your correction.
To whose who are interested in, additional information can be found from:
http://en.chys.info/2009/01/linux%E2%80%99s-vsyscall/
Anyway, I believe we should avoid gettimeofday as much as possible to implement fast servers.
--Kazu
_______________________________________________ web-devel mailing list web-devel@haskell.org http://www.haskell.org/mailman/listinfo/web-devel
--
Gregory Collins

On Wed, Sep 5, 2012 at 12:32 PM, Gregory Collins
On recent (>2009) Linux, you can call clock_gettime() with CLOCK_REALTIME_COARSE which is about 6x faster:
https://gist.github.com/3634708
On my workstation calling clock_gettime(CLOCK_REALTIME, ...) and poking the value into a Haskell struct takes about 70ns, with CLOCK_REALTIME_COARSE it's about 19ns (with a much lower stddev). Worth using for this application if it's available. Of course, in Snap we do the "update the clock every second in a thread" trick also.
Of course, I made a rookie mistake here, and can't reproduce the results
because a single call is too short to benchmark accurately. Adding a
replicateM_ 1000 gives:
CLOCK_PROCESS_CPUTIME_ID: 195.0717 ns
CLOCK_REALTIME: 24.92609 ns
CLOCK_REALTIME_COARSE: 14.47882 ns
CLOCK_MONOTONIC: 25.00275 ns
CLOCK_MONOTONIC_COARSE: 15.60754 ns
Updated the gist accordingly.
G
--
Gregory Collins

On Tue, Sep 4, 2012 at 7:10 PM, Kazu Yamamoto
Anyway, I believe we should avoid gettimeofday as much as possible to implement fast servers.
Sort of agree. It only costs about 17-44ns, depending on the system, so it's actually very cheap. For comparison, reading an uncontended IORef seems to cost about 0.6ns (!).
participants (3)
-
Bryan O'Sullivan
-
Gregory Collins
-
Kazu Yamamoto