简体   繁体   English

使用Json上下文参数的Visual Studio加载CPU使用率激增

[英]Visual Studio Load CPU usage skyrockets with Json Context Parameters

I've used Visual Studio 2015 to record a WebPerformance test that is used by a Load Test. 我使用Visual Studio 2015记录了负载测试所使用的WebPerformance测试。 After the inital recording I could run 20 simultanious users with only about 25% CPU usage. 初始记录后,我可以仅以25%的CPU使用率运行20个同时用户。 However the website I'm testing on uses Json, so to make the tests more realistic I added a custom extraction rule for Json: 但是,我正在测试的网站使用Json,因此为了使测试更加现实,我为Json添加了自定义提取规则:

[DisplayName("JSON Extraction Rule")]
[Description("Extracts the specified JSON value from an object.")]
public class JsonExtractionRule : ExtractionRule
{
    [DisplayName("Name/path of attribute")]
    [Description("String to fetch the attribute from the Json Object.")]
    public string Name { get; set; }

    [DisplayName("Fetch 4 first characters only")]
    [Description("Set to true if only the first 4 characters of the attribute should be fetched.")]
    public Boolean fourFirstCharacters { get; set; }

    public override void Extract(object sender, ExtractionEventArgs e)
    {
        if (e.Response.BodyString != null)
        {
            var json = e.Response.BodyString;

            if (json.StartsWith("["))
            {
                json = "{\"array\":" + json + "}";
            }

            var data = JObject.Parse(json);

            if (data != null)
            {
                var attribute = data.SelectToken(Name).ToString();
                if (fourFirstCharacters)
                {
                    e.WebTest.Context.Add(this.ContextParameterName, attribute.Substring(0, 4));
                } else
                {
                    e.WebTest.Context.Add(this.ContextParameterName, attribute);
                }                   
                e.Success = true;
                return;
            }
        }

        e.Success = false;
        e.Message = String.Format(CultureInfo.CurrentCulture, "Not Found: {0}", Name);
    }
}

I used this to extract several Json attributes from the response and added them to subsequent requests using context parameters. 我用它从响应中提取了几个Json属性,并使用上下文参数将它们添加到后续请求中。

After adding several extractions likese and passing on some context parameters to the requests my Load Test reaches 100% CPU usage with only 5 simultanious users. 在添加了一些类似的提取并将一些上下文参数传递给请求之后,我的负载测试仅使用5个同时用户就达到了100%的CPU使用率。

The above extraction rule is used about 20 times in the WebPerformance test, and between 0-5 times on any single response. 在WebPerformance测试中,上述提取规则使用了大约20次,而在任何单个响应中,使用了0-5次。 The Json responses and requests are about 2k characters long. Json响应和请求的长度约为2k个字符。 The largest extraction consists of about 500 characters. 最大的提取包含大约500个字符。

I could understand if the response times went up or something like that as a result of more realistic Json being passed. 我能理解响应时间是否增加了,或者是由于更现实的Json通过了类似的结果。 However I do not understand why CPU usage skyrockets? 但是我不明白为什么CPU使用率飞速增长? Can the response time of the requests affect CPU usage from the Load Test? 请求的响应时间会影响负载测试的CPU使用率吗?

Is extractions + context parameters a bad(in context of CPU usage) way of implementing the Json in the requests? 提取+上下文参数是否是在请求中实现Json的一种不好的方式(在CPU使用情况下)? Is there a smarter way to do this that would save CPU usage? 有没有更聪明的方法可以节省CPU使用率?

The majority of the CPU usage seems to have been caused by using the above custom Json extraction in a validation rule. CPU使用率的大部分似乎是由于在验证规则中使用上述自定义Json提取引起的。 I removed it since the validation wasn't critical and everything ran more smoothly. 我删除了它,因为验证不是很关键,并且一切运行都更加顺利。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual Studio 2015使用节点100%的CPU使用率 - Visual Studio 2015 100-percent CPU usage with Node Visual Studio 2022 - 内置分析器中的 CPU 使用率超过 100% - Visual Studio 2022 - CPU usage over 100% in built-in profiler Visual Studio 2022 CPU 使用率在准备数据步骤时冻结 - Visual Studio 2022 CPU Usage frozen at preparing data step 如何使用Visual Studio加载JSON类架构 - How to load JSON Class Schema with Visual Studio 在调试模式下运行Visual Studio控制台应用程序的CPU使用率不会超过50% - Running Visual Studio console application in debug mode consumes no more than 50 percent cpu usage 附加Visual Studio调试器会导致较高的CPU使用率和UI线程锁定 - Attaching Visual Studio debugger causes high CPU usage and UI thread locks 当我通过 Visual Studio 调试器检查 CPU 使用情况时,看到的外部和本机功能是什么? - what are the external and native functions seen when i check cpu usage by visual studio debugger? Visual Studio中的上下文帮助 - Context help in Visual Studio 使用 NanoFramework 和 Visual Studio 分析 CPU? - Profiling CPU with NanoFramework and Visual Studio? Visual Studio Performance Profiling.Net Core 控制台应用程序通过对 nvlddmkm.sys 的“unwalkable”调用显示大量 CPU 使用率 - Visual Studio Performance Profiling .Net Core console application shows significant CPU usage by "unwalkable" calls into nvlddmkm.sys
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM