On Tue, Aug 14, 2018 at 8:34 AM Brion Vibber <bvibber(a)wikimedia.org> wrote:
On Tue, Aug 14, 2018, 3:39 AM Aleksey Bekh-Ivanov
<
aleksey.bekh-ivanov(a)wikimedia.de> wrote:
Hi Brion.
I might be a bit late, but I just wonder why did you decide to go with
forking instead of Pthreads PHP extension?
ForkController and OrderedStreamingForkController were already present and
using pcntl_fork; also I didn't know PHP has a pthreads extension now. :)
Worth looking at...
AFAIK, Mediawiki should support not only *nix
platforms, but Windows as
well, and `pcntl_fork()` does not work on Windows.
If no threads are specified it'll run in-process which will still work,
but of course you get no additional processes then.
I took a quick look at the PHP pthreads extension; it looks interesting,
but looks like it might be trickier to integrate.
Not all of the global environment is available to threads -- only classes
that extend a special Threaded type -- so I think threads would either end
up without the MediaWiki environment, severely limiting what they can do,
or they would have to reinitialize MediaWiki locally.
Also it doesn't seem to be packaged in Debian, so it would be extra work
for us to adopt and package it for production use, and it's less likely to
be present by default in other peoples' operating environments.
If re-initializing the application state is necessary in the threads anyway
without retooling the entire application, it might be easier to use a
separate-process model where the maintenance script is re-invoked with
wfShellExec() with a special child-process mode, and data routed over
stdin/stdout.
In which case it might be more consistent to do that than using
pcntl_fork() to begin with... but I'm not sure how to integrate that into
phpunit tests. :)
PS: Couldn't find related ticket. Can you post a link to it?
No ticket currently, though I can open one. :)
Opened as
https://phabricator.wikimedia.org/T201970 -- if there's more
interest in getting this right I can make this an RFC. (I had an inquiry
about thinking about ways to do multiprocess work from web requests too,
which might not work with pcntl_fork().)
Additional thoughts welcome on pcntl_fork() vs separate process launch vs
something else. :D
-- brion