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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |