in reply to Re: Getting query string with CGI::Fast
in thread Getting query string with CGI::Fast

Thank you so much for your explanation on the "while" vs "if" condition and for your beautiful code - as someone who writes procedural code, I never quite get round to switching to object-oriented. Will try to learn (and adapt) from yours.

I have a question about persistence. Suppose the module Myapp uses other modules, are these other modules also stored in memory so they are not loaded for every request?

  • Comment on Re^2: Getting query string with CGI::Fast

Replies are listed 'Best First'.
Re^3: Getting query string with CGI::Fast
by hippo (Archbishop) on Jul 28, 2020 at 10:21 UTC
    Suppose the module Myapp uses other modules, are these other modules also stored in memory so they are not loaded for every request?

    Short answer: yes.

    Any module which a script uses is loaded into memory at compile time, including all the modules used by those modules and so on. This memory stays used until the script exits. For long-running scripts such as those under FCGI this means that all those modules remain in memory for a long time. Each web request to your FCGI script will either encounter an existing FCGI process where all those modules are ready and therefore have no startup penalty or occasionally will have to spin up a fresh FCGI process which will take longer because it loads all the modules.

    You can manage this somewhat by loading modules on demand at run-time instead of at compile time. Suppose there's a task your script will need to perform only once in every 10,000 runs and which needs a heavy module. You would not necessarily want that module taking up lots of RAM unnecessarily for 9,999 runs when it isn't needed. This sort of memory and process management is something you will probably want to consider if you are going to use FCGI (or any other persistent back-end) for serious purposes.


    🦛

      I'm using shared hosting. Being new to FCGI, I have absolutely no idea how things would turn out when and if I put the code to use. For the time being, I have the non-FCGI version but have known for a long time FCGI would make things faster. Does the persistence automatically go away after some time of inactivity? Like no request for a certain number of minutes?

        Ordinarily, yes. If you are on shared hosting then I would say definitely so. Your hosting providers will not want shared resources taken up doing nothing. There will also be a maximum number of requests served by any one instance in order to mitigate memory leaks.


        🦛