Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Inline::Java with MCE::Hobo

by Fletch (Chancellor)
on May 27, 2021 at 14:31 UTC ( #11133135=note: print w/replies, xml ) Need Help??


in reply to Inline::Java with MCE::Hobo

Untried hunch: Haven't diddled with MCE as much as I'd like to have (possibly should have) but if the problem is that your worker children are inheriting too much context, then rather than pulling in Inline::Java in the parent you might try pushing that out into a separate module which you then require in your on_start handler for your MCE::Hobo workers. That way you're going to be sure that an separate JVM instance and all its associated plumbing is coming up only on the child process side of the fork.

Edit: Derp, I do need to play with MCE more because apparently (re-?)reading the MCE::Hobo docs the on_start callback is called in the parent after a worker is started. Possibly instead then do the require in the sub you pass to the create method instead and that'll still keep it done only in the child.

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^2: Inline::Java with MCE::Hobo
by eraskin (Novice) on May 27, 2021 at 15:06 UTC

    I could not make the require work. First, I removed the "use SexCoder" from the top of my script. Then I added this:

    MCE::Hobo->init(on_start => sub { require SexCoder; });
    The error message I got was:
    Hobo 30016 terminated abnormally: reason Can't locate object method "n +ew" via package "SexCoder" (perhaps you forgot to load "SexCoder"?) a +t ./convert.mce line 721, <__ANONIO__> line 24.

    So, the SexCoder did not load. I then tried removing the Hobo->init and placing "use SexCoder" inside my worker sub {}. That was no different than my original code. I had exactly the same issue, where some workers were able to get results from the service and others were not. That really confuses me. I think you are on the right track, though. There must be something odd in my SexCoder package that I'm not seeing. See my reply to cavac above for the complete code to that package. Maybe you can see something?

    I have one more tidbit for everyone helping me. The code works if $num_workers = 1 (simulating single-threaded code). That's why I suspect an issue with Inline::Java or with the rtsClient itself. I just can't fathom why if each is running in its own process.

      Greetings eraskin,

      Have you tried importing SexCoder inside the input_task Hobo routine. This is where to load the class uniquely per worker child.

      sub input_task { require SexCoder; SexCoder->import(); # THIS CALLS JAVA TO CREATE THE CONNECTION TO DATA SERVICES my $sexcoder = SexCoder->new("$ds_server", 4000); ... }

        Kind reminder: Remember to comment out SexCoder at the top of the script to ensure the class is loaded by each Hobo worker individually.

        my $num_workers = 5; # use SexCoder; use MCE::Hobo; use MCE::Shared; ...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11133135]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2021-10-18 17:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (74 votes). Check out past polls.

    Notices?