ekg/System/Remote/Counter.hs
Johan Tibell 64e6ba1259 Improve scalability of counters a lot
Counters now scale orders of magnitudes better as the number of
writers to the same counter increases. Here's the results on our
current benchmark on a 6 core machine:

        cores
            1       6
before  1.87s  81.09s
after   0.11s   0.32s

Note how the very heavy contention gives a slowdown rather than a
speedup as the number of cores increases, but the new implementation
slows down much less than the old one and is also generally faster.
2014-04-08 17:25:58 +02:00

20 lines
651 B
Haskell

{-# LANGUAGE BangPatterns, ForeignFunctionInterface #-}
-- | This module defines a type for mutable, integer-valued counters.
-- Counters are non-negative, monotonically increasing values and can
-- be used to track e.g. the number of requests served since program
-- start. All operations on counters are thread-safe.
module System.Remote.Counter
(
Counter
, inc
, add
) where
import System.Remote.Counter.Internal
-- | Increase the counter by one.
inc :: Counter -> IO ()
inc counter = add counter 1
-- | Increase the counter by the given amount.
foreign import ccall unsafe "hs_counter_add" add :: Counter -> Int -> IO ()