1

We're trying to fire off two commands in parallel to try and speed up the return of data but it looks like the processes are just being queued. The amount of cumulative time to run the processes individually is equal to running them both at the same time. And the second data set is not returned until the first has.

Can anyone shed some light on the situation please?

Thanks,

I'll attach an example.

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) {
  }
  });
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Anthony
  • 13
  • 2

2 Answers2

1

For the test purpose can you please create a simpler case? At least cutting DB dependency would eliminate the need to establish DB connection and execute SP which might have some locking inside.

Also note that browsers have a limit of concurrent connections (How many concurrent AJAX (XmlHttpRequest) requests are allowed in popular browsers?) as well as .NET application(https://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.defaultconnectionlimit(v=vs.110).aspx) and the server itself (Max Outgoing Socket Connections in .NET/Windows Server)

So less variables in the test - the more likely will be to narrow down the bottleneck

Community
  • 1
  • 1
Galin Iliev
  • 167
  • 5
0

That is kind of an old school way of doing parallel processing. Now you can just use the Async stuff built into .Net. Just start two tasks and do an WhenAll on them.

Paul Fryer
  • 9,268
  • 14
  • 61
  • 93
  • Thanks for your reply however It seems there is no use using Async. The database is not returning the result of 2nd SP. Because the 1st SP executes and it locks the database. So the next Thread/Async try's to execute but it won't execute because it is blocked by first SP and has to wait for it to finish. Can you help with another way around it please? Thanks. – Anthony Jun 23 '15 at 10:07
  • If that's the case then you may need a more advanced database level locking scheme. See this for info: http://fryerblog.com/post/11358861869/multi-threading-with-tsql – Paul Fryer Jun 23 '15 at 14:45