I have a pretty basic MVC project in C#. It's views use only ajax calls to call the one controller I have with eather GET
or POST
methods. This project uses Entity framework to let the user login and use the controller's actions (check credentials for every action called).
When I finaly started testing the web application for multiple users the web app just stopped responding. Like everyone's requests were in queue and the only guy at the counter said: 'im on a break', and that made every request wait without calling it quits. I tested by calling the Test
function of my controller from multiple browsers that had a user logged in every 5-10 seconds.
The Test
function just called one of the other functions in that controller, executed it, and didn't return anything, as it would be the case with actions that it called (that user normaly calls).
I also made the ajax test calling code record the ID and time of each call when it was started and ended. Here I noticed an anomaly. It looked like this:
START 1
END 1
START 2
END 2
START 3
START 4
END 4
START 5
END 5
START 6
... //which eventualy brings us to
START 20
START 21
START 22
START 23
START 24
... // without any of these requests being resolved
And I've never heared the END
of call No3.
I've read online that the MVC's querying every request, and I think that this is most likely the cause for the web application to stop responding.
I tried using [SessionState(SessionStateBehavior.Disabled)]
as described here with same results.
Many clients will be using this web application at the same time, and this is an unacceptable behavior. One of the ways to "solve" this is to create a script that would allow every user to make only 1 ajax call at a time. But what when 50 users make an ajax call at the same time? (I can't test for that, but I beleave that it would do the same. I managed to test for 5 since I have 5 browsers).
Why is the web application not responding after often ajax calls? Why is (as in example above) call No4 more important than call No3? This isn't a FIFO stack! It's a whole web application. How do I allow users to call and get anything from my controller without the web app crashing on me?
Here is the code I use to call the Test
action from controller:
// TESTING
var testCallCount = 0, testSuccessCount = 0, testFailCount = 0;
function StartTesting(caller) {
$(caller).prop('disabled', true); // disables the button that's used to start the testing process
var interval = 3 //RandomNumber(5, 10)
* 1000;
setInterval(function () {
testCallCount++;
var now = new Date
console.log('CALLED-' + testCallCount + ' ' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds());
var current = testCallCount;
$.ajax({
type: 'GET',
url: '../Documents/Test',
success: function () { testSuccessCount++; },
error: function () { testFailCount++; },
complete: function () { var text = TestCounts(testCallCount); console.log(text); }
});
}, interval);
}
function TestCounts(callNo) {
var now = new Date();
var text =
"END-" + callNo + ' ' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds() +
"\nT:" + testCallCount +
" S:" + testSuccessCount +
" F:" + testFailCount
;
return text;
}
Also, all my ajax calls are in this form (whitout the call's time and ID part). And this is the Test
function:
[HttpGet]
public void Test()
{
var randNo = new Random().Next(0, 10);
var testCatNo = 6;
var testDocNo = 3856;
switch (randNo)
{
case 0: UniversalForm(UniversalFormType.Category, testCatNo, null); break;
case 1: NavTree(); break;
case 2: SearchDatabase(SearchResultsType.Category, testCatNo, 0, null); break;
case 3: FullTextSearch(0, "asd", true, true); break;
case 4: ItemData(SearchDetailsType.Document, testDocNo); break;
//case 5: CreateItem(EditType.Document, testCatNo, new List<UFParameter>()); break;
case 6: SearchPermRequests(testCatNo, 0); break;
case 7: ShowMyPermRequests(0); break;
case 8: CheckMyAllowedPermRequests(); break;
//case 9: Preview(testDocNo); break;
}
}
NOTE I forgot to say that the web app works just fine when I'm using it on my own for testing controller methods (this means I don't make more than like 3 concurrent ajax requests at the time). Also, every action takes about 4 seconds on average to execute. With proper parameters, all the actions that Test
action calls work fine, so I hardcoded the proper values to enshure that the Test
action always returns with no errors.