出于分析的目的,我需要分析向我的服务器发出的请求的数量,并且我正在使用Application。由于数据庞大,为了限制成本,我决定采用5%的固定率抽样。在做了一些测试之后,我得到了以下结果:
我预计抽样率为5%,但我的经验数据显示准确度很低。这种行为正常吗?这一切为什么要发生?我是否可以认为这些数据在请求量大的情况下具有代表性?
发布于 2022-08-30 19:13:02
应用程序中的抽样是使用随机方法完成的:
当新的span启动时,操作id是随机的,generated
5%并不意味着每收集20份文件。因此,在较小的数字上,您确实可以看到与配置的5%不同的差异。在更大的数字上,这应该越来越接近5% (与任何随机分布一样)。
这里有一个示例代码来说明它(这不是Application实现它的方法,这只是说明了基于随机抽样的工作方式):
static void Main(string[] args)
{
var random = new Random();
const int numRuns = 50;
const int numPerRun = 200;
int total = 0;
for (int j = 0; j < numRuns; j++)
{
int totalPerRun = 0;
for (int i = 0; i < numPerRun; i++)
{
var next = random.Next(100);
if (next < 5)
{
++totalPerRun;
++total;
}
}
Console.WriteLine($"Run #{j}: {totalPerRun} out of {numPerRun}");
}
Console.WriteLine($"Total: {total} out of {numRuns * numPerRun}");
}这是输出。注意,在10,000中,几乎有5%的。但就个人运行而言,这一比例远远超过了5%:
Run #0: 12 out of 200
Run #1: 6 out of 200
Run #2: 12 out of 200
Run #3: 7 out of 200
Run #4: 8 out of 200
Run #5: 8 out of 200
Run #6: 6 out of 200
Run #7: 12 out of 200
Run #8: 7 out of 200
Run #9: 11 out of 200
Run #10: 18 out of 200
Run #11: 11 out of 200
Run #12: 9 out of 200
Run #13: 11 out of 200
Run #14: 11 out of 200
Run #15: 10 out of 200
Run #16: 13 out of 200
Run #17: 7 out of 200
Run #18: 9 out of 200
Run #19: 15 out of 200
Run #20: 4 out of 200
Run #21: 6 out of 200
Run #22: 9 out of 200
Run #23: 8 out of 200
Run #24: 10 out of 200
Run #25: 10 out of 200
Run #26: 6 out of 200
Run #27: 13 out of 200
Run #28: 9 out of 200
Run #29: 5 out of 200
Run #30: 15 out of 200
Run #31: 9 out of 200
Run #32: 9 out of 200
Run #33: 12 out of 200
Run #34: 10 out of 200
Run #35: 8 out of 200
Run #36: 13 out of 200
Run #37: 8 out of 200
Run #38: 10 out of 200
Run #39: 9 out of 200
Run #40: 8 out of 200
Run #41: 6 out of 200
Run #42: 10 out of 200
Run #43: 11 out of 200
Run #44: 14 out of 200
Run #45: 10 out of 200
Run #46: 7 out of 200
Run #47: 13 out of 200
Run #48: 13 out of 200
Run #49: 9 out of 200
Total: 487 out of 10000https://stackoverflow.com/questions/73543766
复制相似问题