Daniel Ovaska
Aug 10, 2009
  7659
(1 votes)

Xforms performance

Introduction

The main issue is that the XFormSelect.aspx does a lot of database calls to load each xform. You can check the bug #25759: EPiServer.UI.Edit.XFormSelect.LoadForms calls GetxFormUsedonPages twice per xform on each request.

The problem is that GetxFormUsedonPages results in a call to the FindPagesByCriteria method. If you haven’t been warned about using that method extensively, you should have been. So the bottom line is that if you have 200 xforms this will result in 2*200=400 FindPagesByCriteria calls every time the popup is opened / paged / filtered which hammers the database badly and can result in deadlocks. Response time at worst for me was around 120 seconds which causes a timeout error.

Solution

Warning: This solution modifies some files in the episerver UI folder. This will have to be redone after upgrading episerver. If possible, wait until episerver implements some similar solution. I did not have that option with a lot of angry editors on my back. If you do not have the privilege of time, feel free to use my workaround.

  1. Locate and backup the modified UI files (XFormSelect.aspx, XFormSelect.ascx, XFormEdit.aspx)
    These are usually found at C:\Program\EPiServer\CMS\5.2.375.133\Application\UI\Edit when doing a standard install.
  2. Replace the files above with the
  3. Add some logging, change namespaces etc to fit your needs.
  4. Add these files and their code behind files (.cs) to your solution. 
  5. Add the XFormManager.cs to your solution.
  6. Open your Global.asax and add the following lines:
    a)  If you haven't added some page events. Do it…
    protected void Application_Start(Object sender, EventArgs e)
    {
        EPiServer.DataFactory.Instance.CreatedPage += 
    new PageEventHandler(onCreatedPage); EPiServer.DataFactory.Instance.DeletedPage +=
    new PageEventHandler(onDeletedPage); EPiServer.DataFactory.Instance.SavedPage +=
    new EPiServer.PageEventHandler(OnSavedPage); }
    b) Add event handlers if you don’t have any. 
    private void onDeletedPage(object sender, PageEventArgs e)
    {
       PageData deletedPage = 
    EPiServer.DataFactory.Instance.GetPage(e.PageLink); InvalidateXFormCache(deletedPage); } private void OnSavedPage(object sender, EPiServer.PageEventArgs e) { PageData updatedPage =
    EPiServer.DataFactory.Instance.GetPage(e.PageLink); InvalidateXFormCache(updatedPage); } private void onCreatedPage(object sender, PageEventArgs e) { PageData createdPage =
    EPiServer.DataFactory.Instance.GetPage(e.PageLink); InvalidateXFormCache(createdPage); }
  7. c) Add private helper function to invalidate xforms cache for that page.
    private void InvalidateXFormCache(PageData page)
    {
       try
       {
           foreach (PropertyData prop in page.Property)
           {
              if (prop.Name == "XForm")
              {
                 if (prop.Value != null)
                 {
                      string formid = prop.Value.ToString();
                      if (!string.IsNullOrEmpty(formid))
                      {
                         string cacheKey = "xFormUsedonPages" + formid;
                         HttpContext.Current.Cache.Remove(cacheKey);
                      }
                 }
               }
             }
         }
         catch (Exception ex)
         {
             //Do some logging with log4net for example
         }
    }
  8. Build and try it out and add a comment on this blog

Summary

To solve the bad performance with xforms selection and the deadlocks in the database this can cause I added caching in a helper class (XFormsManager) and redirected the calls from XFormSelect.ascx and XFormEdit.aspx to use this class instead. This reduced the response time from 120 seconds to a few ms. As the XFormSelect page also displays which pages use which form, I added eventhandlers to Global.asax to ensure that these text were updated.

Aug 10, 2009

Comments

Sep 21, 2010 10:32 AM

Nice work
/ Anders Hattestad

Magnus Rahl
Magnus Rahl Sep 21, 2010 10:32 AM

Question: You tagged this with CMS 5 R2 SP1, is that correct? A customer seems to have encountered this problem when upgrading to SP2, it was fine in SP1.

Sep 21, 2010 10:32 AM

Magnus: Yes that is correct. This problem was noticed when upgrading from 5.1 SP2 to 5 R2 SP1. If you should happen to find a true fix to the database issue rather then curing the symphoms with caching, feel free to let me know about it :)
/ Daniel

Sep 21, 2010 10:32 AM

I get an error when I try to edit a form and choose the "edit and save" button. If I edit and just save it works.

Jun 18, 2015 08:52 AM

The bad performance I talk about in this case with Xforms has been fixed with EPiServer 6 and is no longer an issue. 

Please login to comment.
Latest blogs
Opti ID overview

Opti ID allows you to log in once and switch between Optimizely products using Okta, Entra ID, or a local account. You can also manage all your use...

K Khan | Jul 26, 2024

Getting Started with Optimizely SaaS using Next.js Starter App - Extend a component - Part 3

This is the final part of our Optimizely SaaS CMS proof-of-concept (POC) blog series. In this post, we'll dive into extending a component within th...

Raghavendra Murthy | Jul 23, 2024 | Syndicated blog

Optimizely Graph – Faceting with Geta Categories

Overview As Optimizely Graph (and Content Cloud SaaS) makes its global debut, it is known that there are going to be some bugs and quirks. One of t...

Eric Markson | Jul 22, 2024 | Syndicated blog

Integration Bynder (DAM) with Optimizely

Bynder is a comprehensive digital asset management (DAM) platform that enables businesses to efficiently manage, store, organize, and share their...

Sanjay Kumar | Jul 22, 2024

Frontend Hosting for SaaS CMS Solutions

Introduction Now that CMS SaaS Core has gone into general availability, it is a good time to start discussing where to host the head. SaaS Core is...

Minesh Shah (Netcel) | Jul 20, 2024

Optimizely London Dev Meetup 11th July 2024

On 11th July 2024 in London Niteco and Netcel along with Optimizely ran the London Developer meetup. There was an great agenda of talks that we put...

Scott Reed | Jul 19, 2024