Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jan A 63 posts 268 karma points
    Nov 20, 2017 @ 22:29
    Jan A
    0

    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.

    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.

    Here is the sql

    UPDATE [cmsPropertyData]
    SET    [contentNodeId] = 1605 /* @0 */,[versionId] = '851c55a5-b47b-43b0-a68c-d24d467e68a9' /* @1 */,[propertytypeid] = 117 /* @2 */,[dataInt] = NULL /* @3 */,[dataDecimal] = NULL /* @4 */,[dataDate] = NULL /* @5 */,[dataNvarchar] = NULL /* @6 */,[dataNtext] = NULL /* @7 */
    WHERE  [id] = 6406 /* @8 */
    

    This is the calls beeing made for each get of member

    SELECT [cmsContent].[pk],[cmsContent].[nodeId],[cmsContent].[contentType]
    FROM   [cmsContent]
    WHERE  nodeId = 1605 /* @0 */
    
    
    UPDATE [umbracoNode] SET [trashed] = 0 /* @0 */, [parentID] = -1 /* @1 */, [nodeUser] = 0 /* @2 */, [level] = 1 /* @3 */, [path] = -1,1605 /* @4 */, [sortOrder] = 2 /* @5 */, [uniqueID] = '4014dfe5-f145-44e9-b1c7-75189e39a837' /* @6 */, [text] = 'memberName' /* @7 */, [nodeObjectType] = '39eb0f98-b348-42a1-8662-e7eb18487560' /* @8 */, [createDate] = '2015-04-20 16:43:10.057' /* @9 */ WHERE [id] = 1605 /* @10 */
    
    
    SELECT [cmsContentVersion].[id],[cmsContentVersion].[ContentId],[cmsContentVersion].[VersionId],[cmsContentVersion].[VersionDate]
    FROM [cmsContentVersion]
    WHERE VersionId = '851c55a5-b47b-43b0-a68c-d24d467e68a9' /* @0 */
    
    
    UPDATE [cmsContentVersion]
    SET    [ContentId] = 1605 /* @0 */,[VersionId] = '851c55a5-b47b-43b0-a68c-d24d467e68a9' /* @1 */,[VersionDate] = 'Error parsing date' /* @2 */
    WHERE  [id] = 775 /* @3 */
    
    // This multiple time, 1 for each property i guess
    UPDATE [cmsPropertyData]
    SET [contentNodeId] = 1605 /* @0 */,[versionId] = '851c55a5-b47b-43b0-a68c-d24d467e68a9' /* @1 */,[propertytypeid] = 117 /* @2 */,[dataInt] = NULL /* @3 */,[dataDecimal] = NULL /* @4 */,[dataDate] = NULL /* @5 */,[dataNvarchar] = NULL /* @6 */,[dataNtext] = NULL /* @7 */
    WHERE [id] = 6406 /* @8 */
    
    // ending with
    UPDATE [cmsContentXml] SET [xml] = {XML GENERATED DATA}
    

    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

  • Charles R. Matvchuk 18 posts 124 karma points
    Nov 20, 2017 @ 23:28
    Charles R. Matvchuk
    0

    Why are you using Session? What type of session are you using: InProc, Custom, etc.?

  • Jan A 63 posts 268 karma points
    Nov 21, 2017 @ 07:04
    Jan A
    0

    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

  • Michele Di Maria 34 posts 239 karma points
    Nov 21, 2017 @ 00:43
    Michele Di Maria
    0

    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

  • Jan A 63 posts 268 karma points
    Nov 21, 2017 @ 07:08
    Jan A
    0

    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.

  • Jan A 63 posts 268 karma points
    Nov 21, 2017 @ 10:30
    Jan A
    100

    Update

    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

Please Sign in or register to post replies

Write your reply to:

Draft