Quantcast
Channel: Brian Pedersen's Sitecore and .NET Blog
Viewing all articles
Browse latest Browse all 286

Sitecore Memory Issues – Every memory optimization trick in the book

$
0
0

My recent post, Sitecore high memory usage – not always a problem, claims that high memory usage is not the same as having a memory problem in Sitecore. But the reason you are reading this blog is because the memory have become a problem – right? So let’s see what you can do about it.

I will not go into the real issue, which probably is that your own application code have a memory leak. This not Sitecore’s fault, although we would like it to be. Instead I will show you the Sitecore settings that will limit the memory consumption of the Sitecore platform itself.

TRICK 1: YOUR EVENT QUEUE IS RUNNING HIGH

This is the #1 issue: Too many events in the event queue. First you need to clean the event queue. Read how to clean the event queue here.

Next you need to manage the event queue size. Use the CleanupEventQueue agent and tune the cleanup so you have no more than 7000 items in the queue at any time:

<agent type="Sitecore.Tasks.CleanupEventQueue, Sitecore.Kernel" method="Run" interval="04:00:00">
  <IntervalToKeep>04:00:00</IntervalToKeep>
  <DaysToKeep>1</DaysToKeep>
</agent>

TRICK 2: DON’T LET THE SITECORE CACHE RUN WILD

Use the Caching.DisableCacheSizeLimits to enforce the cache limits you have painfully configured through the application:

<setting name="Caching.DisableCacheSizeLimits" value="false" />

Also use one of the many Sitecore Cache Tuning Guides online. Even old blog posts will still be useful, as the cache is part of Sitecore basics and have not changed much.

TRICK 3: YOU HAVE TOO MANY UNUSED VERSIONS OF YOUR ITEMS

Items with many versions will eat your memory every time you open the item in the Sitecore Shell. If possible, delete the old versions. Click here to see how to delete old Sitecore item versions.

TRICK 4: DISABLE EXM

Are you using EXM? No? Then disable EXM:

<setting name="EXM.Enabled" value="false" />

TRICK 6: DO NOT CACHE ITEMS WHEN PUBLISHING

You can disable the Publishing database cache. Then the items being published will not be added to the Sitecore database cache.

<setting name="Publishing.DisableDatabaseCaches" value="true"/>

TRICK 7: LOWER THE BATCH SIZE WHEN INDEXING

The Sitecore SOLR indexing can eat your memory. Lowering the batch size have a positive effect on the amount of memory being used when an item is indexed:

<setting name="ContentSearch.IndexUpdate.BatchSize" value="150" />

TRICK 8: DO NOT CACHE WHEN INDEXING

You can disable the index caching. Then the items being retrieved during an index is not cached:

<setting name="ContentSearch.Indexing.DisableDatabaseCaches" value="true" />

TRICK 9: UTILIZE INTERNING

.NET introduced a string object pool pattern that allows you to reference strings that are duplicated. Strings cannot be changed once created (also called “immutable objects”), and can therefore be referenced using interning. Sitecore have implemented interning on fields, but you have to define which fields should be interned. Legend says that there is a performance penalty when interning, but I have not been able to measure any performance decrease.

<interning>
  <fieldIdsToIntern>
    <workflowState>{3E431DE1-525E-47A3-B6B0-1CCBEC3A8C98}</workflowState>
    <workflow>{A4F985D9-98B3-4B52-AAAF-4344F6E747C6}</workflow>
    <updatedBy>{BADD9CF9-53E0-4D0C-BCC0-2D784C282F6A}</updatedBy>
    <createdBy>{5DD74568-4D4B-44C1-B513-0AF5F4CDA34F}</createdBy>
    ...
    ...
  </fieldIdsToIntern>
</interning>

TRICK 10: FORCE GARBAGE COLLECTION WHEN MEMORY IS LOW

The old peeing in your pants trick is also implemented by Sitecore. You need to enable counters first:

<setting name="Counters.Enabled" value="true"/>

Then you can allow the MemoryMonitorHook to force a garbage collection when memory is running low:

<hooks>
    <hook type="Sitecore.Diagnostics.MemoryMonitorHook, Sitecore.Kernel">
        <param desc="Threshold">8192MB</param>
        <param desc="Check interval">00:15:00</param>
        <ClearCaches>true</ClearCaches>
        <GarbageCollect>true</GarbageCollect>
        <AdjustLoadFactor>false</AdjustLoadFactor>
    </hook>
</hooks>

I guess that’s it. If you know of a memory trick for Sitecore, please let me know.

MORE TO READ:

 


Viewing all articles
Browse latest Browse all 286

Trending Articles