Fair sampling with very low sample rates
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 207
- Forks
- 17
- PR merge metrics
- No merged PRs in 30d
Description
It may be desirable to run the sampling profiler with a very low sample rate. Instead of sampling every 1ms on 0.1% of users, more representative results could be achieved with one sample every 1s on 100% of users. (Facebook samples stacks from each machine in the server fleet once every 10 seconds to derive a representative dataset.)
However, large sample rates are likely to give a biased sample if not implemented “fairly”. For example, if profiling begins at pageload with a 1s sample rate, you would end up never capturing a sample of any initialization that happens within the first second, leading to misleading, skewed results. This can happen even with lower sample rates, especially if you have interval- or frame-based processes at a regular interval.
However, it’s possible to create a fair sample even with an extremely large sample rate by using an exponential probability distribution: https://en.wikipedia.org/wiki/Exponential_distribution. Each time you take a sample, instead of setting a timer for interval again, you generate a random variate (interval * -ln(Math.random()), I believe) and set a timer for that long. After n * interval has passed, you have still collected on average n samples, but they will have been sampled more fairly instead of at a regular, predictable, (and therefore biased) interval.
Can we consider adding an element to the spec that mandates that browsers use this method, either by default or as opt-in?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the js-self-profiling proposal and the discussion on this issue. Evaluate whether exponential sampling should be mandated or offered as an opt-in, and define done as an agreed specification change that addresses fair sampling at low rates.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100