Debugging usage
theofidry opened this issue · 7 comments
Moving my question from box-project/box#53 (comment) to here.
I think it would be good if it would be possible to easily switch from parallelMap()
to a plain old array_map()
, be it for debugging purposes or simply because in a special case parallelMap()
is not working e.g. when the passed argument is not serializable.
Maybe an env variable would work, the inconvenient being it's gonna rely on global state, the benefit is would be easier and won't require much changes.
On the same token, the major downside I have with this library is the inability to use break points for the paralellised work. Would make it work?
If you have some insight regarding this that would be greatly appreciated, otherwise I'll try to give it a stab in the coming months :)
After giving this some thought, the correct place for a solution may in fact be in amphp/parallel
(where you first opened the issue amphp/parallel#39).
We already use an environment variable (or constant) AMP_DEBUG
to turn on certain debugging features in amphp/amp
. I think a similar constant such as AMP_PARALLEL_DEBUG
may be a good idea. What I'm thinking is for this flag to cause DefaultWorkerFactory
to return a worker that uses a context that executes in the same process. This way breakpoints could be set within Task
implementors (parallelMap()
is executed by a class implementing Task
). That class already uses another such flag, AMP_PHP_BINARY
, that can be set to define a specific path to the PHP executable binary.
I'm not sure if AMP_PARALLEL_DEBUG
is really needed. At least PHPStorm allows you to debug multiple processes simultaneously, check this manual: https://confluence.jetbrains.com/display/PhpStorm/Simultaneous+debugging+sessions+with+PhpStorm. Works like a charm for me.
@rybakit mind to share you configuration? Because I can't it get working. Whenever the breakpoint is in a function executed by the worker in another process the breakpoint is never hit
I've just thought about it: @rybakit is kinda right. What is not working is a breakpoint inside the payload: I think it's because the function is serialiazed/unserialized it's no longer able to pick up where it's coming from :/
@theofidry Correct. You can implement a Task
class instead and use the amphp/parallel
API, then it should continue to work.
Wouldn't it be easier then to simply call the callable in parallel()
?
As the main point here is to not serialize, if we were to try to use the works & co. still it means creating a new task & context to execute the task within the same process. That's a non-negligeable amount of work and I'm not sure there's any benefit in it. The point of this debugging mode is more being able to debug the callable not execute the whole amphp toolchain
Yes, that's definitely easier.