Work on performance improvements with caching

This commit is contained in:
Deon George
2012-12-04 11:52:10 +11:00
parent eafb80f7fc
commit 1bf8a520e2
30 changed files with 877 additions and 495 deletions

View File

@@ -32,80 +32,238 @@ class Model_DOMAIN extends TSM_ORM {
),
);
// Pools used by a domain.
private $pools = array();
// Work out all the storage pools used by a domain.
// $dtype is BACKUP (Bkup) or ARCHIVE (Arch)
public function getStoragePools($dtype) {
return isset($this->pools[$dtype]) ? $this->pools[$dtype] : $this->_getpools($dtype);
}
private function _getpools($dtype) {
$this->pools[$dtype] = array();
foreach ($this->NODE->find_all() as $no)
foreach ($no->getStoragePools($dtype) as $ptype => $stgpools)
foreach ($stgpools as $spo)
if (! isset($this->pools[$dtype][$ptype]) OR ! in_array($spo,$this->pools[$dtype][$ptype]))
$this->pools[$dtype][$ptype][] = $spo;
return $this->pools[$dtype];
}
// Return the storage pools used for a domain by backup type
// $dtype is BACKUP (Bkup) or ARCHIVE (Arch)
// $ptype is pool type (PRIMARY,ACTIVE,COPY)
public function getStoragePoolsType($dtype,$ptype) {
if (! isset($this->pools[$dtype]))
$this->_getpools($dtype);
return isset($this->pools[$dtype][$ptype]) ? $this->pools[$dtype][$ptype] : array();
}
// $dtype is BACKUP or ARCHIVE
// $ptype is pool type (PRIMARY,ACTIVE,COPY)
public function getStorageModeVols($dtype,$ptype,$spo='') {
/**
* Get all the NODES in this DOMAIN
*/
private function _nodes() {
$result = array();
foreach ($this->NODE->find_all() as $no)
$result = array_merge($result,$no->getStorageModeVols($dtype,$ptype,$spo));
// In the interest of performance, we load all the records and get PHP to process it.
// Our ORM caching we reduce the hit on TSM.
foreach (ORM::factory('NODE')->find_all() as $o)
if ($o->DOMAIN_NAME == $this->DOMAIN_NAME)
array_push($result,$o);
return $result;
}
// $dtype is BACKUP (Bkup) or ARCHIVE (Arch)
// $ptype is pool type (PRIMARY,ACTIVE,COPY)
public function getStorageModeFiles($dtype,$ptype,$spo='') {
$count = 0;
foreach ($this->NODE->find_all() as $no)
$count += $no->getStorageModeFiles($dtype,$ptype,$spo);
return $count;
public function nodes() {
return $this->_nodes();
}
// $dtype is BACKUP or ARCHIVE
// $ptype is pool type (PRIMARY,ACTIVE,COPY)
public function getStorageModeData($dtype,$ptype,$spo='') {
$count = 0;
/**
* Return the FILES that NODES in this DOMAIN has in a STORAGE POOL
* @param $pool is STORAGE POOL NAME
*/
public function file_bypool($pool) {
$k = sprintf('%s-%s-%s',__METHOD__,$this->DOMAIN_NAME,$pool);
$c = Kohana::$config->load('config')->cache;
foreach ($this->NODE->find_all() as $no)
$count += $no->getStorageModeData($dtype,$ptype,$spo);
if (is_null($result = Cache::instance($c)->get($k))) {
$result = 0;
return $count;
foreach ($this->_nodes() as $no)
$result += $no->file_bypool($pool);
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
// $dtype is BACKUP or ARCHIVE
// $ptype is pool type (PRIMARY,ACTIVE,COPY)
public function getStorageModeNodes($dtype,$ptype,$spo='') {
/**
* Return the LOGICAL_MB that NODES in this DOMAIN has in a STORAGE POOL
* @param $pool is STORAGE POOL NAME
*/
public function logmb_bypool($pool) {
$k = sprintf('%s-%s-%s',__METHOD__,$this->DOMAIN_NAME,$pool);
$c = Kohana::$config->load('config')->cache;
if (is_null($result = Cache::instance($c)->get($k))) {
$result = 0;
foreach ($this->_nodes() as $no)
$result += $no->logmb_bypool($pool);
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
/**
* Return the NODES in this DOMAIN that have data in this STORAGE POOL
* @param $pool is STORAGE POOL NAME
*/
public function nodes_bypool(ORM $spo) {
$result = array();
foreach ($this->NODE->find_all() as $no)
if ($no->getStorageModeData($dtype,$ptype,$spo))
foreach ($spo->nodes() as $no)
if (in_array($no,$this->_nodes()))
array_push($result,$no);
return $result;
}
/**
* Return the STORAGE POOLS used by NODES in this DOMAIN
*/
public function stgpools() {
$k = sprintf('%s-%s',__METHOD__,$this->DOMAIN_NAME);
$c = Kohana::$config->load('config')->cache;
if (is_null($result = Cache::instance($c)->get($k))) {
$result = array();
foreach ($this->nodes() as $no)
foreach ($no->stgpools() as $spo)
if (! in_array($spo,$result))
array_push($result,$spo);
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
/**
* Return the STORAGE POOL TYPES used by NODES in this DOMAIN
* ie: ACTIVE/PRIMARY/COPY
* @todo This should be sorted by PRIMARY/ACTIVE/COPY
*/
public function stgpooltypes() {
$k = sprintf('%s-%s',__METHOD__,$this->DOMAIN_NAME);
$c = Kohana::$config->load('config')->cache;
if (is_null($result = Cache::instance($c)->get($k))) {
$result = array();
foreach ($this->stgpools() as $spo)
if (! in_array($spo->POOLTYPE,$result))
array_push($result,$spo->POOLTYPE);
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
/**
* Return the STORAGE POOLS that NODES in this DOMAIN uses by BACKUP TYPE
* @param $type is BACKUP/ARCHIVE/SPACE MANAGED
*/
public function stgpools_bybtype($type) {
$k = sprintf('%s-%s-%s',__METHOD__,$this->DOMAIN_NAME,$type);
$c = Kohana::$config->load('config')->cache;
if (is_null($result = Cache::instance($c)->get($k))) {
$x = $result = array();
foreach ($this->_nodes() as $no)
foreach ($no->stgpools_bybtype($type) as $spo)
if (! in_array($spo->STGPOOL_NAME,$result))
array_push($result,$spo);
Sort::MASort($result,'STGPOOL_NAME');
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
/**
* Return the STORAGE POOLS that NODES in this DOMAIN uses by BACKUP TYPE
* @param $type is ACTIVEDATA/PRIMARY/COPY
*/
public function stgpools_byptype($type) {
$k = sprintf('%s-%s-%s',__METHOD__,$this->DOMAIN_NAME,$type);
$c = Kohana::$config->load('config')->cache;
if (is_null($result = Cache::instance($c)->get($k))) {
$result = array();
foreach ($this->stgpools() as $spo)
if ($spo->POOLTYPE == $type)
array_push($result,$spo);
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
/**
* Return the VOLUMES that NODES in this DOMAIN use
* @param $pool is STORAGE POOL NAME
*/
public function vols_bypool($pool) {
$k = sprintf('%s-%s-%s',__METHOD__,$this->DOMAIN_NAME,$pool);
$c = Kohana::$config->load('config')->cache;
if (is_null($result = Cache::instance($c)->get($k))) {
$x = $result = array();
foreach ($this->_nodes() as $no)
foreach ($no->vols_bypool($pool) as $vuo)
if (! in_array($vuo->VOLUME_NAME,$x)) {
array_push($result,$vuo);
array_push($x,$vuo->VOLUME_NAME);
}
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
/**
* Return the VOLUMES that NODES in this DOMAIN uses by BACKUP TYPE
* @param $type is BACKUP/ARCHIVE/SPACE MANAGED
*/
public function vols_bybtype($type) {
$k = sprintf('%s-%s-%s',__METHOD__,$this->DOMAIN_NAME,$type);
$c = Kohana::$config->load('config')->cache;
if (TRUE OR is_null($result = Cache::instance($c)->get($k))) {
$x = $result = array();
foreach ($this->_nodes() as $no)
foreach ($no->vols_bybtype($type) as $vuo)
if (! in_array($vuo->VOLUME_NAME,$x)) {
array_push($result,$vuo);
array_push($x,$vuo->VOLUME_NAME);
}
// @todo Cache time should be configurble
Cache::instance($c)->set($k,$result,300);
}
return $result;
}
/**
* Return the VOLUMES that this NODE uses by pool and BACKUP TYPE
* @param $pool is STORAGE POOL NAME
* @param $type is BACKUP/ARCHIVE/SPACE MANAGED
*/
public function vols_bypoolbybtype($pool,$type) {
$x = $result = array();
foreach ($this->vols_bypool($pool) as $vuo)
if ($vuo->COPY_TYPE == $type AND ! in_array($vuo->VOLUME_NAME,$x)) {
array_push($result,$vuo);
array_push($x,$vuo->VOLUME_NAME);
}
return $result;
}
}
?>