首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >定速率采样在应用中的应用--精度不高

定速率采样在应用中的应用--精度不高
EN

Stack Overflow用户
提问于 2022-08-30 14:01:56
回答 1查看 112关注 0票数 0

出于分析的目的,我需要分析向我的服务器发出的请求的数量,并且我正在使用Application。由于数据庞大,为了限制成本,我决定采用5%的固定率抽样。在做了一些测试之后,我得到了以下结果:

  • 800真实请求-> 32例(4%)
  • 200实际请求-> 14例(7%)

我预计抽样率为5%,但我的经验数据显示准确度很低。这种行为正常吗?这一切为什么要发生?我是否可以认为这些数据在请求量大的情况下具有代表性?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-30 19:13:02

应用程序中的抽样是使用随机方法完成的:

当新的span启动时,操作id是随机的,generated

  • Operation id被散列并转换为0.1范围的

  • ,如果这个数字小于或等于配置的采样率,则在遥测中采样,否则丢弃

5%并不意味着每收集20份文件。因此,在较小的数字上,您确实可以看到与配置的5%不同的差异。在更大的数字上,这应该越来越接近5% (与任何随机分布一样)。

这里有一个示例代码来说明它(这不是Application实现它的方法,这只是说明了基于随机抽样的工作方式):

代码语言:javascript
复制
    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%:

代码语言:javascript
复制
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 10000
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73543766

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档