|go ahead... be a heretic|
Re^3: Create parallel database handles... (MCE::Loop)by 1nickt (Abbot)
|on Apr 14, 2020 at 03:13 UTC||Need Help??|
Hi again perlygapes,
The MCE::Loop code just abstracts away all your Parallel::ForkManager logic and improves it, just as Parallel::ForkManager abstracts away and improves some of the tedious manual work of using fork() directly. See how the logic is encapsulated in a sub just like in your code, only with less concurrency boilerplate.
"using a separate DB connection instead for each child feels intuitively right"
I agree, the code I shared keeps a connection open for each child, which itself stays alive and handles multiple jobs from the job list as managed by MCE.
Here's a simpler example I've shared recently showing how to parallelize existing code for making a series of HTTP requests. How would you do the same using P::FM?
Update: fixed error in first demo code, ++choroba
Hope this helps!
The way forward always starts with a minimal test.