1

Should a daemon, forked from a CGI script (whenever the CGI script is called and the daemon is not yet running), hang running (most of the time just waiting for a connection) all time, or should it be terminated as soon as there is no more data to process (to be restarted by the next CGI call)? (The process is a Perl script.)

This happens on FreeBSD.

The details of what I am going to implement are available at Writing a daemon behind CGI: WebSocket or long polling question.

porton
  • 752
  • 1
  • 7
  • 20
  • Do you have any criteria for evaluating your decision? Are you running out of memory, for example? – Robert Harvey Jul 14 '16 at 13:33
  • @RobertHarvey No, I asked for such a criteria. I think our server has plenty of memory – porton Jul 14 '16 at 13:36
  • 1
    I edited the title of your post to more correctly reflect the question that I think you're asking. Feel free to re-edit or roll back if that's not your actual question. – Robert Harvey Jul 14 '16 at 13:38
  • 1
    Please improve your question by explaining what your CGI is doing, and what is the daemon doing. Give some motivation and context (so **edit your question**) – Basile Starynkevitch Jul 14 '16 at 16:55
  • @BasileStarynkevitch Done – porton Jul 14 '16 at 18:36
  • A reason to terminate the script when there is no data to process right now is that it simplifies debugging as I do not need to kill the script after every change in its cod – porton Jul 14 '16 at 22:27
  • As soon as it starts, there are no yet any connections. So it could exit immediately and thus does not work at all, if it exited on the event of no connections. This is an argument to keep it running persistently. – porton Jul 15 '16 at 19:59

1 Answers1

1

It looks like your situation is a good candidate for (at least) FastCGI, or perhaps making some dedicated HTTP server (perhaps using some HTTP server library like libonion) that your main web server would use as "proxy" for some selected requests or URLs.

There is also the issue about what kind of state should the daemon keep from one CGI request to the next one.

Intuitively, you could use as criteria to stop your daemon after a few minutes (real-time) of inactivity.

(You definitely should give more details and motivations)

Basile Starynkevitch
  • 32,434
  • 6
  • 84
  • 125