re-adding seperate tables for shares and hashes due to SQL load when combining them

This commit is contained in:
Sebastian Grewe 2013-05-17 13:40:22 +02:00
parent 313e87defb
commit ccf322bde1
5 changed files with 99 additions and 59 deletions

View File

@ -156,31 +156,37 @@ class Statistics {
return false;
}
public function getTopContributors($limit=15) {
$stmt = $this->mysqli->prepare("
SELECT
ROUND(COUNT(id) / 60 / 10, 2) AS sharesps,
ROUND(COUNT(id) * POW(2," . $this->config['difficulty'] . ")/600/1000,2) AS hashrate,
SUBSTRING_INDEX( username, '.', 1 ) AS account
FROM " . $this->share->getTableName() . "
WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)
GROUP BY account
ORDER BY hashrate DESC LIMIT ?");
if ($this->checkStmt($stmt) && $stmt->bind_param("i", $limit) && $stmt->execute() && $hashrates= $stmt->get_result()) {
$aHashData = $hashrates->fetch_all(MYSQLI_ASSOC);
$stmt->close();
} else {
public function getTopContributors($type='shares', $limit=15) {
switch ($type) {
case 'shares':
$stmt = $this->mysqli->prepare("
SELECT
COUNT(id) AS shares,
SUBSTRING_INDEX( username, '.', 1 ) AS account
FROM " . $this->share->getTableName() . "
GROUP BY account
LIMIT ?");
if ($this->checkStmt($stmt) && $stmt->bind_param("i", $limit) && $stmt->execute() && $result = $stmt->get_result())
return $result->fetch_all(MYSQLI_ASSOC);
$this->debug->append("Fetching shares failed: ");
return false;
break;
case 'hashes':
$stmt = $this->mysqli->prepare("
SELECT
ROUND(COUNT(id) * POW(2," . $this->config['difficulty'] . ")/600/1000,2) AS hashrate,
SUBSTRING_INDEX( username, '.', 1 ) AS account
FROM " . $this->share->getTableName() . "
WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)
GROUP BY account
ORDER BY hashrate DESC LIMIT ?");
if ($this->checkStmt($stmt) && $stmt->bind_param("i", $limit) && $stmt->execute() && $result = $stmt->get_result())
return $result->fetch_all(MYSQLI_ASSOC);
$this->debug->append("Fetching shares failed: ");
return false;
break;
}
foreach ($aHashData as $key => $aData) {
$stmt = $this->mysqli->prepare("SELECT COUNT(id) FROM " . $this->share->getTableName() . " WHERE SUBSTRING_INDEX( username , '.', 1 ) = ?");
if ($stmt->bind_param("s", $aData['username']) && $stmt->execute() && $result = $stmt->get_result()) {
$aHashData[$key]['shares'] = $this->getUserShares($this->user->getUserId($aData['account']))['valid'];
} else {
continue;
}
}
return $aHashData;
}
public function getHourlyHashrateByAccount($account_id) {

View File

@ -20,11 +20,20 @@ if ($bitcoin->can_connect() === true){
$_SESSION['POPUP'][] = array('CONTENT' => 'Unable to connect to pushpool service: ' . $bitcoin->can_connect(), 'TYPE' => 'errormsg');
}
if (!$aHashData = $memcache->get('aHashData')) {
$debug->append('STA Fetching Hashrates from database');
$aHashData = $statistics->getTopContributors();
$memcache->set('aHashData', $aHashData, 60);
$debug->append('END Fetching Hashrates from database');
// Top share contributors
if (!$aContributorsShares = $memcache->get('aContributorsShares')) {
$debug->append('STA Fetching contributor shares from database');
$aContributorsShares = $statistics->getTopContributors('shares', 15);
$memcache->set('aContributorsShares', $aContributorsShares, 60);
$debug->append('END Fetching contributor shares from database');
}
// Top hash contributors
if (!$aContributorsHashes = $memcache->get('aContributorsHashes')) {
$debug->append('STA Fetching contributor hashes from database');
$aContributorsHashes = $statistics->getTopContributors('hashes', 15);
$memcache->set('aContributorsHashes', $aContributorsHashes, 60);
$debug->append('END Fetching contributor hashes from database');
}
// Grab the last 10 blocks found
@ -52,7 +61,8 @@ if (!empty($aBlockData)) {
$smarty->assign("ESTTIME", $iEstTime);
$smarty->assign("TIMESINCELAST", $dTimeSinceLast);
$smarty->assign("BLOCKSFOUND", $aBlocksFoundData);
$smarty->assign("TOPHASHRATES", $aHashData);
$smarty->assign("CONTRIBSHARES", $aContributorsShares);
$smarty->assign("CONTRIBHASHES", $aContributorsHashes);
$smarty->assign("CURRENTBLOCK", $iBlock);
$smarty->assign("LASTBLOCK", $aBlockData['height']);
$smarty->assign("DIFFICULTY", $dDifficulty);

View File

@ -1,34 +1,8 @@
{include file="global/block_header.tpl" BLOCK_HEADER="Pool Statistics" BLOCK_STYLE="clear:none;"}
{include file="global/block_header.tpl" BLOCK_HEADER="Top Contributers"}
<center>
<table width="100%" border="0" style="font-size:13px;" class="sortable">
<thead>
<tr style="background-color:#B6DAFF;">
<th align="left">Rank</th>
<th align="left" scope="col">User Name</th>
<th align="left" scope="col">KH/s</th>
<th align="left" scope="col">Shares</th>
<th align="left" scope="col">Shares/s</th>
<th align="left">Ł/Day<font size="1"> (est)</font></th>
</tr>
</thead>
<tbody>
{assign var=rank value=1}
{section hashrate $TOPHASHRATES}
<tr class="{cycle values="odd,even"}">
<td>{$rank++}</td>
<td>{$TOPHASHRATES[hashrate].account}</td>
<td>{$TOPHASHRATES[hashrate].hashrate|number_format}</td>
<td>{$TOPHASHRATES[hashrate].shares|number_format}</td>
<td>{$TOPHASHRATES[hashrate].sharesps}</td>
<td>{math equation="round(reward / ( diff * pow(2,32) / ( hashrate * 1000 ) / 3600 / 24),3)" diff=$DIFFICULTY reward=$REWARD hashrate=$TOPHASHRATES[hashrate].hashrate}</td>
</tr>
{/section}
</tbody>
</table>
<div id="pagination" class="pagination"></div>
</center>
{include file="global/block_footer.tpl"}
{include file="statistics/pool/contributors_shares.tpl"}
{include file="statistics/pool/contributors_hashrate.tpl"}
{include file="global/block_header.tpl" BLOCK_HEADER="Server Stats" BLOCK_STYLE="clear:all;" STYLE="padding-left:5px;padding-right:5px;"}
<table class="" width="100%" style="font-size:13px;">

View File

@ -0,0 +1,26 @@
{include file="global/block_header.tpl" ALIGN="left" BLOCK_HEADER="Top Hashrate Contributers"}
<center>
<table width="100%" border="0" style="font-size:13px;" class="sortable">
<thead>
<tr style="background-color:#B6DAFF;">
<th align="left">Rank</th>
<th align="left" scope="col">User Name</th>
<th align="left" scope="col">KH/s</th>
<th align="left">Ł/Day<font size="1"> (est)</font></th>
</tr>
</thead>
<tbody>
{assign var=rank value=1}
{section contrib $CONTRIBHASHES}
<tr class="{cycle values="odd,even"}">
<td>{$rank++}</td>
<td>{$CONTRIBHASHES[contrib].account}</td>
<td>{$CONTRIBHASHES[contrib].hashrate|number_format}</td>
<td>{math equation="round(reward / ( diff * pow(2,32) / ( hashrate * 1000 ) / 3600 / 24),3)" diff=$DIFFICULTY reward=$REWARD hashrate=$CONTRIBHASHES[contrib].hashrate}</td>
</tr>
{/section}
</tbody>
</table>
<div id="pagination" class="pagination"></div>
</center>
{include file="global/block_footer.tpl"}

View File

@ -0,0 +1,24 @@
{include file="global/block_header.tpl" ALIGN="right" BLOCK_HEADER="Top Share Contributers"}
<center>
<table width="100%" border="0" style="font-size:13px;" class="sortable">
<thead>
<tr style="background-color:#B6DAFF;">
<th align="left">Rank</th>
<th align="left" scope="col">User Name</th>
<th align="left" scope="col">Shares</th>
</tr>
</thead>
<tbody>
{assign var=rank value=1}
{section hashrate $CONTRIBSHARES}
<tr class="{cycle values="odd,even"}">
<td>{$rank++}</td>
<td>{$CONTRIBSHARES[hashrate].account}</td>
<td>{$CONTRIBSHARES[hashrate].shares|number_format}</td>
</tr>
{/section}
</tbody>
</table>
<div id="pagination" class="pagination"></div>
</center>
{include file="global/block_footer.tpl"}