@@ -235,42 +235,17 @@ data WorkerInfo = WorkerInfo
235235 , workerLatencyStart :: IORef (Count, TimeSpec)
236236 }
237237
238−-- | Specify the stream yield rate.
238+-- | Specify the stream yield rate in yields per second (@Hertz@). We try to
239+-- keep the average rate at 'rateGoal', if the actual average rate goes above
240+-- or below the goal we try to recover it by increasing or decreasing the
241+-- instantaneous rate but keeping it within 'rateLow' and 'rateHigh' limits.
239242--
240243-- @since 0.5.0
241−data Rate =
242− AvgRate Double
243− -- ^ Specifies the average production rate of a stream in number of yields
244− -- per second (i.e. @Hertz@). Concurrent production is ramped up or down
245− -- automatically to achieve the specified average yield rate. The rate can
246− -- go down to half of the specified rate on the lower side and double of
247− -- the specified rate on the higher side.
248− | MinRate Double
249− -- ^ Specifies the minimum rate at which the stream should yield values. As
250− -- far as possible the yield rate would never be allowed to go below the
251− -- specified rate, even though it may possibly go above it at times, the
252− -- upper limit is double of the specified rate.
253− | MaxRate Double
254− -- ^ Specifies the maximum rate at which the stream should yield values. As
255− -- far as possible the yield rate would never be allowed to go above the
256− -- specified rate, even though it may possibly go below it at times, the
257− -- lower limit is half of the specified rate. This can be useful in
258− -- applications where certain resource usage must not be allowed to go
259− -- beyond certain limits.
260− | ConstRate Double
261− -- ^ Specifies a constant yield rate. If for some reason the actual rate
262− -- goes above or below the specified rate we do not try to recover it by
263− -- increasing or decreasing the rate in future. This can be useful in
264− -- applications like graphics frame refresh where we need to maintain a
265− -- constant refresh rate.
266− | Rate Double Double Double
267− -- ^ This is the most general specification of the stream yield rate and
268− -- all the other specifications can be expressed in terms of this. The
269− -- first argument is the target rate, the second argument is the lower
270− -- limit and the third argument is the upper limit. We try to keep the
271− -- average rate at the target rate specified, if the actual rate goes above
272− -- or below we try to recover the rate by increasing or decreasing it in
273− -- future while keeping the maximum or minimum within the specified range.
244+data Rate = Rate
245+ { rateLow :: Double -- ^ The lower rate limit
246+ , rateGoal :: Double -- ^ The target rate we want to achieve
247+ , rateHigh :: Double -- ^ The upper rate limit
248+ }
274249
275250data LatencyRange = LatencyRange
276251 { minLatency :: NanoSecs
@@ -1828,29 +1803,13 @@ postProcessPaced sv = do
18281803
18291804getYieldRateInfo :: State t m a -> IO (Maybe YieldRateInfo)
18301805getYieldRateInfo st = do
1831− let -- convert rate in Hertz to latency in Nanoseconds
1832− rateToLatency r = if r <= 0 then maxBound else round $ 1.0e9 / r
1833− -- handle overflowed latency value
1834− toMaxLatency l = if l <= 0 then maxBound else l
1806+ -- convert rate in Hertz to latency in Nanoseconds
1807+ let rateToLatency r = if r <= 0 then maxBound else round $ 1.0e9 / r
18351808 case getStreamRate st of
1836− Just (AvgRate rate) ->
1837− let l = rateToLatency rate
1838− mx = toMaxLatency (l * 2)
1839− in mkYieldRateInfo l (LatencyRange (l `div` 2) mx)
1840− Just (MinRate rate) ->
1841− let l = rateToLatency rate
1842− in mkYieldRateInfo l (LatencyRange (l `div` 2) l)
1843− Just (MaxRate rate) ->
1844− let l = rateToLatency rate
1845− mx = toMaxLatency (l * 2)
1846− in mkYieldRateInfo l (LatencyRange l mx)
1847− Just (ConstRate rate) ->
1848− let l = rateToLatency rate
1849− in mkYieldRateInfo l (LatencyRange l l)
1850− Just (Rate rate minr maxr) ->
1851− let l = rateToLatency rate
1852− minl = rateToLatency maxr
1853− maxl = rateToLatency minr
1809+ Just (Rate low goal high) ->
1810+ let l = rateToLatency goal
1811+ minl = rateToLatency high
1812+ maxl = rateToLatency low
18541813 in mkYieldRateInfo l (LatencyRange minl maxl)
18551814 Nothing -> return Nothing
18561815