New Uber Prof Feature: Too Many Database Calls In The Same Request
Join the DZone community and get the full member experience.Join For Free
recently, we added a way to track alerts across all the sessions the request. this alert will detect whenever you are making too many database calls in the same request.
but wait, don’t we already have that?
yes, we do, but that was limited to the scope of one session. there is a very large set of codebases where the usage of or/ms is… suboptimal (in other words, they could take the most advantage of the profiler abilities to detect issues and suggest solutions to them), but because of the way they are structured, they weren’t previously detected.
what is the difference between a session and a request?
note: i am using nhibernate terms here, but naturally this feature is shared among all profiler:
a session is the nhibernate session (or the data/object context in linq to sql / entity framework), and the request is the http request or the wcf operation. if you had code such as the following:
public t getentity<t>(int id)
using (var session = sessionfactory.opensession())
this code is bad, it micro manages the session, it uses too many connections to the database, it … well, you get the point. the problem is that code that uses this code:
public ienumerable<friends> getfriends(int friends)
var results = new list<friends>();
foreach(var id in friends)
the code above would look like the following in the profiler:
as you can see, each call is in a separate session, and previously, we wouldn’t have been able to detect that you have too many calls (because each call is a separate session).
now, however, we will alert the user with a too many database calls in the same request alerts.
Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.