Note that there are some explanatory texts on larger screens.

plurals
  1. POPerl: event-based and parallel-based style - when choose one?
    text
    copied!<p>It`s slightly difficult to ask good questions if you knowledge a small, but I try to be best. My apologies if I mislead you.</p> <p>So, I try to understand generally differences on event-based and parallel-based style. I read question about <a href="https://stackoverflow.com/questions/6133574/how-to-articulate-the-difference-between-asynchronous-and-parallel-programming">How to articulate the difference between asynchronous and parallel programming?</a>, but anyway I confused.</p> <p><strong>Why it is very important to me</strong>:</p> <blockquote> <p>fork() or its analog is a heavy weapon, as I know. It copy data (or share it, but in some case it worst), spawn new process (which may die or something bad happened), have huge problem to return data back to "parent" process and so on. Yes, at CPAN is exists bunch of good designed modules to wrap this problem and give to me smooth interface, but any way fork-style have some overhead.</p> <p>In this case, as I see, I need follow to simply rule - "<em>if you <strong>CAN</strong> solve you problem without fork() or Parallel::* you <strong>MUST NOT</strong> use it, you <strong>SHOULD</strong> use event-based solutions instead</em>"</p> <p>May be I totally wrong there too?</p> </blockquote> <p>Is it right I see:</p> <ul> <li><p>event-based style should be chosen if we are have IO-operations or something, using <strong>external</strong> (to my program) event, like signal, or file changed, or data in pipe and so on</p></li> <li><p>parallel-based style must be chosen if we are have only <strong>internal</strong> (to the program) "event", like subroutine finish calculated.</p></li> </ul> <p>In other word, if I always have subroutine or class method/function and I know it`s have some latency "inside" ( because a lot of calculation or its waiting something - the are no differences ) - I <em>must</em> use parallel-based style only. And no way to use it event-based style, it be worked continuously, because this code will block main program and will block "event flow".</p> <p>And I <em>may</em> use event-based style <strong>only if</strong> I write subroutine or class method/function with "waiting latency inside", when it calling something outside main program.</p> <p>Is it correctly?</p> <p><strong>EDIT:</strong></p> <p>this is pseudo-code for clearance</p> <pre><code># we are CANT re-write this methods, but we are known it`s have latency sub method_with_latency_as_blackbox1{...}; sub method_with_latency_as_blackbox2{...}; my @in_data = (2,3,5); my @out_data; # we are need to run this for each item in @in_data array, somehow # and there we are CAN re-write code to speed up it # by somehow "separating" all block execution for each item # and not method_1* from method_2* - it`s impossible because it related foreach my $ent ( @in_data ){ my $res1 = method_with_latency_as_blackbox1( $ent ); my $res2 = method_with_latency_as_blackbox2( $ent, $res1 ); # yes, it related push @out_data, $res2; # we are not care about result position } </code></pre> <p>how I can use AnyEvent or Coro to speed up code like this one?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload