Re: FCGI process handling and fine-tunning for saving CPU, under Perl code

Chris Lightfoot <[email protected]>
Newsgroups gmane.comp.web.fastcgi.devel
Message-ID <[email protected]>
On Fri, Dec 02, 2005 at 03:56:43PM -0200, phoenix_fly wrote:
    [...]
> > > how to handle it, I mean, how do I restart the processes
> > > when I update the script code? How do I know the number of
> > > the process??
> >
> > Two options: you can have the mod_fastcgi process manager
> > (if you use that) notice when your script file is updated
> > on disk and then automatically restart it when it is
> > (assuming you can switch that option on); this is limited
> > by the fact that it only checks your main script file, so
> > if you have modules which you also change, this won't help
> > you.
> 
> I am not aware I have a mod_cgi process manager installed, but in fact, this
> correlate updates happen just all the time. So I really will need to
> kill/restart through the shell.

OK -- in that case you're probably best off making your
fastcgi servers daemon processes listening on a specific
(UNIX or TCP) port, and have the webserver talk to them.

> Alternatively, you can check the timestamp on your
> > script files in your main loop. We have code to do this
> > here:
> >
> https://secure.mysociety.org/cvstrac/getfile/mysociety/perllib/mySociety/Wat
> chUpdate.pm
> > though it's a little ugly.
> 
> I have tried to use it, but for some reason it didn´t work, I mean, the
> script stopped working after including the code calling the module. Also, I
> fear that this verification will consume precious CPU, maybe it´s better to
> restart/kill the processes myself, as soon as I know how to do that.

Well, possibly, but checking the timestamps on the files
oughtn't to use very much CPU. E.g:

$ time perl -e ''
real    0m0.004s
user    0m0.003s
sys     0m0.001s
$ time perl -e 'for (my $i = 0; $i < 10000; ++$i) { my $s = stat "/etc/passwd"; }'
real    0m0.034s
user    0m0.013s
sys     0m0.020s


> > > My main goal with FCGI is to save precious CPU minutes,
> > > as the traffic is increasing a lot (and my host will kick
> > > me out if I get too heavy-processing, as they just dont
> > > have dedicated servers available). You guys know if the
> > > CPU savings are worth adapting the code? I mean, can I
> > > expect to use, like, 30% less CPU?
> >
> > That depends on the startup cost of your program vs the
> > marginal cost of serving one request, basically. Without
> > knowing any more detail it's impossible to comment; really
> > you need to measure it now and decide whether it's
> > worthwhile.
> 
> All scripts load 5 method libraries with more than 10 thousand lines total,
> and connect to mysql before doing anything. So FCGI it may be a good thing
> to save CPU, right? You´d say I can save 50% CPU?

Without seeing any measurements, no, I can't say that, but
the measurements are pretty easy to do!

-- 
``Some circumstantial evidence is very strong,
  as when one finds a trout in the milk.'' (Thoreau)
___________________________________
fastcgi-developers mailing list
http://fastcgi.com/fastcgi-developers/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.