我們試圖並行觸發兩條命令來嘗試加速數據返回,但看起來進程正在排隊。單獨運行流程的累積時間量等於同時運行它們。直到第一個數據集才被返回。Azure上的並行處理
請問誰能告訴我這種情況?
謝謝,
我會附上一個例子。
Thread GetResult1Thread = new Thread(new ThreadStart(GetResult1));
GetResult1Thread.IsBackground = true;
GetResult1Thread.Start();
Thread GetResult2Thread = new Thread(new ThreadStart(GetResult2));
GetResult2Thread.IsBackground = true;
GetResult2Thread.Start();
}
public void GetResult1()
{
//Blocks time untill database request is complete
//Total Execution time 1 min
DataSet ds = db.getSPDataSet("getCBRWeeklyPercentageBody", "@JobID",JobID,
"@StartDate", StartDate, "@ResourcingGradeIDs",
ResourceID, "@StaffIds", StaffIds);
}
}
public void GetResult2()
{
//Thread pending do to Result1 is not released from database
//1 min delayed response
DataSet ds = db.getSPDataSet("getCBRWeeklyPercentageHeader",
"@JobID", JobID, "@StartDate", StartDate,
"@ResourcingGradeIDs", ResourceID, "@StaffIds", StaffIds);
}
And the JS------------------------------------------
//Request 1
$.ajax({
url: "api/SaveDefaultSettings",
data: {
},
type: "POST",
cache: false,
async: true
success: function (data) {
//Default save result
//Get Active Activity List
ResourceHours = [];
GetDefaultData();
selectedRows = SaveData;
ResourceHours = data;
var spl = StartDate.split("-")
if (spl[1].length == 1) {
spl[1] = "0" + spl[1];
}
StartDate = spl[2] + "/" + spl[1] + "/" + spl[0];
},
error: function (xhr, ajaxOptions, thrownError) {
}
});
//Request 2
$.ajax({
url: "api/GetResources",
data: { JobID: JobID, StartDate: StartDate },
type: "POST",
cache: false,
async: true
success: function (data) {
// CallProgressDialog("Processing", "Please wait while data is loading.");
Resources = [];
Resources = data;
Populate();
$(".QuantimDialog_Button0").click();
},
error: function (xhr, ajaxOptions, thrownError) {
}
});
感謝您的回覆然而,似乎沒有用的使用異步。數據庫沒有返回第二個SP的結果。因爲第一個SP執行並鎖定數據庫。因此,下一個線程/異步嘗試要執行,但不會執行,因爲它被第一個SP阻止,必須等待它完成。你可以用另一種方式幫助嗎?謝謝。 – Anthony
如果是這種情況,那麼您可能需要更高級的數據庫級鎖定方案。有關信息,請參閱以下內容:http://fryerblog.com/post/11358861869/multi-threading-with-tsql –