Skip to content

Instantly share code, notes, and snippets.

@mrclay
Created November 28, 2014 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrclay/96894afa7c26a07c0df8 to your computer and use it in GitHub Desktop.
Save mrclay/96894afa7c26a07c0df8 to your computer and use it in GitHub Desktop.
Elgg: Graph memory usage loading a large number of entities
<?php
require __DIR__ . '/engine/start.php';
global $ENTITY_CACHE;
_elgg_services()->db->disableQueryCache();
$md_cache = _elgg_services()->metadataCache;
$mem_initial = 0;
$show_mem_delta = function () use (&$mem_initial) {
static $last;
$mem = memory_get_usage();
$total = ($mem - $mem_initial);
$delta = (null === $last) ? 0 : ($total - $last);
if ($delta > 0) {
$delta = "+$delta";
}
$width = round($total / 3000);
echo "<div class='r' title='$delta (total: $total)' style='width:{$width}px'></div>";
$last = $total;
flush();
ob_flush();
};
// get a bunch of GUIDs to load later
$guids = elgg_get_entities(array(
//'type' => 'user',
'order_by' => 'guid DESC',
'limit' => 3000,
'callback' => function ($row) { return $row->guid; },
));
// baseline mem usage
$ENTITY_CACHE = array();
$md_cache->flush();
$mem_initial = memory_get_usage();
?>
<style>.r{background:#080;height:2px}</style>
<?php
foreach ($guids as $i => $guid) {
if ($i % 10 == 0) {
$show_mem_delta($i);
}
$entity = get_entity($guid);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment