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:

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.

Solution

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.