[英]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.