Coding standards
Security in ResourceSpace
Developer reference
Database
User api session functions
Geolocation functions
Storage test functions

storage_test_public()

Description

Return objective measurements and progress only. Throughput uses decimal MB (1,000,000 bytes).
Small-file rates count successfully completed whole files, not byte estimates.

Parameters

ColumnTypeDefaultDescription
$state: array
$state array Server state.

Return

array JSON-safe response, including formatted metric values and units.

Location

include/storage_test_functions.php lines 575 to 626

Definition

 
function storage_test_public(array $state): array
{
    
$metrics = [];
    foreach (
$state['metrics'] as $name => $measurement) {
        
$count = match ($name) {
            
'small_create' => $state['small_created'],
            
'small_read' => $state['small_read'],
            default => 
$measurement['count'] ?? 0,
        };
        if (
$count <= 0 || $measurement['seconds'] <= 0 || $name === 'random') {
            continue;
        }
        
$throughput = in_array($name, ['write', 'read'], true);
        
$rate = $count / $measurement['seconds'] / ($throughput ? 1e6 : 1);
        
$whole_files = in_array($name, ['small_create', 'small_read', 'file_delete'], true);
        
$metrics[$name] = [
            
'value' => number_format($rate, 2, '.', ''),
            
'unit' => $throughput ? 'MB/s' : ($whole_files ? 'files/s' : 'ops/s'),
            
'count' => $count,
            
'seconds' => round($measurement['seconds'], 6),
        ];
    }
    
$latencies = $state['latencies'];
    
sort($latencies, SORT_NUMERIC);
    if (
$latencies !== []) {
        
$mean = array_sum($latencies) / count($latencies);
        
$p95 = $latencies[(int) ceil(count($latencies) * 0.95) - 1];
        
$metrics['random_mean'] = ['value' => number_format($mean, 2, '.', ''), 'unit' => 'ms'];
        
$metrics['random_p95'] = ['value' => number_format($p95, 2, '.', ''), 'unit' => 'ms'];
    }
    
$stages = array_merge(array_keys(storage_test_stages()), ['cleanup', 'done']);
    
$index = array_search($state['stage'], $stages, true);
    
$limits = ['directories' => 20, 'write' => 64, 'read' => 64, 'small_create' => 96,
        
'small_read' => 96, 'stat' => 96, 'random' => 64, 'enumerate' => 20, 'cleanup' => 121, 'done' => 1];
    
$fraction = $state['stage'] === 'cleanup'
        
? $state['cleanup_cursor'] / 121
        
: $state['cursor'] / $limits[$state['stage']];
    
$elapsed = $state['elapsed'] ?? microtime(true) - $state['started'];
    
$metrics['elapsed'] = ['value' => number_format($elapsed, 2, '.', ''), 'unit' => 's'];
    return [
'id' => $state['id'], 'sequence' => $state['sequence'], 'stage' => $state['stage'],
        
'progress' => $state['stage'] === 'done' ? 100 : min(99, (int) (($index + $fraction) / 9 * 100)),
        
'last_operation' => $state['last_operation'] ?? null,
        
'operations' => $state['operations'] ?? 0,
        
'operations_total' => array_sum($limits) - $limits['done'],
        
'completed' => $state['stage'] === 'cleanup' ? $state['cleanup_cursor'] : $state['cursor'],
        
'total' => $limits[$state['stage']],
        
'item' => in_array($state['stage'], ['directories', 'enumerate'], true)
            ? (
storage_test_manifest()['dirs'][$state['cursor']] ?? '') : '',
        
'written' => $state['written'], 'read' => $state['read'], 'metrics' => $metrics,
        
'slow' => $state['slow'], 'limited' => $state['limited'], 'outcome' => $state['outcome'],
        
'error' => $state['error'] ?? null];
}

This article was last updated 13th November 2026 13:05 Europe/London time based on the source file dated 13th November 2026 11:40 Europe/London time.