[web-devel] Caching the System time

Greg Weber greg at gregweber.info
Sun Aug 7 00:20:41 CEST 2011


couldn't tryTakeMVar and tryPutMVar handle this case of multiple writers
well? I am asking because I really don't know :)

On Sat, Aug 6, 2011 at 2:05 PM, Gregory Collins <greg at gregorycollins.net>wrote:

> On Sat, Aug 6, 2011 at 8:11 PM, Michael Snoyman <michael at snoyman.com>wrote:
>
>> Without having delved into the issue in any great depth, I had a
>> possible idea on this point. How about storing an IORef containing a
>> time and the text representations you need. Whenever you need to get
>> the time, compare the time in the IORef with the current time, and if
>> they're different, update appropriately. Bonus points: store in an
>> unpacked datatype and use a Builder instead of String. Would this (in
>> theory) work?
>>
>
> We do something similar to this, except we get the thread to recompute the
> date -- otherwise every second you have a race condition possibility where
> multiple threads compete to write the new thread into the IORef. If there's
> no activity, the date thread goes to sleep, the code to get the current date
> notices that the date is stale, and then it wakes the thread and recomputes
> the new date itself. Again, I'm not sure if it's worth it in the general
> case, but during periods of high load I think it helps to get as much stuff
> out of the processing threads as possible.
>
> G
> --
> Gregory Collins <greg at gregorycollins.net>
>
> _______________________________________________
> web-devel mailing list
> web-devel at haskell.org
> http://www.haskell.org/mailman/listinfo/web-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/web-devel/attachments/20110806/d78ba05a/attachment-0001.htm>


More information about the web-devel mailing list