Skip to content

Instantly share code, notes, and snippets.

@glompix
Created August 26, 2015 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save glompix/8338c0602efe7c6804db to your computer and use it in GitHub Desktop.
Save glompix/8338c0602efe7c6804db to your computer and use it in GitHub Desktop.
Calculate average item size for a Sitecore database
<%@ Page language="c#" %>
<%@ Import Namespace="Sitecore.Data.Items" %>
<!DOCTYPE html>
<html>
<head>
<title>Cache Admin</title>
<link rel="shortcut icon" href="/sitecore/images/favicon.ico" />
<%
var db = Sitecore.Configuration.Factory.GetDatabase("master");
Func<Item[]> ReturnAllItems = () =>
{
Item i = db.GetItem("/sitecore/content");
return i.Axes.GetDescendants();
};
var start = GC.GetTotalMemory(true);
var items = ReturnAllItems();
var end = GC.GetTotalMemory(true);
var item = items[1]; // Supposedly required for accurate results.
const double bytesInKilo = 1024;
var bytesPerItem = (end - start) / (double)items.Length;
%>
</head>
<body>
<h1>Average Item Size Calculator</h1>
<p>This is a tool to determine what to set the <strong>Caching.AverageItemSize</strong> setting to.</p>
<p>
(<%= end %>B - <%= start %>B) / <%= items.Length %> items = <b><%= bytesPerItem %> B/item</b>.
</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment