pmmp / ext-pmmpthread

Fork of https://github.com/krakjoe/pthreads with a revamped API and PHP 8.1+ support
Other
81 stars 15 forks source link

Slow Pool::submit #63

Open JunoBoom opened 3 years ago

JunoBoom commented 3 years ago

Environment

Summary

Pool::Submit takes around 0.02sec for each thread. Each iteration of my foreach loop takes 0.002seconds until getting to Pool::Submit line, where time increases 10fold for each iteration, going up from 0.002 to 0.02 average .

Reproducing Code

$ProfilesThreadsPool = new \Pool($ProfilesLimit);
$AllProfilesThreads = [];
$SelectedActivePool = $SelectedProfiles = [];

for ($j = 0; $j < count($OpenTasks); $j++) {
/// Lots of Random Code Before Submitting Thread///
///////////////////////////////////////////////////
$SelectedProfiles = array_merge($SelectedProfiles, array_column($ChunkedProfiles, 'id'));
$CurrentProfileThread = new MultiThreadProfiles($ChunkedProfiles, $ActiveProfile);
$AllProfilesThreads[] = $CurrentProfileThread;
$ProfilesThreadsPool->submit($CurrentProfileThread);
{

Expected Output

Expected thread creation time under 0.002sec

Actual Output

Each thread submit takes 0.02sec .

JunoBoom commented 3 years ago

Enabling opcache.enable_cli=1 seems to partially have fixed the Pool::Submit slowness with some of the threads submitted but created a new issue :

zend_mm_heap corrupted Segmentation fault

dktapps commented 3 years ago

Hi, this fork of pthreads is specifically intended for PocketMine-MP usage, and PM doesn't use Pool, so this is unlikely to get fixed.