MongoDB server performance issues when using MongoDB session providers, if a required index is missing

  • Description

    The MongoDB server can be heavily loaded when using the MongoDB providers for both private and shared session states, if a collection is missing a required index.

    For example, when the private and shared session state providers are configured as in the following:

    • In the \App_Config\ConnectionStrings.config file:
      <connectionStrings>
      ...  
        <add name="private.sessions" connectionString="mongodb://{user-name}:{password}@{host}/sitecore_private_sessions" />
        <add name="shared.sessions" connectionString="mongodb://{user-name}:{password}@{host}/sitecore_shared_sessions" />
      ...
      </connectionStrings>
    • In the Web.config file:
      <sessionState mode="Custom" customProvider="mongo" ... >
        <providers>
        ...
         <add name="mongo"
           type="Sitecore.SessionProvider.MongoDB.MongoSessionStateProvider, Sitecore.SessionProvider.MongoDB"
              sessionType="Private"
              connectionStringName="private.sessions"
              pollingInterval="5"
              compression="true" />
        ...
        </providers>
      </sessionState>
    • In the \App_Config\Include\Sitecore.Analytics.Tracking.config file:
      <sharedSessionState defaultProvider="mongo">
        <providers>
        ...
          <add name="mongo"
         type="Sitecore.SessionProvider.MongoDB.MongoSessionStateProvider, Sitecore.SessionProvider.MongoDB"
               sessionType="Shared"
               connectionStringName="shared.sessions"
      pollingInterval="5"
               compression="true" />
        ...
        </providers>
      ...
      </sharedSessionState>

    Sitecore XP creates two instances of the Sitecore.SessionProvider.MongoDB.MongoSessionStateProvider class, but only the first one will initialize the sessions collection in MongoDB with the e_1__id.s_1__id.a_1 index. As a result, querying the private session state database uses the index, and querying the shared session state database uses a full collection scan.

  • To resolve this issue:

    1. Connect to the MongoDB server using a GUI tool, for example Robomongo.
    2. Open the shared.sessions database and navigate to the \Collections\sessions\Indexes node.
    3. Right-click on the Indexes node and then click the Add Index... command.
    4. In the Index Properties dialog, fill in the Name and Keys fields using the following values:
      • Name: e_1__id.s_1__id.a_1
      • Keys: { "e" : 1, "_id.s" : 1, "_id.a" : 1 }
    5. In the Index Properties dialog, click Save.

Applies to:

CMS 7.5+

March 24, 2017
March 29, 2017

Reference number:

114604

Keywords: 

  • CMS,
  • Performance,
  • xDB