Conversation
rcoh
left a comment
There was a problem hiding this comment.
mostly looking at high level stuff. didnt' get super deep in the code itself
| } | ||
| } | ||
|
|
||
| impl<S: task_dump_config_builder::State> TaskDumpConfigBuilder<S> { |
There was a problem hiding this comment.
I wonder if we should make TaskDumpConfigV2 no strong preference, but its possible some code would be simpler if we had two independent code paths.
There was a problem hiding this comment.
Done. I changed direction by adapting my changes on top of fresh upstream main. That's why history got re-written. I also removed the published demo trace file as this produces a new event that is not consumed yet, and can not be produced at the same time as TaskDumps from the metrics-service example.
The old feature is called TaskDump, and the new one is called TaskSample. That's reflected in all related types, like event types or config types. (I can adjust the name).
Inside the same runtime, task dumps and task samples are exclusive, but you can have 2 different runtimes, configured differently.
There was a problem hiding this comment.
Now that I think, maybe we should protect this config API with a experimental-task-sampling flag.
| // preceding epoch was empty. A quiet worker can sample every transition. | ||
| let previous_count = if epochs == 1 { self.eligible } else { 0 }; | ||
| self.probability = if previous_count == 0 { | ||
| 1.0 |
There was a problem hiding this comment.
this is definitely not going to work for production. Setting probability to 1 would be a large bottleneck for a production service. I think you are already looking into some options, but we need to have a cap.
| /// Shared by every thread that drives a logical worker. The source reads | ||
| /// activation metadata without locking a worker's sampling decision. | ||
| #[cfg(feature = "taskdump")] | ||
| task_dump_workers: Mutex<BTreeMap<u64, Arc<crate::task_dump_sampler::WorkerTaskDumpSampler>>>, |
There was a problem hiding this comment.
having this be a btree map is probably going to be a performance problem. Did you benchmark this? This should probably be a Vec instead.
Secondarily, I think having this mutex be on every Pending might end up being too hot. Would be good to have some benchmarks with this on vs. off.
One option could be a TLS that stores the current worker id and has some sort of fast path for when there wasn't a worker handoff?
There was a problem hiding this comment.
The Mutex<BTreeMap<...> is not locked/looked-up on every Pending. I cache in TLS the WorkerTaskDumpSampler.
I'm in the middle of moving things around but look for static SAMPLER: RefCell<Option<Arc<WorkerTaskDumpSampler>>>, which is set from the existing register_worker_if_needed.
TaskDumped<F> always obtains its sampler from TLS. It also makes an Arc::clone of it (only if pointers are really different) to keep it stable during the poll.
The only Mutex::lock being called in Pendings is the internal one, inside WorkerTaskDumpSampler, which should be mostly un-contended (except in the block_in_place case which may move the worker's core to a different thread to continue operating, while the original thread also uses that Mutex).
There was a problem hiding this comment.
Note: BTreeMap is used because register_worker_if_needed currentely receives dial9's global/displaced worker index, which has no fixed maximum (as runtimes can be dynamically created).
But, there is not reason to actually use that global id for this, I think? I can use Tokio's raw worker index without displacement, and put data into pre-allocated Box<[Option<...>]> using num_workers() as the size.
(I'm trying this change now)
There was a problem hiding this comment.
9b9d9f7 to
765de52
Compare
Changes
TaskSamplingConfig,DIAL9_TASK_SAMPLING_ENABLED, andDIAL9_TASK_SAMPLING_PER_WORKER_HZ. ExistingTaskDumpConfigand idle-threshold settings retain their behavior.TaskSampleEvents with capture probabilities and sampling metadata for future mixed flamegraphs.For reviewers
Just in case, check the changes in the design first, then prioritize:
dial9-tokio-telemetry/src/telemetry/task_sampling_config.rs,dial9/src/env_config.rs.dial9-tokio-telemetry/src/task_dump/, particularlysampler.rs,worker.rs, andsampled.rs.legacy.rspreserves the existing policy.capture.rscontains shared capture mechanics.dial9-tokio-telemetry/src/telemetry/recorder/runtime_context.rs.Closes #842