62,254
社区成员
发帖
与我相关
我的任务
分享
$(function () {
//控件初始化完成后
bindA();
bindB();
bindC();
})
function bindA() {
$.ajax({
type: 'post',
async: true,
url: 'Home/GetDateA',
dataType: 'json',
success: function (result) {
},
error: function () {
}
});
}
function bindB() {
$.ajax({
type: 'post',
async: true,
url: 'Home/GetDateB',
dataType: 'json',
success: function (result) {
},
error: function () {
}
});
}
function bindC() {
$.ajax({
type: 'post',
async: true,
url: 'Home/GetDateC',
dataType: 'json',
success: function (result) {
},
error: function () {
}
});
}
public async Task<IActionResult> GetDateA()
{
var dateA= await _service.GetDateA();
log.Error("线程:" + Thread.CurrentThread.ManagedThreadId + ";名称:GetDateA");
return Json(dateA);
}
public async Task<IActionResult> GetDateB()
{
var dateB= await _service.GetDateB();
log.Error("线程:" + Thread.CurrentThread.ManagedThreadId + ";名称:GetDateB");
return Json(dateB);
}
public async Task<IActionResult> GetDateC()
{
var dateC= await _service.GetDateC();
log.Error("线程:" + Thread.CurrentThread.ManagedThreadId + ";名称:GetDateC");
return Json(dateC);
}

$(function () {
//控件初始化完成后
bindA();
bindB();
bindC();
})
function bindA() {
console.time(1);
$.ajax({
type: 'post',
async: true,
url: 'Home/GetDateA',
dataType: 'json',
success: function (result) {
console.timeEnd(1);
},
error: function () {
}
});
}
function bindB() {
console.time(2);
$.ajax({
type: 'post',
async: true,
url: 'Home/GetDateB',
dataType: 'json',
success: function (result) {
console.time(2);
},
error: function () {
}
});
}
function bindC() {
console.time(3);
$.ajax({
type: 'post',
async: true,
url: 'Home/GetDateC',
dataType: 'json',
success: function (result) {
},
error: function () {
console.time(3);
}
});
}
1: 4342.380126953125ms
2: 3698.45703125ms
3: 2882.753173828125ms
如果把
bindB();
bindC();
暂时屏蔽掉,单个
bindA的时间为
701.97021484375ms
\
public async Task<IActionResult> GetDateA()
{
Stopwatch timer = new Stopwatch();
timer.Start();
var dateA= await _service.GetDateA();
timer.Stop();
JsonResult json = Json(dateA);
log.Error("线程:" + Thread.CurrentThread.ManagedThreadId + ";名称:GetDateA;时间:"+ timer.Elapsed);
return json ;
}
同时三个请求,日志
线程:9;名称:GetDateA;时间:00:00:00.3336152
线程:23;名称:GetDateA;时间:00:00:00.2841588
线程:10;名称:GetDateA;时间:00:00:00.4298977
那这么看,每个返回时间也不超过1S
Application Insights显示的每个post请求相应时间为1.5-2s左右
这个应该是前端发起请求,到后台返回数据的时间,那么,这些时间应该是阻塞在了,前端和后台之间
我在看一下,在前端做下计时[/quote]
日志应该是
线程:9;名称:GetDateA;时间:00:00:00.3336152
线程:23;名称:GetDateB;时间:00:00:00.2841588
线程:10;名称:GetDateC;时间:00:00:00.4298977\
public async Task<IActionResult> GetDateA()
{
Stopwatch timer = new Stopwatch();
timer.Start();
var dateA= await _service.GetDateA();
timer.Stop();
JsonResult json = Json(dateA);
log.Error("线程:" + Thread.CurrentThread.ManagedThreadId + ";名称:GetDateA;时间:"+ timer.Elapsed);
return json ;
}
同时三个请求,日志
线程:9;名称:GetDateA;时间:00:00:00.3336152
线程:23;名称:GetDateA;时间:00:00:00.2841588
线程:10;名称:GetDateA;时间:00:00:00.4298977
那这么看,每个返回时间也不超过1S
Application Insights显示的每个post请求相应时间为1.5-2s左右
这个应该是前端发起请求,到后台返回数据的时间,那么,这些时间应该是阻塞在了,前端和后台之间
我在看一下,在前端做下计时