on master help sign in
Use explicit arguments in the concurrency config options
commit41fb0734bc0e59dbb952742bce2ca58f574a29f2 authorAdithya Kumar <adithya@composewell.com> dateTue 25 Oct 2022, 16:29 (4 years ago) parent1fb51c4
7 files changed+44−38
benchmark/Streamly/Benchmark/Data/Stream/ConcurrentEager.hs+4−1 benchmark/Streamly/Benchmark/Data/Stream/ConcurrentInterleaved.hs+2−1 benchmark/Streamly/Benchmark/Data/Stream/ConcurrentOrdered.hs+3−1 src/Streamly/Internal/Data/Stream/Channel/Types.hs+8−8 src/Streamly/Internal/Data/Stream/Concurrent.hs+24−24 src/Streamly/Internal/FileSystem/Event/Windows.hs+1−1 test/Streamly/Test/Data/Stream/Concurrent.hs+2−2
benchmark/Streamly/Benchmark/Data/Stream/ConcurrentEager.hs+4−1
@@ -19,4 +19,7 @@ moduleName = "Data.Stream.ConcurrentEager"
1919-------------------------------------------------------------------------------
2020
2121main :: IO ()
22−main = runWithCLIOpts defaultStreamSize (allBenchmarks moduleName Async.eager)
22+main =
23+ runWithCLIOpts
24+ defaultStreamSize
25+ (allBenchmarks moduleName (Async.eager True))
benchmark/Streamly/Benchmark/Data/Stream/ConcurrentInterleaved.hs+2−1
@@ -21,4 +21,5 @@ moduleName = "Data.Stream.ConcurrentInterleaved"
2121main :: IO ()
2222main =
2323 runWithCLIOpts
24− defaultStreamSize (allBenchmarks moduleName Async.interleaved)
24+ defaultStreamSize
25+ (allBenchmarks moduleName (Async.interleaved True))
benchmark/Streamly/Benchmark/Data/Stream/ConcurrentOrdered.hs+3−1
@@ -20,4 +20,6 @@ moduleName = "Data.Stream.ConcurrentOrdered"
2020
2121main :: IO ()
2222main =
23− runWithCLIOpts defaultStreamSize (allBenchmarks moduleName Async.ordered)
23+ runWithCLIOpts
24+ defaultStreamSize
25+ (allBenchmarks moduleName (Async.ordered True))
src/Streamly/Internal/Data/Stream/Channel/Types.hs+8−8
@@ -489,8 +489,8 @@ getStreamLatency = _streamLatency
489489
490490-- | Print debug information about the 'Channel' when the stream ends.
491491--
492−inspect :: Config -> Config
493−inspect st = st { _inspect = True }
492+inspect :: Bool -> Config -> Config
493+inspect flag st = st { _inspect = flag }
494494
495495getInspectMode :: Config -> Bool
496496getInspectMode = _inspect
@@ -505,8 +505,8 @@ getInspectMode = _inspect
505505-- /Note:/ This option has no effect when rate has been specified.
506506-- /Note:/ Not supported with 'interleaved'.
507507--
508−eager :: Config -> Config
509−eager st = st { _eagerDispatch = True }
508+eager :: Bool -> Config -> Config
509+eager flag st = st { _eagerDispatch = flag }
510510
511511getEagerDispatch :: Config -> Bool
512512getEagerDispatch = _eagerDispatch
@@ -523,8 +523,8 @@ getStopWhen = _stopWhen
523523--
524524-- /Note:/ Not supported with 'interleaved'.
525525--
526−ordered :: Config -> Config
527−ordered st = st { _ordered = True }
526+ordered :: Bool -> Config -> Config
527+ordered flag st = st { _ordered = flag }
528528
529529getOrdered :: Config -> Bool
530530getOrdered = _ordered
@@ -536,8 +536,8 @@ getOrdered = _ordered
536536-- /Note:/ Can only be used on finite number of streams.
537537-- /Note:/ Not supported with 'ordered'.
538538--
539−interleaved :: Config -> Config
540−interleaved st = st { _interleaved = True }
539+interleaved :: Bool -> Config -> Config
540+interleaved flag st = st { _interleaved = flag }
541541
542542getInterleaved :: Config -> Bool
543543getInterleaved = _interleaved
src/Streamly/Internal/Data/Stream/Concurrent.hs+24−24
@@ -289,46 +289,46 @@ append2 = combineWith id
289289-- the left stream. This schedules all streams in a round robin fashion over
290290-- limited number of threads.
291291--
292−-- >>> interleave2 = Async.combineWith Async.interleaved
292+-- >>> interleave2 = Async.combineWith (Async.interleaved True)
293293--
294294{-# INLINE interleave2 #-}
295295interleave2 :: MonadAsync m => Stream m a -> Stream m a -> Stream m a
296−interleave2 = combineWith interleaved
296+interleave2 = combineWith (interleaved True)
297297
298298-- | Like 'append' but with 'ordered' on.
299299--
300−-- >>> ahead2 = Async.combineWith Async.ordered
300+-- >>> ahead2 = Async.combineWith (Async.ordered True)
301301--
302302{-# INLINE ahead2 #-}
303303ahead2 :: MonadAsync m => Stream m a -> Stream m a -> Stream m a
304−ahead2 = combineWith ordered
304+ahead2 = combineWith (ordered True)
305305
306306-- | Like 'append2' but with 'eager' on.
307307--
308−-- >>> parallel2 = Async.combineWith Async.eager
308+-- >>> parallel2 = Async.combineWith (Async.eager True)
309309--
310310{-# INLINE parallel2 #-}
311311parallel2 :: MonadAsync m => Stream m a -> Stream m a -> Stream m a
312−parallel2 = combineWith eager
312+parallel2 = combineWith (eager True)
313313
314314-- | Like 'parallel2' but stops the output as soon as the first stream stops.
315315--
316−-- >>> parallelFst2 = Async.combineWith (Async.eager . Async.stopWhen Async.FirstStops)
316+-- >>> parallelFst2 = Async.combineWith (Async.eager True . Async.stopWhen Async.FirstStops)
317317--
318318-- /Pre-release/
319319{-# INLINE parallelFst2 #-}
320320parallelFst2 :: MonadAsync m => Stream m a -> Stream m a -> Stream m a
321−parallelFst2 = combineWith (eager . stopWhen FirstStops)
321+parallelFst2 = combineWith (eager True . stopWhen FirstStops)
322322
323323-- | Like 'parallel2' but stops the output as soon as any of the two streams
324324-- stops.
325325--
326−-- >>> parallelMin2 = Async.combineWith (Async.eager . Async.stopWhen Async.AnyStops)
326+-- >>> parallelMin2 = Async.combineWith (Async.eager True . Async.stopWhen Async.AnyStops)
327327--
328328-- /Pre-release/
329329{-# INLINE parallelMin2 #-}
330330parallelMin2 :: MonadAsync m => Stream m a -> Stream m a -> Stream m a
331−parallelMin2 = combineWith (eager . stopWhen AnyStops)
331+parallelMin2 = combineWith (eager True . stopWhen AnyStops)
332332
333333-------------------------------------------------------------------------------
334334-- concat streams
@@ -482,11 +482,11 @@ concatMap = concatMapWith id
482482-- evaluate the earlier stream first, this schedules all streams in a round
483483-- robin fashion over the available threads.
484484--
485−-- >>> concatMapInterleave = Async.concatMapWith Async.interleaved
485+-- >>> concatMapInterleave = Async.concatMapWith (Async.interleaved True)
486486--
487487-- When used with a single thread it behaves like serial interleaving:
488488--
489−-- >>> f cfg xs = Stream.fold Fold.toList $ Async.concatMapWith (Async.interleaved . cfg) id $ Stream.fromList xs
489+-- >>> f cfg xs = Stream.fold Fold.toList $ Async.concatMapWith (Async.interleaved True . cfg) id $ Stream.fromList xs
490490--
491491-- >>> stream1 = Stream.fromList [1,2,3]
492492-- >>> stream2 = Stream.fromList [4,5,6]
@@ -497,7 +497,7 @@ concatMap = concatMapWith id
497497--
498498{-# INLINE concatMapInterleave #-}
499499concatMapInterleave :: MonadAsync m => (a -> Stream m b) -> Stream m a -> Stream m b
500−concatMapInterleave = concatMapWith interleaved
500+concatMapInterleave = concatMapWith (interleaved True)
501501
502502-- | Like 'concat' but we can also specify the concurrent channel's
503503-- configuration parameters using Config modifiers.
@@ -541,44 +541,44 @@ append = concatListWith id
541541-- the left stream. This schedules all streams in a round robin fashion over
542542-- limited number of threads.
543543--
544−-- >>> interleave = Async.concatListWith Async.interleaved
544+-- >>> interleave = Async.concatListWith (Async.interleaved True)
545545--
546546{-# INLINE interleave #-}
547547interleave :: MonadAsync m => [Stream m a] -> Stream m a
548−interleave = concatListWith interleaved
548+interleave = concatListWith (interleaved True)
549549
550550-- | Like 'append' but with 'ordered' on.
551551--
552−-- >>> ahead = Async.concatListWith Async.ordered
552+-- >>> ahead = Async.concatListWith (Async.ordered True)
553553--
554554{-# INLINE ahead #-}
555555ahead :: MonadAsync m => [Stream m a] -> Stream m a
556−ahead = concatListWith ordered
556+ahead = concatListWith (ordered True)
557557
558558-- | Like 'append' but with 'eager' on.
559559--
560−-- >>> parallel = Async.concatListWith Async.eager
560+-- >>> parallel = Async.concatListWith (Async.eager True)
561561--
562562{-# INLINE parallel #-}
563563parallel :: MonadAsync m => [Stream m a] -> Stream m a
564−parallel = concatListWith eager
564+parallel = concatListWith (eager True)
565565
566566-- | Like 'parallel' but stops the output as soon as the first stream stops.
567567--
568−-- >>> parallelFst = Async.concatListWith (Async.eager . Async.stopWhen Async.FirstStops)
568+-- >>> parallelFst = Async.concatListWith (Async.eager True . Async.stopWhen Async.FirstStops)
569569--
570570{-# INLINE parallelFst #-}
571571parallelFst :: MonadAsync m => [Stream m a] -> Stream m a
572−parallelFst = concatListWith (eager . stopWhen FirstStops)
572+parallelFst = concatListWith (eager True . stopWhen FirstStops)
573573
574574-- | Like 'parallel' but stops the output as soon as any of the two streams
575575-- stops.
576576--
577−-- >>> parallelMin = Async.concatListWith (Async.eager . Async.stopWhen Async.AnyStops)
577+-- >>> parallelMin = Async.concatListWith (Async.eager True . Async.stopWhen Async.AnyStops)
578578--
579579{-# INLINE parallelMin #-}
580580parallelMin :: MonadAsync m => [Stream m a] -> Stream m a
581−parallelMin = concatListWith (eager . stopWhen AnyStops)
581+parallelMin = concatListWith (eager True . stopWhen AnyStops)
582582
583583-------------------------------------------------------------------------------
584584-- Applicative
@@ -671,7 +671,7 @@ zipWith f = zipWithM (\a b -> return $ f a b)
671671{-# INLINE_NORMAL newCallbackStream #-}
672672newCallbackStream :: MonadAsync m => m (a -> m (), Stream m a)
673673newCallbackStream = do
674− chan <- newChannel eager
674+ chan <- newChannel (eager True)
675675
676676 -- XXX Add our own thread-id to the SVar as we can not know the callback's
677677 -- thread-id and the callback is not run in a managed worker. We need to
src/Streamly/Internal/FileSystem/Event/Windows.hs+1−1
@@ -471,7 +471,7 @@ closePathHandleStream =
471471--
472472watchWith :: (Config -> Config) -> NonEmpty (Array Word8) -> Stream IO Event
473473watchWith f paths =
474− S.bracketIO before after (Concur.concatMapWith eager eventStreamAggr)
474+ S.bracketIO before after (Concur.concatMapWith (eager True) eventStreamAggr)
475475
476476 where
477477
test/Streamly/Test/Data/Stream/Concurrent.hs+2−2
@@ -83,9 +83,9 @@ commonOpConfigs =
8383 , ("maxBuffer 0", Async.maxBuffer 0)
8484 , ("maxThreads 0", Async.maxThreads 0)
8585 , ("maxThreads 1", Async.maxThreads 1)
86− , ("eager", Async.eager)
86+ , ("eager", Async.eager True)
8787 -- XXX Need to use an unsorted eq operation for ahead
88− , ("ordered", Async.ordered)
88+ , ("ordered", Async.ordered True)
8989#ifdef USE_LARGE_MEMORY
9090 , ("maxThreads -1", Async.maxThreads (-1))
9191#endif