Use adaptive cache worker count

This commit is contained in:
Terranom674
2026-08-15 20:24:50 +02:00
parent e6c195f657
commit 7d679d7aa2

View File

@@ -4,6 +4,8 @@ if (!defined('PHPWG_ROOT_PATH'))
die('Hacking attempt!'); die('Hacking attempt!');
} }
require_once(BRATONIEN_TOOLS_PATH.'include/cache_worker_settings.inc.php');
function bratonien_tools_main_cache_status_file() function bratonien_tools_main_cache_status_file()
{ {
return PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'bratonien-tools-main-cache.status.json'; return PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'bratonien-tools-main-cache.status.json';
@@ -38,6 +40,8 @@ function bratonien_tools_write_main_cache_status(array $status)
'skipped'=>0, 'skipped'=>0,
'errors'=>0, 'errors'=>0,
'current'=>'', 'current'=>'',
'worker_count'=>0,
'cpu_count'=>0,
'updated_at'=>time(), 'updated_at'=>time(),
), $status); ), $status);
$payload['updated_at'] = time(); $payload['updated_at'] = time();
@@ -372,13 +376,19 @@ function bratonien_tools_start_main_cache_build()
throw new RuntimeException('PHP exec() ist deaktiviert; Cache-Worker kann nicht gestartet werden.'); throw new RuntimeException('PHP exec() ist deaktiviert; Cache-Worker kann nicht gestartet werden.');
} }
$settings = bratonien_tools_get_cache_worker_settings();
$worker_count = max(1, (int)$settings['worker_count']);
$cpu_count = max(1, (int)$settings['cpu_count']);
bratonien_tools_write_main_cache_status(array( bratonien_tools_write_main_cache_status(array(
'state'=>'queued', 'state'=>'queued',
'message'=>'Piwigo-Bildcache wird mit 6 Workern vorbereitet.', 'message'=>sprintf('Piwigo-Bildcache wird mit %d Worker(n) vorbereitet.', $worker_count),
'worker_count'=>$worker_count,
'cpu_count'=>$cpu_count,
)); ));
$log = PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'bratonien-tools-main-cache.log'; $log = PHPWG_ROOT_PATH.PWG_LOCAL_DIR.'bratonien-tools-main-cache.log';
$command = 'nohup '.escapeshellarg($php).' '.escapeshellarg($worker).' >> '.escapeshellarg($log).' 2>&1 < /dev/null & echo $!'; $command = 'nohup '.escapeshellarg($php).' '.escapeshellarg($worker).' --workers='.$worker_count.' >> '.escapeshellarg($log).' 2>&1 < /dev/null & echo $!';
$output = array(); $output = array();
$exit = 1; $exit = 1;
@exec($command, $output, $exit); @exec($command, $output, $exit);
@@ -390,6 +400,8 @@ function bratonien_tools_start_main_cache_build()
'state'=>'error', 'state'=>'error',
'message'=>'Piwigo-Bildcache konnte nicht gestartet werden.', 'message'=>'Piwigo-Bildcache konnte nicht gestartet werden.',
'errors'=>1, 'errors'=>1,
'worker_count'=>$worker_count,
'cpu_count'=>$cpu_count,
)); ));
throw new RuntimeException('Piwigo-Bildcache konnte nicht gestartet werden.'); throw new RuntimeException('Piwigo-Bildcache konnte nicht gestartet werden.');
} }
@@ -397,7 +409,12 @@ function bratonien_tools_start_main_cache_build()
return array( return array(
'started'=>true, 'started'=>true,
'pid'=>$pid, 'pid'=>$pid,
'message'=>'Piwigo-Bildcache wurde manuell mit 6 Workern gestartet.', 'message'=>sprintf(
'Piwigo-Bildcache wurde mit %d Worker(n) gestartet (%d CPU(s), %s).',
$worker_count,
$cpu_count,
$settings['auto'] ? 'Automatik 1:1' : 'manuell'
),
); );
} }