I have big performance issues. When we get about 5-700 requests my sql server peak at 100% constantly. I figured out that it's my code, partly stored in a surface controller that's causing this.
The site is a site where the user log on so the member is loaded at many different parts of the page.
What I found is that it seems like it's when I get the member, It does all this updates after. I get the member data and read some properties. But I dont update it. I have the member data in both the controller, and also in the razor templates. Also I check some in an partial template.
I have a helper function for this.
public static IMember GetCurrentMember()
{
var user = System.Web.Security.Membership.GetUser();
if (user == null || user.UserName == "")
return null;
var member = HttpContext.Current.Session["memberSessionKey"] as IMember;
if (member == null)
{
member = ApplicationContext.Current.Services.MemberService.GetByUsername(user.UserName);
HttpContext.Current.Session["memberSessionKey"] = member;
}
return member;
}
The session part is me trying to fix all the loading but without success.
Before it was only
var member = ApplicationContext.Current.Services.MemberService.GetByUsername(user.UserName);
I get about 80-90 request regarding getting the member and then updates like these. I figure that I load the member "wrong" so the context belive there is an update, and post it. But I can't figure out why.
I would check if the session cookie is saved on the browser and send for each request... maybe something is broken on that and the current member is not saved in the context. Just an idea.
I found what causing the updates, or at least how to fix it.
If I change the following line
var user = System.Web.Security.Membership.GetUser();
to
MembershipHelper memHelper = new MembershipHelper(Umbraco.Web.UmbracoContext.Current);
It only does the select, and don't update the post.
In the future I would consider to change the handling of IMember to use MemberHelper and the IPublishedContent I get from membershipHelper.GetCurrentMember instead. But for now, I go with the following
public static IMember GetCurrentMember()
{
MembershipHelper memHelper = new MembershipHelper(Umbraco.Web.UmbracoContext.Current);
string username = memHelper.CurrentUserName;
if (string.IsNullOrEmpty(username))
return null;
var member = ApplicationContext.Current.Services.MemberService.GetByUsername(username);
return member;
}
This will still query the database each time and don't cache, but at least I will not get the multiple updates
Many update request on cmsPropertyData
I have big performance issues. When we get about 5-700 requests my sql server peak at 100% constantly. I figured out that it's my code, partly stored in a surface controller that's causing this.
The site is a site where the user log on so the member is loaded at many different parts of the page.
What I found is that it seems like it's when I get the member, It does all this updates after. I get the member data and read some properties. But I dont update it. I have the member data in both the controller, and also in the razor templates. Also I check some in an partial template.
I have a helper function for this.
The session part is me trying to fix all the loading but without success.
Before it was only
I get about 80-90 request regarding getting the member and then updates like these. I figure that I load the member "wrong" so the context belive there is an update, and post it. But I can't figure out why.
Here is the sql
This is the calls beeing made for each get of member
Of all sql queries I get this:
update cmspropertydata uses 21% of all sql time, called 1,753,972 times
select cmsmember uses 21% of all sql time, called 169,406 times
select cmsdatatypeprevalues uses 21% of all sql time, called 159,820 times
select cmspropertydata, cmspropertytype, cmsmember uses 20% of sql time, called 159,820 times
This is in about 1 hour(!)
Please help me find what I'm doing wrong
Why are you using Session? What type of session are you using: InProc, Custom, etc.?
I was trying to use session to see if I could avoid all the loads. But since it makes the same calls I figure it dosn't matter what I use.
So it was only for testing
I would check if the session cookie is saved on the browser and send for each request... maybe something is broken on that and the current member is not saved in the context. Just an idea.
Michele
When I debug at local I see the session beeing stored and read as I would expect. But even the local debug does all the calls.
Is there something I missed, like Umbraco update the member to set something on request level, like update "last seen" or something.
Update
I found what causing the updates, or at least how to fix it.
If I change the following line
to
It only does the select, and don't update the post. In the future I would consider to change the handling of IMember to use MemberHelper and the IPublishedContent I get from membershipHelper.GetCurrentMember instead. But for now, I go with the following
This will still query the database each time and don't cache, but at least I will not get the multiple updates
is working on a reply...