Created
November 28, 2014 14:54
-
-
Save mrclay/96894afa7c26a07c0df8 to your computer and use it in GitHub Desktop.
Elgg: Graph memory usage loading a large number of entities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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