Commit 1813369
authored
Fixing DSM flush logic & CPU usage (#7827)
## Summary of changes
Moves DSM flush work to a dedicated thread to improve thread pool
performance. Also simplifies the flushing logic to more closely match
the AgentWriter logic.
(See below for test results)
## Reason for change
A = DSM enabled after the fix
B = DSM enabled before the fix
<img width="1168" height="573" alt="Screenshot 2025-12-01 at 5 23 44 pm"
src="https://github.com/user-attachments/assets/95d77f11-927c-4e7a-bfa6-451a1cf527a9"
/>
DSM flush logic was previously running entirely on the thread pool,
which includes the task to frequently move DSM checkpoints off of the
buffer and add them to the backlog. This was causing thread contention
shown in the above profile.
## Implementation details
Moves the DSM buffer flushing logic into it's own thread. Below is a
profile after the fix (DSM disabled on the right).
<img width="1422" height="622" alt="Screenshot 2025-12-01 at 5 26 53 pm"
src="https://github.com/user-attachments/assets/4a0cb28a-633f-47c8-9e04-cff9ce6829b9"
/>
## Test coverage
Mostly manual testing. I ran a set of three apps:
1. DSM enabled, after the fix
2. DSM disabled, after the fix
3. DSM enabled, before the fix
The test app just forwards a Kafka message every 0.5 seconds.
And run those via docker-compose with a restricted CPU count of 0.1 and
0.5 in the below screenshots. In both cases, DSM disabled is the lowest
CPU usage, and the line just above is DSM enabled after the fix. The
highest CPU is DSM enabled, prior to the fix. The performance is a lot
better, but I'm not sure if the gap can be closed further.
<img width="1046" height="523" alt="Screenshot 2025-12-01 at 6 30 10 pm"
src="https://github.com/user-attachments/assets/09cc8cdb-ba8d-4b44-be6e-b866cccb022d"
/>
<img width="694" height="379" alt="Screenshot 2025-12-01 at 5 55 28 pm"
src="https://github.com/user-attachments/assets/f4e1c24d-4800-46ed-8e86-42eec3def22d"
/>
## Other details1 parent 24ae76f commit 1813369
File tree
2 files changed
+99
-63
lines changed- tracer
- src/Datadog.Trace/DataStreamsMonitoring
- test/Datadog.Trace.Tests/DataStreamsMonitoring
2 files changed
+99
-63
lines changedLines changed: 98 additions & 62 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| 33 | + | |
31 | 34 | | |
32 | 35 | | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
36 | | - | |
| 39 | + | |
37 | 40 | | |
38 | 41 | | |
39 | 42 | | |
40 | | - | |
41 | 43 | | |
| 44 | + | |
42 | 45 | | |
43 | | - | |
| 46 | + | |
44 | 47 | | |
45 | 48 | | |
46 | 49 | | |
| |||
93 | 96 | | |
94 | 97 | | |
95 | 98 | | |
96 | | - | |
| 99 | + | |
97 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
98 | 105 | | |
99 | 106 | | |
100 | 107 | | |
| |||
169 | 176 | | |
170 | 177 | | |
171 | 178 | | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | 179 | | |
179 | 180 | | |
180 | | - | |
| 181 | + | |
181 | 182 | | |
182 | 183 | | |
183 | 184 | | |
184 | 185 | | |
185 | 186 | | |
186 | 187 | | |
| 188 | + | |
| 189 | + | |
187 | 190 | | |
188 | 191 | | |
189 | | - | |
| 192 | + | |
190 | 193 | | |
191 | | - | |
192 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
193 | 204 | | |
194 | | - | |
| 205 | + | |
195 | 206 | | |
196 | | - | |
| 207 | + | |
197 | 208 | | |
198 | | - | |
| 209 | + | |
| 210 | + | |
199 | 211 | | |
200 | 212 | | |
201 | | - | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
202 | 216 | | |
203 | 217 | | |
204 | 218 | | |
| 219 | + | |
| 220 | + | |
205 | 221 | | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
210 | 228 | | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
215 | 237 | | |
216 | | - | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
217 | 248 | | |
218 | | - | |
| 249 | + | |
219 | 250 | | |
220 | 251 | | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
221 | 273 | | |
222 | 274 | | |
223 | | - | |
224 | 275 | | |
225 | 276 | | |
226 | 277 | | |
227 | 278 | | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | 279 | | |
234 | 280 | | |
235 | 281 | | |
| |||
268 | 314 | | |
269 | 315 | | |
270 | 316 | | |
271 | | - | |
| 317 | + | |
272 | 318 | | |
273 | | - | |
274 | 319 | | |
275 | 320 | | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
276 | 333 | | |
277 | 334 | | |
278 | 335 | | |
| |||
284 | 341 | | |
285 | 342 | | |
286 | 343 | | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | 344 | | |
297 | 345 | | |
298 | 346 | | |
299 | | - | |
| 347 | + | |
300 | 348 | | |
301 | | - | |
302 | | - | |
| 349 | + | |
303 | 350 | | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
| 351 | + | |
313 | 352 | | |
314 | 353 | | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
| 354 | + | |
319 | 355 | | |
320 | | - | |
| 356 | + | |
321 | 357 | | |
322 | 358 | | |
323 | 359 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
221 | | - | |
| 221 | + | |
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
| |||
0 commit comments