22 lines
3.0 KiB
PHP
22 lines
3.0 KiB
PHP
<?php
|
|
use Illuminate\Support\Facades\DB;
|
|
use App\Shared\Context\CompanyContext;
|
|
use App\Modules\Purchasing\SupplierPayables;
|
|
use Tempo\Finance\Payables\Payables;
|
|
|
|
$f=json_decode(file_get_contents($s['root'].'/fixture.json'),true,64,JSON_THROW_ON_ERROR);$scope=$f['scope'];$strategy=$argv[3]??'';
|
|
if(!in_array($strategy,['legacy','page25','page100'],true))throw new LogicException('Unknown isolated read strategy');
|
|
config(['supplier_payable_history.synthetic_enabled'=>true]);$u=App\Models\User::findOrFail($f['actors']['read']);auth()->setUser($u);app(CompanyContext::class)->selectFor($u->id,$scope['tenant_id'],$scope['company_id'],$scope['unit_id']);$service=app(SupplierPayables::class);
|
|
$volume=DB::table('pa_imported_sources')->where($scope)->count();if(!in_array($volume,[51,1000,5000,10000],true))throw new LogicException('Unknown owned benchmark volume');
|
|
// Equal bounded warm-up in every independent PHP worker; no cache flush or server change.
|
|
$service->listing($u,['q'=>'FT-PG-1']);$queries=0;$capture=false;DB::listen(function($q)use(&$queries,&$capture){if($capture)$queries++;});gc_collect_cycles();memory_reset_peak_usage();$base=memory_get_usage(true);$capture=true;$time=hrtime(true);
|
|
if($strategy==='legacy'){$result=$service->engine($u)->listing(DB::table('pa_imported_sources')->where($scope)->pluck('id')->map(fn($id)=>(int)$id)->all());}
|
|
else {$result=$service->listing($u,['per_page'=>$strategy==='page25'?25:100]);}
|
|
$elapsed=(hrtime(true)-$time)/1e6;$capture=false;$peak=memory_get_peak_usage(true);
|
|
$fingerprints=[];
|
|
foreach($strategy==='legacy'?[25,100]:[$strategy==='page25'?25:100] as $size){
|
|
$locals=DB::table('pa_imported_sources')->where($scope)->orderByDesc('id')->limit($size)->pluck('id')->all();$sourceIds=DB::table('pa_sources')->where($scope)->whereIn('local_source_id',$locals)->select('id');$wanted=DB::table('pa_obligations')->where($scope)->whereIn('source_id',$sourceIds)->pluck('id')->all();$set=array_fill_keys($wanted,true);$rows=array_values(array_filter($result['obligations'],fn($o)=>isset($set[$o['id']])));usort($rows,fn($a,$b)=>$a['id']<=>$b['id']);$fingerprints[$size]=hash('sha256',Payables::canonical($rows));
|
|
}
|
|
$report=['volume'=>$volume,'strategy'=>$strategy,'time_ms'=>round($elapsed,3),'queries'=>$queries,'php_heap_baseline_bytes'=>$base,'php_heap_peak_bytes'=>$peak,'php_heap_extra_peak_bytes'=>$peak-$base,'rows'=>['documents'=>count($result['documents']),'obligations'=>count($result['obligations']),'proposals'=>$result['proposals']->count(),'events'=>$result['events']->count()],'position_fingerprints'=>$fingerprints,'php'=>PHP_VERSION,'memory_limit'=>ini_get('memory_limit'),'independent_php_process'=>true,'warmup'=>'Same bounded source search in each worker; seeded PostgreSQL caches; no cache flush.','indices_added'=>false,'not_deployment_capacity'=>true];
|
|
$output=$s['root'].'/bench-'.$volume.'-'.$strategy.'.json';if(is_file($output)){copy($output,$output.'.'.hash_file('sha256',$output).'.archive');}file_put_contents($output,json_encode($report,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR));echo json_encode($report)."\n";
|