Just found the handbrake ...
This commit is contained in:
parent
b9bcc921a6
commit
99b86c9fd9
2 changed files with 50 additions and 24 deletions
|
@ -627,6 +627,12 @@ class dba {
|
||||||
self::$dbo->errorno = mysql_errno(self::$dbo->db);
|
self::$dbo->errorno = mysql_errno(self::$dbo->db);
|
||||||
} else {
|
} else {
|
||||||
self::$dbo->affected_rows = mysql_affected_rows($retval);
|
self::$dbo->affected_rows = mysql_affected_rows($retval);
|
||||||
|
|
||||||
|
// Due to missing mysql_* support this here wasn't tested at all
|
||||||
|
// See here: http://php.net/manual/en/function.mysql-num-rows.php
|
||||||
|
if (self::$dbo->affected_rows <= 0) {
|
||||||
|
self::$dbo->affected_rows = mysql_num_rows($retval);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1038,7 +1044,7 @@ class dba {
|
||||||
$sql = "DELETE FROM `".$command['table']."` WHERE `".
|
$sql = "DELETE FROM `".$command['table']."` WHERE `".
|
||||||
implode("` = ? AND `", array_keys($command['param']))."` = ?";
|
implode("` = ? AND `", array_keys($command['param']))."` = ?";
|
||||||
|
|
||||||
logger(dba::replace_parameters($sql, $command['param']), LOGGER_DATA);
|
logger(self::replace_parameters($sql, $command['param']), LOGGER_DATA);
|
||||||
|
|
||||||
if (!self::e($sql, $command['param'])) {
|
if (!self::e($sql, $command['param'])) {
|
||||||
if ($do_transaction) {
|
if ($do_transaction) {
|
||||||
|
@ -1068,7 +1074,7 @@ class dba {
|
||||||
$sql = "DELETE FROM `".$table."` WHERE `".$field."` IN (".
|
$sql = "DELETE FROM `".$table."` WHERE `".$field."` IN (".
|
||||||
substr(str_repeat("?, ", count($field_values)), 0, -2).");";
|
substr(str_repeat("?, ", count($field_values)), 0, -2).");";
|
||||||
|
|
||||||
logger(dba::replace_parameters($sql, $field_values), LOGGER_DATA);
|
logger(self::replace_parameters($sql, $field_values), LOGGER_DATA);
|
||||||
|
|
||||||
if (!self::e($sql, $field_values)) {
|
if (!self::e($sql, $field_values)) {
|
||||||
if ($do_transaction) {
|
if ($do_transaction) {
|
||||||
|
|
|
@ -18,7 +18,7 @@ if (!file_exists("boot.php") && (sizeof($_SERVER["argv"]) != 0)) {
|
||||||
require_once("boot.php");
|
require_once("boot.php");
|
||||||
|
|
||||||
function poller_run($argv, $argc){
|
function poller_run($argv, $argc){
|
||||||
global $a, $db, $poller_up_start;
|
global $a, $db, $poller_up_start, $poller_db_duration;
|
||||||
|
|
||||||
$poller_up_start = microtime(true);
|
$poller_up_start = microtime(true);
|
||||||
|
|
||||||
|
@ -104,8 +104,9 @@ function poller_run($argv, $argc){
|
||||||
|
|
||||||
// If possible we will fetch new jobs for this worker
|
// If possible we will fetch new jobs for this worker
|
||||||
if (!$refetched && Lock::set('poller_worker_process', 0)) {
|
if (!$refetched && Lock::set('poller_worker_process', 0)) {
|
||||||
logger('Blubb: a');
|
$stamp = (float)microtime(true);
|
||||||
$refetched = find_worker_processes();
|
$refetched = find_worker_processes();
|
||||||
|
$poller_db_duration += (microtime(true) - $stamp);
|
||||||
Lock::remove('poller_worker_process');
|
Lock::remove('poller_worker_process');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -545,15 +546,16 @@ function poller_too_much_workers() {
|
||||||
}
|
}
|
||||||
dba::close($entries);
|
dba::close($entries);
|
||||||
|
|
||||||
$jobs_per_minute = 0;
|
$intervals = array(1, 10, 60);
|
||||||
|
$jobs_per_minute = array();
|
||||||
$jobs = dba::p("SELECT COUNT(*) AS `jobs` FROM `workerqueue` WHERE `done` AND `executed` > UTC_TIMESTAMP() - INTERVAL 10 MINUTE");
|
foreach ($intervals AS $interval) {
|
||||||
if ($job = dba::fetch($jobs)) {
|
$jobs = dba::p("SELECT COUNT(*) AS `jobs` FROM `workerqueue` WHERE `done` AND `executed` > UTC_TIMESTAMP() - INTERVAL ".intval($interval)." MINUTE");
|
||||||
$jobs_per_minute = number_format($job['jobs'] / 10, 0);
|
if ($job = dba::fetch($jobs)) {
|
||||||
|
$jobs_per_minute[$interval] = number_format($job['jobs'] / $interval, 0);
|
||||||
|
}
|
||||||
|
dba::close($jobs);
|
||||||
}
|
}
|
||||||
dba::close($jobs);
|
$processlist = ' - jpm: '.implode('/', $jobs_per_minute).' ('.implode(', ', $listitem).')';
|
||||||
|
|
||||||
$processlist = ' - jpm: '.$jobs_per_minute.' ('.implode(', ', $listitem).')';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$entries = poller_total_entries();
|
$entries = poller_total_entries();
|
||||||
|
@ -664,34 +666,52 @@ function find_worker_processes($mypid = 0) {
|
||||||
|
|
||||||
if (poller_passing_slow($highest_priority)) {
|
if (poller_passing_slow($highest_priority)) {
|
||||||
// Are there waiting processes with a higher priority than the currently highest?
|
// Are there waiting processes with a higher priority than the currently highest?
|
||||||
$result = dba::e("UPDATE `workerqueue` SET `executed` = ?, `pid` = ?
|
$result = dba::p("SELECT `id` FROM `workerqueue`
|
||||||
WHERE `executed` <= ? AND `priority` < ? AND NOT `done`
|
WHERE `executed` <= ? AND `priority` < ? AND NOT `done`
|
||||||
ORDER BY `priority`, `created` LIMIT ".intval($limit),
|
ORDER BY `priority`, `created` LIMIT ".intval($limit),
|
||||||
datetime_convert(), $mypid, NULL_DATE, $highest_priority);
|
NULL_DATE, $highest_priority);
|
||||||
if ($result) {
|
|
||||||
$found = (dba::affected_rows() > 0);
|
while ($id = dba::fetch($result)) {
|
||||||
|
$ids[] = $id["id"];
|
||||||
}
|
}
|
||||||
|
dba::close($result);
|
||||||
|
|
||||||
|
$found = (count($ids) > 0);
|
||||||
|
|
||||||
if (!$found) {
|
if (!$found) {
|
||||||
// Give slower processes some processing time
|
// Give slower processes some processing time
|
||||||
$result = dba::e("UPDATE `workerqueue` SET `executed` = ?, `pid` = ?
|
$result = dba::p("SELECT `id` FROM `workerqueue`
|
||||||
WHERE `executed` <= ? AND `priority` > ? AND NOT `done`
|
WHERE `executed` <= ? AND `priority` > ? AND NOT `done`
|
||||||
ORDER BY `priority`, `created` LIMIT ".intval($limit),
|
ORDER BY `priority`, `created` LIMIT ".intval($limit),
|
||||||
datetime_convert(), $mypid, NULL_DATE, $highest_priority);
|
NULL_DATE, $highest_priority);
|
||||||
if ($result) {
|
|
||||||
$found = (dba::affected_rows() > 0);
|
while ($id = dba::fetch($result)) {
|
||||||
|
$ids[] = $id["id"];
|
||||||
}
|
}
|
||||||
|
dba::close($result);
|
||||||
|
|
||||||
|
$found = (count($ids) > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is no result (or we shouldn't pass lower processes) we check without priority limit
|
// If there is no result (or we shouldn't pass lower processes) we check without priority limit
|
||||||
if (!$found) {
|
if (!$found) {
|
||||||
$result = dba::e("UPDATE `workerqueue` SET `executed` = ?, `pid` = ? WHERE `executed` <= ? AND NOT `done` ORDER BY `priority`, `created` LIMIT ".intval($limit),
|
$result = dba::p("SELECT `id` FROM `workerqueue` WHERE `executed` <= ? AND NOT `done` ORDER BY `priority`, `created` LIMIT ".intval($limit), NULL_DATE);
|
||||||
datetime_convert(), $mypid, NULL_DATE);
|
|
||||||
if ($result) {
|
while ($id = dba::fetch($result)) {
|
||||||
$found = (dba::affected_rows() > 0);
|
$ids[] = $id["id"];
|
||||||
}
|
}
|
||||||
|
dba::close($result);
|
||||||
|
|
||||||
|
$found = (count($ids) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($found) {
|
||||||
|
$sql = "UPDATE `workerqueue` SET `executed` = ?, `pid` = ? WHERE `id` IN (".substr(str_repeat("?, ", count($ids)), 0, -2).") AND `pid` = 0 AND NOT `done`;";
|
||||||
|
array_unshift($ids, datetime_convert(), $mypid);
|
||||||
|
dba::e($sql, $ids);
|
||||||
|
}
|
||||||
|
|
||||||
return $found;
|
return $found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue