parallel-functions icon indicating copy to clipboard operation
parallel-functions copied to clipboard

Debugging usage

Open theofidry opened this issue 7 years ago • 7 comments

Moving my question from https://github.com/humbug/box/issues/53#issue-294948638 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 :)

theofidry avatar Feb 12 '18 22:02 theofidry

After giving this some thought, the correct place for a solution may in fact be in amphp/parallel (where you first opened the issue https://github.com/amphp/parallel/issues/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.

trowski avatar Feb 13 '18 01:02 trowski

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 avatar Feb 13 '18 13:02 rybakit

@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

theofidry avatar Mar 01 '18 08:03 theofidry

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 avatar Mar 01 '18 09:03 theofidry

@theofidry Correct. You can implement a Task class instead and use the amphp/parallel API, then it should continue to work.

kelunik avatar Mar 01 '18 09:03 kelunik

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

theofidry avatar Mar 01 '18 09:03 theofidry

Yes, that's definitely easier.

kelunik avatar Mar 01 '18 11:03 kelunik