I know that we can call R functionalities by Rscript or rdotnet in .Net. There are some nice explanations here, here and here.
My question is:
How can we have multiple concurrent R calls in .Net?
I did the following test and found out that it is not possible to have them concurrent. It works sequentially. Any idea about how I can have them concurrent? Shall I switch to Shiny or Microsoft R server?
string result=null; string filename = null;string args = null;
int pp ;
try
{
for (pp = 0; pp <= 20; pp++)
{
filename = uid+pp.ToString() + "." + DropDownList1.SelectedItem.Text + "." + DropDownList2.SelectedItem.Text + dt + "." + DateTime.Now.Millisecond;
args = filename + " " + DropDownList1.SelectedItem.Text + " " + DropDownList2.SelectedItem.Text;
result = RScriptRunner.RunFromCmd(path + @"\rcode.r", @"D:\Programms\R-3.3.3\bin" + @"\rscript.exe", args);
}
}
catch (Exception ex)
{
}
As suggested,
I changed it to
try
{
Parallel.For(0, 20, (int pp) =>
{
filename = uid + pp.ToString() + "." + DropDownList1.SelectedItem.Text + "." + DropDownList2.SelectedItem.Text + dt + "." + DateTime.Now.Millisecond;
args = filename + " " + DropDownList1.SelectedItem.Text + " " + DropDownList2.SelectedItem.Text;
result = resultFunction(path, pp, args);
});
}
catch (Exception ex)
{
}
and it worked perfectly, all the expected outputs appeared almost instantly.
My concern is:
I intentionally forced the app to run in parallel. Shall I expect the same behavior in a web application with multiple online users (sessions)?