Skip to content

Commit 863ad8d

Browse files
authored
Coroutine instrumentation Q/A added to UG FAQ (#634)
1 parent 08039d0 commit 863ad8d

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

user-guide/modules/ROOT/pages/faq.adoc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,29 @@ Requesting value...
11051105
Got result: 333
11061106
----
11071107

1108+
. *What is considered best practices for instrumenting a coroutine based program - what should be logged?*
1109+
+
1110+
Instrumenting coroutine-based code is a little different from instrumenting traditional synchronous code because control flow becomes non-linear. For long-running or important coroutines, log "coroutine x started" and "coroutine x completed". And don't forget errors "coroutine x failed: timeout". The most valuable information in coroutine systems is often before and after `co_await`. Cancellation is frequently overlooked, make sure to log concellation requests, cancellation observed, and probably a cleanup complete message too. This is enormously helpful when investigating shutdown issues.
1111+
+
1112+
For performance-based instrumentation, obviously add accurate timing to your logs, such as "Socket read completed in 2.1 ms".
1113+
+
1114+
Large coroutine systems become nearly impossible to diagnose without _corelation IDs_ - IDs that connect sockets, databases, timers and worker pools. A corelation ID should be generated and logged along with coroutine events such as requests, queueing or waiting, completion, response sent. Coroutine systems often hide queueing, so it will be helpful to have logs of "queued for 18 ms" and " exectured for 2 ms" - obviously to help you identify bottlenecks. Tracing resource ownership has also proved to be of value, as coroutines often make resource lifetimes less obvious because ownership spans suspension points.
1115+
+
1116+
Consider _not_ logging every suspend/resume event, as this will very quickly become noise.
1117+
+
1118+
For boost:asio[] applications specifically, a common best practice is to trace:
1119+
+
1120+
.. Coroutine start/end
1121+
.. Every significant `co_await` of I/O operations
1122+
.. Executor transitions (post, dispatch, thread-pool hops)
1123+
.. Exceptions and cancellations
1124+
.. Timing information around each awaited operation
1125+
.. A request/session correlation ID carried through the coroutine chain
1126+
+
1127+
Those six categories typically provide most of the diagnostic value with relatively little logging overhead.
1128+
1129+
1130+
11081131

11091132
== Debugging
11101133

0 commit comments

Comments
 (0)