on master help sign in
Add auto concurrency control section in overview
commitbb746aa407c83171555a6c4c68444e8bd8618655 authorHarendra Kumar <harendra@composewell.com> dateMon 29 Mar 2021, 23:05 (6 years ago) parent5616d0e
1 file changed+14−4
src/Streamly/Prelude.hs+14−4
src/Streamly/Prelude.hs+14−4
@@ -129,10 +129,6 @@
129129-- >>> Stream.drain $ Stream.asyncly $ Stream.replicateM 10 $ delay 1
130130-- ...
131131--
132−-- By default, there is a limit on how many concurrent actions may be executed
133−-- at a time, the "Concurrency Control" section describes combinators that can
134−-- be used to control the concurrency.
135−--
136132-- We can use 'mapM' to map an action concurrently:
137133--
138134-- >>> f x = delay 1 >> return (x + 1)
@@ -148,6 +144,20 @@
148144-- constraint. However, a @MonadAsync m@ constraint does not necessarily mean
149145-- that the combinator is concurrent.
150146--
147+-- == Automatic Concurrency Control
148+--
149+-- 'SerialT' (and 'WSerialT') runs all tasks serially whereas 'ParallelT' runs
150+-- all tasks concurrently i.e. one thread per task. The stream types 'AsyncT',
151+-- 'WAsyncT', and 'AheadT' provide demand driven concurrency. It means that
152+-- based on the rate at which the consumer is consuming the stream, it
153+-- maintains the optimal number of threads to increase or decrease parallelism.
154+--
155+-- However, the programmer can control the maximum number of threads using
156+-- 'maxThreads'. It provides an upper bound on the concurrent IO requests or
157+-- CPU cores that can be used. 'maxBuffer' limits the number of evaluated
158+-- stream elements that we can buffer. See the "Concurrency Control" section
159+-- for details.
160+--
151161-- == Combining Two streams
152162--
153163-- Earlier we distinguished stream types based on the execution behavior of