memcache: allow yii to use cache too (db structure)

cache is now enabled in yiimp console too
This commit is contained in:
Tanguy Pruvot 2016-01-15 15:06:01 +01:00
parent 235dc7411b
commit 3a6ec3201a
6 changed files with 89 additions and 43 deletions

View file

@ -57,6 +57,19 @@ return array(
'charset'=>'utf8',
'schemaCachingDuration'=>3600,
),
'cache'=>array(
'class'=>'CMemCache',
'keyPrefix'=>'',
'servers'=>array(
array(
'host'=>'127.0.0.1',
'port'=> 11211,
'weight'=> 60,
),
),
),
),

View file

@ -11,7 +11,14 @@ return array(
'basePath'=>YAAMP_HTDOCS."/yaamp",
'preload'=>array('log'),
'import'=>array('application.components.*'),
// autoloading model and component classes
'import'=>array(
'application.components.*',
'application.commands.*',
'application.models.*',
'application.extensions.*',
),
'components'=>array(
@ -20,22 +27,6 @@ return array(
'baseUrl' => '',
),
// autoloading model and component classes
'import'=>array(
'application.components.*',
'application.commands.*',
//'application.commands.shell.*',
'application.models.*',
'application.extensions.*',
),
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'appendParams'=>false,
),
'assetManager'=>array(
'basePath'=>YAAMP_HTDOCS."/assets"
),
@ -55,11 +46,6 @@ return array(
),
),
'user'=>array(
'allowAutoLogin'=>true,
'loginUrl'=>array('site/login'),
),
'db'=>array(
'class'=>'CDbConnection',
'connectionString'=>"mysql:host=".YAAMP_DBHOST.";dbname=".YAAMP_DBNAME,
@ -71,12 +57,20 @@ return array(
'charset'=>'utf8',
'schemaCachingDuration'=>3600,
),
),
'cache'=>array(
'class'=>'CMemCache',
'keyPrefix'=>'',
'servers'=>array(
array(
'host'=>'127.0.0.1',
'port'=> 11211,
'weight'=> 60,
),
),
),
),
);

View file

@ -2,9 +2,21 @@
function controller()
{
// console app has no controller
if (app() instanceof CConsoleApplication)
return app();
return app()->getController();
}
function cache()
{
if (app() instanceof CConsoleApplication)
return app()->cache;
return app()->getController()->memcache;
}
function arraySafeVal($arr,$p,$default=NULL)
{
if (isset($arr[$p]))

View file

@ -7,13 +7,11 @@ JavascriptFile("/extensions/jqplot/plugins/jqplot.highlighter.js");
echo getAdminSideBarLinks();
//<a href='/site/memcached'>Memcache</a>&nbsp;
//<a href='/site/eval'>Eval</a>&nbsp;
//<a href='/renting/admin'>Jobs</a>&nbsp;
?>
<a href='/site/memcached'>Memcache</a>&nbsp;
<a href='/site/connections'>Connections</a>&nbsp;
<?php if (YAAMP_RENTAL) : ?>
<a href='/renting/admin'>Rental</a>&nbsp;
<?php endif; ?>

View file

@ -3,8 +3,6 @@
$last = dboscalar("select max(last) from connections");
$list = getdbolist('db_connections', "1 order by id desc");
echo count($list)." connections<br>";
//echo "<table class='dataGrid'>";
showTableSorter('maintable');
echo "<thead>";
@ -12,7 +10,7 @@ echo "<tr>";
echo "<th>ID</th>";
echo "<th>User</th>";
echo "<th>Host</th>";
echo "<th>Db</th>";
echo "<th>Database</th>";
echo "<th>Idle</th>";
echo "<th>Created</th>";
echo "<th>Last</th>";
@ -43,6 +41,4 @@ foreach($list as $conn)
echo "</tbody></table><br>";
echo count($list)." connections to the database<br>";

View file

@ -5,6 +5,42 @@ echo "<a href='/site/memcached'>refresh</a><br>";
$memcache = controller()->memcache->memcache;
$a = memcache_get($this->memcache->memcache, 'url-map');
function printStats($stat)
{
echo "<hr/>";
echo "<table>";
echo "<tr><td>Memcache Server version</td><td> ".$stat["version"]."</td></tr>";
echo "<tr><td>Process id of this server process</td><td>".$stat["pid"]."</td></tr>";
echo "<tr><td>Server uptime </td><td>".$stat["uptime"]." seconds</td></tr>";
echo "<tr><td>Accumulated user time for this process</td><td>".round($stat["rusage_user"],1)." seconds</td></tr>";
echo "<tr><td>Accumulated system time for this process</td><td>".round($stat["rusage_system"],1)." seconds</td></tr>";
echo "<tr><td>Total number of items stored by this server start</td><td>".$stat["total_items"]."</td></tr>";
echo "<tr><td>Number of open connections </td><td>".$stat["curr_connections"]."</td></tr>";
echo "<tr><td>Total number of connections opened since server start</td><td>".$stat["total_connections"]."</td></tr>";
echo "<tr><td>Number of connection structures allocated by the server</td><td>".$stat["connection_structures"]."</td></tr>";
echo "<tr><td>Cumulative number of retrieval requests</td><td>".$stat["cmd_get"]."</td></tr>";
echo "<tr><td> Cumulative number of storage requests</td><td>".$stat["cmd_set"]."</td></tr>";
$percCacheHit=((real)$stat["get_hits"]/ (real)$stat["cmd_get"] *100);
$percCacheHit=round($percCacheHit,3);
$percCacheMiss=100-$percCacheHit;
echo "<tr><td>Number of keys that have been requested and found</td><td>".$stat["get_hits"]." ($percCacheHit%)</td></tr>";
echo "<tr><td>Number of items that have been requested and not found</td><td>".$stat["get_misses"]." ($percCacheMiss%)</td></tr>";
$MBRead= (real)$stat["bytes_read"]/(1024*1024);
echo "<tr><td>Total number of bytes read by this server from network</td><td>".$MBRead." MB</td></tr>";
$MBWrite=(real) $stat["bytes_written"]/(1024*1024) ;
echo "<tr><td>Total number of bytes sent by this server to network</td><td>".$MBWrite." MB</td></tr>";
$MBSize=(real) $stat["limit_maxbytes"]/(1024*1024) ;
echo "<tr><td>Size allowed to use for storage</td><td>".$MBSize." MB</td></tr>";
echo "<tr><td>Items removed from cache to free memory for new items</td><td>".$stat["evictions"]."</td></tr>";
echo "</table>";
}
printStats($this->memcache->memcache->getStats());
$res = array();
function cmp($a, $b)
@ -23,7 +59,8 @@ foreach($a as $url=>$n)
usort($res, 'cmp');
echo "<br><table class='dataGrid'>";
echo '<div style="margin-top: 8px; margin-bottom: 24px; margin-right: 16px;">';
echo '<table class="dataGrid">';
echo "<thead>";
echo "<tr>";
echo "<th>Url</th>";
@ -51,8 +88,4 @@ foreach($res as $item)
echo "</tr>";
}
echo "</tbody></table>";
echo "</tbody></table></div>";