0

we are having some issues with nhibernate in an MVC asp.net web app, One of our first theories was that since session is not thread safe, that might be causing our issue.

we are using structure map, and our session wrapper is instantiated as a "hybrid" which is supposed to solve threading issues by having 1 session per request.

to test this theory, we put a static object lockObject in our session wrapper, and then put locks around any call that modifies (but not retrieves) anything on the session object.

But I'm uncertain as the effect this will have under high load. What we want is no non synchronous access to a give instance of session, will it instead synchronize across all instances, even if memory is not shared?

Is there a better way to achieve our goals?

Thanks

Eric Brown - Cal
  • 14,135
  • 12
  • 58
  • 97
  • Your question is not clear. Having a session per request should be enough to ensure thread safety, since 1 request roughly equals 1 thread. As long as you aren't doing some kind of odd multi-threading type operations that utilize your session within the context of a single request, you should be fine. – Chris Pratt Dec 21 '15 at 18:36
  • That's what I thought, but we added the locks to cover the "we don't know" end of things.. I am wondering it there will be side effects because it's static.. specifically across all the iis requests. – Eric Brown - Cal Dec 21 '15 at 22:03
  • That's my point, the uncertainty is created by adding something that is unnecessary because you don't trust that things should work as they should. Test without the locks, and worry about it when it actually becomes a problem. – Chris Pratt Dec 22 '15 at 13:36

0 Answers0