I'm working on sharing session with an api (don't ask why), everything is working fine except when I do some load testing on it.
I have a single method that all it does is insert an object into session and return, this call is taking 200ms per call, I'm also running scale out host on my machine, but the time is the same for it deployed on server. If I switch to inproc session the time this takes become almost instant.
So I wrote, a second method that all it does is take the same object and inserts a 100 unique entries of it into session, the time this method takes is almost instant.
My question is, why is method 1 so much slower then inserting 100 unique objects into session?
I have a single method that all it does is insert an object into session and return, this call is taking 200ms per call, I'm also running scale out host on my machine, but the time is the same for it deployed on server. If I switch to inproc session the time this takes become almost instant.
So I wrote, a second method that all it does is take the same object and inserts a 100 unique entries of it into session, the time this method takes is almost instant.
My question is, why is method 1 so much slower then inserting 100 unique objects into session?
C#:
//Single insert takes 200ms on call, switching to inproc method takes 6ms (this is only the time of the network round trip)
[HttpPost]
public async Task<IHttpActionResult> Insert(InsertObjectRequest request)
{
HttpContext.Current.Session[request.Key] = request.Value;
return Ok();
}
//100 unique inserts is instant takes < 10ms
[HttpGet]
public IHttpActionResult LoadTest()
{
string value = "json object 42kb in size"
var writes = new System.Diagnostics.Stopwatch();
writes.Start();
for (int a = 0; a < 100; a++)
{
//INSERT
string sessionKey = Guid.NewGuid().ToString("N");
HttpContext.Current.Session[sessionKey] = value;
}
writes.Stop();
return Ok(writes.ElapsedMilliseconds);
}