The "recommended way" depends a lot on what your application is actually trying to accomplish.

Event-driven HTTP servers work best when the web requests are quick or mostly waiting on other servers (such as a database)

Forking HTTP servers work best when the code that serves requests uses blocking APIs, or when the request needs to do a lot of processing.

Perl has a single-threaded design, so if you have two distinct tasks you want it to do like 1) respond to external events (like HTTP requests) and 2) run a big complex calculation, the best way to do it is to have two completely different programs doing these things. One program could spawn the other and manage it as a process parent, or you can run them both from some sort of service manager like Systemd or Docker or Runit.

If the most important task is the big calculation, and you want to be able to check on its status using HTTP, then consider just generating a detailed log file from the calculation and let the HTTP server report info parsed from the log.

If the most important task is responding to HTTP, and sometimes the http requests need to kick off a long-running background job, consider a task server like Minion.


In reply to Re: 'background' CPU process when Idle in AnyEvent by NERDVANA
in thread 'background' CPU process when Idle in AnyEvent by sectokia

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.