Skip to content

Commit a5e309d

Browse files
authored
Merge pull request #6361 from IntersectMBO/fmaste/trace-forward
trace-forward | sink write and read optimizations
2 parents 0614f23 + d1e8c91 commit a5e309d

File tree

17 files changed

+163
-187
lines changed

17 files changed

+163
-187
lines changed

bench/tx-generator/src/Cardano/Benchmarking/Tracer.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ initialTraceConfig = TraceConfig {
172172
, setMaxDetail TracerNameConnect
173173
, setMaxDetail TracerNameSubmit
174174
]
175-
, tcForwarder = Just defaultForwarder {tofConnQueueSize = 2048, tofDisconnQueueSize = 4096}
175+
, tcForwarder = Just defaultForwarder {tofQueueSize = 4096}
176176
, tcNodeName = Nothing
177177
, tcPeerFrequency = Just 2000 -- Every 2 seconds
178178
, tcResourceFrequency = Just 1000 -- Every second

cardano-tracer/demo/multi/forwarder.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ import System.Environment (getArgs)
66

77
main :: IO ()
88
main = getArgs >>= \case
9-
[localSock, "Initiator"] -> launchForwardersSimple Initiator localSock 1000 2000
10-
[localSock, "Responder"] -> launchForwardersSimple Responder localSock 1000 2000
9+
[localSock, "Initiator"] -> launchForwardersSimple Initiator localSock 2000
10+
[localSock, "Responder"] -> launchForwardersSimple Responder localSock 2000
1111
_ -> putStrLn "Usage: ./demo-forwarder /path/to/local/sock Initiator|Responder"

cardano-tracer/demo/ssh/forwarder.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ main = getArgs >>=
2121
, tsWorkDir = Identity "."
2222
}
2323
in case mode of
24-
"Initiator" -> launchForwardersSimple ts Initiator (Net.LocalPipe localSock) 1000 2000
25-
"Responder" -> launchForwardersSimple ts Responder (Net.LocalPipe localSock) 1000 2000
24+
"Initiator" -> launchForwardersSimple ts Initiator (Net.LocalPipe localSock) 2000
25+
"Responder" -> launchForwardersSimple ts Responder (Net.LocalPipe localSock) 2000
2626
_ -> err
2727
_ -> err
2828
where err = error "Usage: ./demo-forwarder /path/to/local/sock Initiator|Responder"

cardano-tracer/test/Cardano/Tracer/Test/DataPoint/Tests.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ propDataPoint ts@TestSetup{..} rootDir localSock = do
4141
savedDPValues :: TVar DataPointValues <- newTVarIO []
4242
withAsync (doRunCardanoTracer config (Just $ rootDir <> "/../state") stderrShowTracer stopProtocols dpRequestors) \_ -> do
4343
sleep 1.0
44-
withAsync (launchForwardersSimple ts Initiator (Net.LocalPipe localSock) 1000 10000) \_ -> do
44+
withAsync (launchForwardersSimple ts Initiator (Net.LocalPipe localSock) 10000) \_ -> do
4545
sleep 1.5
4646
-- We know that there is one single "node" only (and one single requestor too).
4747
-- requestors ((_, dpRequestor):_) <- M.toList <$> readTVarIO dpRequestors

cardano-tracer/test/Cardano/Tracer/Test/Forwarder.hs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,18 @@ launchForwardersSimple
9191
-> ForwardersMode
9292
-> HowToConnect
9393
-> Word
94-
-> Word
9594
-> IO ()
96-
launchForwardersSimple ts mode howToConnect connSize disconnSize = withIOManager \iomgr ->
97-
runInLoop (launchForwardersSimple' ts iomgr mode howToConnect connSize disconnSize) (Just Minimum) howToConnect 1
95+
launchForwardersSimple ts mode howToConnect queueSize = withIOManager \iomgr ->
96+
runInLoop (launchForwardersSimple' ts iomgr mode howToConnect queueSize) (Just Minimum) howToConnect 1
9897

9998
launchForwardersSimple'
10099
:: TestSetup Identity
101100
-> IOManager
102101
-> ForwardersMode
103102
-> HowToConnect
104103
-> Word
105-
-> Word
106104
-> IO ()
107-
launchForwardersSimple' ts iomgr mode howToConnect connSize disconnSize =
105+
launchForwardersSimple' ts iomgr mode howToConnect queueSize =
108106
case (howToConnect, mode) of
109107
(Net.RemoteSocket (Text.unpack -> host) (show -> port), Initiator) -> do
110108
result <- try @IOException do
@@ -177,8 +175,7 @@ launchForwardersSimple' ts iomgr mode howToConnect connSize disconnSize =
177175
tfConfig =
178176
TOF.ForwarderConfiguration
179177
{ TOF.forwarderTracer = nullTracer -- contramap show stdoutTracer
180-
, TOF.disconnectedQueueSize = disconnSize
181-
, TOF.connectedQueueSize = connSize
178+
, TOF.queueSize = queueSize
182179
}
183180

184181
dpfConfig :: DPF.ForwarderConfiguration

cardano-tracer/test/Cardano/Tracer/Test/Logs/Tests.hs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ propLogs ts@TestSetup{..} format logRotLimitBytes logRotMaxAgeMinutes rootDir lo
5151
withAsync (doRunCardanoTracer (acceptConfig rootDir) (Just $ rootDir <> "/../state") stderrShowTracer stopProtocols dpRequestors) \async1 -> do
5252
link async1
5353
sleep 1.0
54-
withAsync (launchForwardersSimple ts Initiator (Net.LocalPipe localSock) 1000 10000) \async2 -> do
54+
withAsync (launchForwardersSimple ts Initiator (Net.LocalPipe localSock) 10000) \async2 -> do
5555
link async2
5656
sleep 8.0 -- Wait till some rotation is done.
5757
applyBrake stopProtocols
@@ -92,10 +92,10 @@ propMultiInit ts@TestSetup{..} format rootDir howToConnect1 howToConnect2 = do
9292
withAsync (doRunCardanoTracer initConfig (Just $ rootDir <> "/../state") stderrShowTracer stopProtocols dpRequestors) \async1 -> do
9393
link async1
9494
sleep 1.0
95-
withAsync (launchForwardersSimple ts Responder howToConnect1 1000 10000) \async2 -> do
95+
withAsync (launchForwardersSimple ts Responder howToConnect1 10000) \async2 -> do
9696
link async2
9797
sleep 1.0
98-
withAsync (launchForwardersSimple ts Responder howToConnect2 1000 10000) \async3 -> do
98+
withAsync (launchForwardersSimple ts Responder howToConnect2 10000) \async3 -> do
9999
link async3
100100
sleep 5.0 -- Wait till some work is done.
101101
applyBrake stopProtocols
@@ -132,12 +132,12 @@ propMultiResp ts@TestSetup{..} format rootDir howToConnect = do
132132
withAsync (doRunCardanoTracer respConfig (Just $ rootDir <> "/../state") stderrShowTracer stopProtocols dpRequestors) \async1 -> do
133133
link async1
134134
sleep 1.0
135-
-- withAsync (launchForwardersSimple ts Initiator howToConnect 1000 10000) \async2 -> do
136-
withAsync (launchForwardersSimple ts Initiator howToConnect 1000 10000) \async2 -> do
135+
-- withAsync (launchForwardersSimple ts Initiator howToConnect 10000) \async2 -> do
136+
withAsync (launchForwardersSimple ts Initiator howToConnect 10000) \async2 -> do
137137
link async2
138138
sleep 1.0
139-
-- withAsync (launchForwardersSimple ts Initiator howToConnect 1000 10000) \async3 -> do
140-
withAsync (launchForwardersSimple ts Initiator howToConnect 1000 10000) \async3 -> do
139+
-- withAsync (launchForwardersSimple ts Initiator howToConnect 10000) \async3 -> do
140+
withAsync (launchForwardersSimple ts Initiator howToConnect 10000) \async3 -> do
141141
link async3
142142
sleep 5.0 -- Wait till some work is done.
143143
applyBrake stopProtocols

cardano-tracer/test/Cardano/Tracer/Test/Queue/Tests.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ propQueue ts rootDir localSocket = do
3737
-- Run the forwarder only. It imitates the case when the acceptor is
3838
-- misconfigured and cannot be launched, so the connection cannot be established.
3939
-- In this case, the forwarder should collect trace items in its internal
40-
-- "flexible queue" and periodically flush them to stdout.
41-
withAsyncBound (launchForwardersSimple ts Responder (Net.LocalPipe localSocket) connSize disconnSize) . const $
40+
-- fixed-capacity queue and periodically flush them to stdout.
41+
withAsyncBound (launchForwardersSimple ts Responder (Net.LocalPipe localSocket) queueSize) . const $
4242
-- Wait till the queue will be redirected to stdout.
4343
sleep 7.0
4444
-- Return the normal stdout.
@@ -48,8 +48,8 @@ propQueue ts rootDir localSocket = do
4848
content <- TIO.readFile tmpPath
4949
removeFile tmpPath
5050
let flushedTraceObjectsNum = T.count "TraceObject" content
51-
return $ flushedTraceObjectsNum === fromIntegral disconnSize
51+
return $ flushedTraceObjectsNum === fromIntegral queueSize
52+
53+
queueSize :: Word
54+
queueSize = 100
5255

53-
connSize, disconnSize :: Word
54-
connSize = 50
55-
disconnSize = 100

cardano-tracer/test/Cardano/Tracer/Test/Restart/Tests.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ propNetworkForwarder ts rootDir localSock = do
4141
brake <- initProtocolsBrake
4242
dpRequestors <- initDataPointRequestors
4343
propNetwork' ts rootDir
44-
( launchForwardersSimple ts Initiator (Net.LocalPipe localSock) 1000 10000
44+
( launchForwardersSimple ts Initiator (Net.LocalPipe localSock) 10000
4545
, doRunCardanoTracer config (Just $ rootDir <> "/../state") stderrShowTracer brake dpRequestors
4646
)
4747

trace-dispatcher/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Revision history for trace-dispatcher
22

3+
## NEXT -- Nov 2025
4+
5+
* Replaced both `tofDisconnQueueSize` and `tofConnQueueSize` with `tofQueueSize` (See #6361 for details).
6+
37
## 2.10.0 -- July, 2025
48
* Forwarding protocol supports connections over TCP socket, in addition to Unix domain sockets.
59
* Failure to initialise the `PrometheusSimple` backend is now lenient - i.e., won't result in an exception being propagated.

trace-dispatcher/src/Cardano/Logging/Types.hs

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -487,50 +487,59 @@ instance AE.FromJSON Verbosity where
487487
<> "Unknown Verbosity: " <> show other
488488

489489
data TraceOptionForwarder = TraceOptionForwarder {
490-
tofConnQueueSize :: Word
491-
, tofDisconnQueueSize :: Word
490+
tofQueueSize :: Word
492491
, tofVerbosity :: Verbosity
493492
, tofMaxReconnectDelay :: Word
494493
} deriving stock (Eq, Ord, Show, Generic)
495494

496-
-- A word regarding queue sizes:
495+
-- A word regarding queue size:
496+
--
497497
-- In case of a missing forwarding service consumer, traces messages will be
498-
-- buffered. This mitigates short forwarding interruptions, or delays at startup time.
498+
-- buffered. This mitigates short forwarding interruptions, or delays at startup
499+
-- time.
499500
--
500-
-- The queue capacity should thus correlate to the expected log lines per second given
501-
-- a particular tracing configuration - to avoid unnecessarily increasing memory footprint.
501+
-- The queue capacity should thus correlate to the expected log lines per second
502+
-- given a particular tracing configuration - to avoid unnecessarily increasing
503+
-- memory footprint.
502504
--
503505
-- The default values here are chosen to accomodate verbose tracing output
504-
-- (i.e., buffering 1min worth of trace data given ~32 messages per second). A config
505-
-- that results in less than 5 msgs per second should also provide TraceOptionForwarder
506-
-- queue size values considerably lower. The `disconnQueueSize` is the hard limit in that case.
506+
-- (i.e., buffering 1min worth of trace data given ~32 messages per second). A
507+
-- config that results in less than 5 msgs per second should also provide
508+
-- `TraceOptionForwarder` a queue size value considerably lower.
507509
--
508-
-- The queue sizes tie in with the max number of trace objects cardano-tracer requests periodically,
509-
-- the default for that being 100. Here, the basic queue can hold enough traces for 10 subsequent polls
510-
-- by cardano-tracer.
510+
-- The queue size ties in with the max number of trace objects cardano-tracer
511+
-- requests periodically, the default for that being 100. Here, the queue can
512+
-- hold enough traces for 10 subsequent polls by cardano-tracer.
511513
instance AE.FromJSON TraceOptionForwarder where
512-
parseJSON (AE.Object obj) =
513-
TraceOptionForwarder
514-
<$> obj AE..:? "connQueueSize" AE..!= 1024
515-
<*> obj AE..:? "disconnQueueSize" AE..!= 2048
516-
<*> obj AE..:? "verbosity" AE..!= Minimum
517-
<*> obj AE..:? "maxReconnectDelay" AE..!= 60
514+
parseJSON (AE.Object obj) = do
515+
-- Field "queueSize" is the new field that replaces and unifies
516+
-- both "connQueueSize" and "disconnQueueSize".
517+
maybeQueueSize <- obj AE..:? "queueSize"
518+
queueSize <- case maybeQueueSize of
519+
-- If the new field was provided we use it.
520+
(Just qs) -> return qs
521+
-- Else we look for the deprectaed fields.
522+
Nothing -> do
523+
-- We keep the same default values.
524+
connQueueSize <- obj AE..:? "connQueueSize" AE..!= 1024
525+
disconnQueueSize <- obj AE..:? "disconnQueueSize" AE..!= 2048
526+
return $ max connQueueSize disconnQueueSize
527+
verbosity <- obj AE..:? "verbosity" AE..!= Minimum
528+
maxReconnectDelay <- obj AE..:? "maxReconnectDelay" AE..!= 60
529+
return $ TraceOptionForwarder queueSize verbosity maxReconnectDelay
518530
parseJSON _ = mempty
519531

520-
521532
instance AE.ToJSON TraceOptionForwarder where
522533
toJSON TraceOptionForwarder{..} = AE.object
523534
[
524-
"connQueueSize" AE..= tofConnQueueSize,
525-
"disconnQueueSize" AE..= tofDisconnQueueSize,
535+
"queueSize" AE..= tofQueueSize,
526536
"verbosity" AE..= tofVerbosity,
527537
"maxReconnectDelay" AE..= tofMaxReconnectDelay
528538
]
529539

530540
defaultForwarder :: TraceOptionForwarder
531541
defaultForwarder = TraceOptionForwarder {
532-
tofConnQueueSize = 1024
533-
, tofDisconnQueueSize = 2048
542+
tofQueueSize = 2048
534543
, tofVerbosity = Minimum
535544
, tofMaxReconnectDelay = 60
536545
}

0 commit comments

Comments
 (0)