I tried to figure out some performance values of two scenarios. I thought that at first I would declare myself. But when I got the results, I was a little embarrassed. And now I'm looking for an excuse for the cause.
I have a library that makes a couple of queries through the MongoDb database and Active Directory, and then returns the results to the client, which:
- GetUserType - to MongoDb - there is a collection that has username and type fields in all its documents. In the request, I give the username and request the type field.
- LoginCheck - in Active Directory - taking into account the user name and password from the client, I create an object
PrincipalContextto access the AD server and call ValidateCredentialson it.
This task is currently being performed in an existing MVC application. And we are going to create a new desktop application and use it with the same work.
We were curious how different these two scenarios could be. We thought that a direct call to the library without any http connection would work better than a service request without hesitation. But we still wondered what the difference was, and if that were acceptable, we are going to get it to work through the rest of the MVC service - due to reasons :)
Therefore, we tested the following architectures:
Scenario 1:

Scenario 2:

Basically what I do for a performance test:
For scenario 1:
for(var i = 0; i<10000; i++)
{
new Class1().HeavyMethod();
}
For scenario 2:
for(var i = 0; i<10000; i++)
{
using ( var client = new HttpClient() )
{
var values = new Dictionary<string, string>();
var content = new FormUrlEncodedContent(values);
var response = client.PostAsync("http://localhost:654/Home/HeavyLift", content).Result;
var responseString = response.Content.ReadAsStringAsync().Result;
}
}
public class HomeController : Controller
{
public JsonResult HeavyLift()
{
return Json(new Class1().HeavyMethod(), JsonRequestBehavior.AllowGet);
}
}
General class:
public class Class1
{
public string HeavyMethod ()
{
var userName = "asdfasdfasd";
var password = "asdfasdfasdf";
try
{
var userType = Personnel.GetPersonnelsType(userName).Result;
var user = new ADUser(new Session
{
UserType = userType.Type,
UserName = userName,
Password = password
});
return userType.Type + "-" + user.Auth();
}
catch ( Exception e )
{
return e.Message;
}
}
}
The results for 10,000 consecutive calls are confusing:
Scenario 1: 159181 ms
Scenario 2: 13952 ms
Scenario 1 , .
Scenario 2 10k.
?
.. , ( ), , .