Skip to content

Commit e7001c9

Browse files
authored
Merge pull request #134 from istathar/rate-limit
Limit the rate which telemetry is read from queue
2 parents a950bff + 3a1b984 commit e7001c9

File tree

9 files changed

+31
-27
lines changed

9 files changed

+31
-27
lines changed

core-program/core-program.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cabal-version: 1.12
55
-- see: https://github.com/sol/hpack
66

77
name: core-program
8-
version: 0.5.0.1
8+
version: 0.5.0.2
99
synopsis: Opinionated Haskell Interoperability
1010
description: A library to help build command-line programs, both tools and
1111
longer-running daemons.

core-program/lib/Core/Program/Execute.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ loopForever :: ([a] -> IO ()) -> MVar Verbosity -> TQueue (Maybe Rope) -> TQueue
401401
loopForever action v out queue = do
402402
-- block waiting for an item
403403
possibleItems <- atomically $ do
404-
cycleOverQueue []
404+
cycleOverQueue 0 []
405405

406406
case possibleItems of
407407
-- we're done!
@@ -419,7 +419,12 @@ loopForever action v out queue = do
419419
)
420420
loopForever action v out queue
421421
where
422-
cycleOverQueue items =
422+
cycleOverQueue !count items =
423+
if count >= (1024 :: Int)
424+
then pure (Just items)
425+
else cycleOverQueue' count items
426+
427+
cycleOverQueue' !count items =
423428
case items of
424429
[] -> do
425430
possibleItem <- readTQueue queue -- blocks
@@ -428,7 +433,7 @@ loopForever action v out queue = do
428433
Nothing -> pure Nothing
429434
-- otherwise start accumulating
430435
Just item -> do
431-
cycleOverQueue (item : [])
436+
cycleOverQueue 1 (item : [])
432437
_ -> do
433438
pending <- tryReadTQueue queue -- doesn't block
434439
case pending of
@@ -446,7 +451,7 @@ loopForever action v out queue = do
446451
pure (Just items)
447452
-- continue accumulating!
448453
Just item -> do
449-
cycleOverQueue (item : items)
454+
cycleOverQueue (count + 1) (item : items)
450455

451456
reportStatus start num = do
452457
level <- readMVar v

core-program/package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: core-program
2-
version: 0.5.0.1
2+
version: 0.5.0.2
33
synopsis: Opinionated Haskell Interoperability
44
description: |
55
A library to help build command-line programs, both tools and

core-telemetry/core-telemetry.cabal

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cabal-version: 1.18
55
-- see: https://github.com/sol/hpack
66

77
name: core-telemetry
8-
version: 0.2.3.2
8+
version: 0.2.3.3
99
synopsis: Advanced telemetry
1010
description: This is part of a library to help build command-line programs, both tools and
1111
longer-running daemons.
@@ -52,9 +52,9 @@ library
5252
async
5353
, base >=4.11 && <5
5454
, bytestring
55-
, core-data >=0.3.3
56-
, core-program >=0.5.0
57-
, core-text >=0.3.7
55+
, core-data >=0.3.3.1
56+
, core-program >=0.5.0.2
57+
, core-text >=0.3.7.1
5858
, exceptions
5959
, http-streams
6060
, io-streams

core-telemetry/package.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: core-telemetry
2-
version: 0.2.3.2
2+
version: 0.2.3.3
33
synopsis: Advanced telemetry
44
description: |
55
This is part of a library to help build command-line programs, both tools and
@@ -33,9 +33,9 @@ dependencies:
3333
library:
3434
dependencies:
3535
- async
36-
- core-text >= 0.3.7
37-
- core-data >= 0.3.3
38-
- core-program >= 0.5.0
36+
- core-text >= 0.3.7.1
37+
- core-data >= 0.3.3.1
38+
- core-program >= 0.5.0.2
3939
- exceptions
4040
- http-streams
4141
- io-streams

core-text/core-text.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cabal-version: 1.18
55
-- see: https://github.com/sol/hpack
66

77
name: core-text
8-
version: 0.3.7.2
8+
version: 0.3.7.3
99
synopsis: A rope type based on a finger tree over UTF-8 fragments
1010
description: A rope data type for text, built as a finger tree over UTF-8 text
1111
fragments. The package also includes utiltiy functions for breaking and

core-text/lib/Core/Text/Utilities.hs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{-# LANGUAGE AllowAmbiguousTypes #-}
22
{-# LANGUAGE BangPatterns #-}
33
{-# LANGUAGE FlexibleInstances #-}
4+
{-# LANGUAGE ImportQualifiedPost #-}
45
{-# LANGUAGE OverloadedStrings #-}
56
{-# LANGUAGE ScopedTypeVariables #-}
67
{-# LANGUAGE TypeApplications #-}
@@ -52,13 +53,13 @@ import Core.Text.Colour
5253
import Core.Text.Parsing
5354
import Core.Text.Rope
5455
import Data.Bits (Bits (..))
55-
import qualified Data.ByteString as B (ByteString, length, splitAt, unpack)
56+
import Data.ByteString qualified as B (ByteString, length, splitAt, unpack)
5657
import Data.Char (intToDigit)
57-
import qualified Data.FingerTree as F (ViewL (..), viewl, (<|))
58+
import Data.FingerTree qualified as F (ViewL (..), viewl, (<|))
5859
import Data.Kind (Type)
59-
import qualified Data.List as List (dropWhileEnd, foldl', splitAt)
60-
import qualified Data.Text as T
61-
import qualified Data.Text.Short as S (
60+
import Data.List qualified as List (dropWhileEnd, foldl', splitAt)
61+
import Data.Text qualified as T
62+
import Data.Text.Short qualified as S (
6263
ShortText,
6364
replicate,
6465
singleton,
@@ -164,10 +165,9 @@ twoWords ds = go ds
164165
where
165166
go [] = []
166167
go [x] = [softline' <> x]
167-
go xs =
168-
let (one : two : [], remainder) = List.splitAt 2 xs
169-
in group (one <> spacer <> two) : go remainder
170-
168+
go xs = case List.splitAt 2 xs of
169+
(one : two : [], remainder) -> group (one <> spacer <> two) : go remainder
170+
_ -> [] -- unreachable
171171
spacer = flatAlt softline' " "
172172

173173
byteChunk :: B.ByteString -> [B.ByteString]
@@ -316,7 +316,6 @@ Sadly if there is only one item you don't get an Oxford comma, either:
316316
λ> __oxford []__
317317
""
318318
@
319-
320319
-}
321320
oxford :: [Rope] -> Rope
322321
oxford [] = emptyRope

core-text/package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: core-text
2-
version: 0.3.7.2
2+
version: 0.3.7.3
33
synopsis: A rope type based on a finger tree over UTF-8 fragments
44
description: |
55
A rope data type for text, built as a finger tree over UTF-8 text

stack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
resolver: nightly-2022-05-28
1+
resolver: nightly-2022-06-06
22
packages:
33
- ./core-data
44
- ./core-text

0 commit comments

Comments
 (0)