Google Answers Logo
View Question
 
Q: Question about Apache 1.2 RLimitCPU directive ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: Question about Apache 1.2 RLimitCPU directive
Category: Computers > Internet
Asked by: davious-ga
List Price: $10.00
Posted: 24 Feb 2004 16:14 PST
Expires: 25 Mar 2004 16:14 PST
Question ID: 310457
I have a question about the RLimitCPU directive documented here:
http://httpd.apache.org/docs/mod/core.html#rlimitcpu

What is the difference between the first and second value and how
would the second value ("the hard limit") come into play and affect
running processes?

It seems if a CGI process uses more CPU time than specified as the
"soft limit", Apache kills the process.  What is the second value for?

Please give a explaination and example of how this works and what each value does.
Answer  
Subject: Re: Question about Apache 1.2 RLimitCPU directive
Answered By: maniac-ga on 24 Feb 2004 17:37 PST
Rated:5 out of 5 stars
 
Hello Davious,

The specific definition of "soft" and "hard" limit may vary with the
operating system you are using. However, the basic definition for
these terms come from Unix (or Linux) systems. For example, searching
for
  man rlimit
provides a variety of references to the functions
  getrlimit
  setrlimit
Using 
  http://www.hmug.org/man/2/setrlimit.html
as an example, scroll down to the explanation of both soft and hard
limits. Specifically it states
  A resource limit is specified as a soft limit and a hard limit.  When a
  soft limit is exceeded a process may receive a signal (for example, if
  the cpu time or file size is exceeded), but it will be allowed to contin-
  ue execution until it reaches the hard limit (or modifies its resource
  limit).  
The CGI process generally cannot increase the hard limit (there IS an
exception for the "root" user).

From what you describe the CGI process appears to be "killed" by the
signal being delivered by exceeding the soft resource limit. If you do
not have a signal handler, the default action indicated in this
reference
  http://www.hmug.org/man/2/sigaction.html
is that the process be killed. In other words, Apache sets the hard
and soft resource limits for the process running the CGI and the limit
will then be enforced by the operating system.

In the reference I used - it states that SIGXCPU is the signal
delivered. If your CGI is written in C (or a similar language) you can
set up a signal handler. The signal handler can then set a flag
indicating the soft limit is exceeded and resume execution. This
allows the main loop of your CGI to take action when this occurs. If
you want to follow up on this alternative, let me know the language so
I can see if you can apply this approach to your CGI and suggest some
methods to implement it.

I provided references for a BSD based system (Mac OS X), but the
behavior is similar in other Unix and Linux systems. For example:
  http://www.die.net/doc/linux/man/man2/getrusage.2.html
describes the similar functions in Linux where the process continues
to get SIGXCPU once a second after exceeding the soft limit (or until
it reaches the hard limit). If it reaches the hard limit, SIGKILL is
delivered (which cannot be stopped).

If you use Microsoft Windows, it appears that Services for Unix also
supports this type of implementation. See
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/itsolutions/interop/unix/sfu/Sfuport.asp
for a description of this support.

As mentioned above, if you are looking for a way to handle the soft
limit within the CGI, please indicate the language being used in a
clarification request. I should be able to describe how to to set up
the signal handler (if feasible).

  --Maniac

Request for Answer Clarification by davious-ga on 25 Feb 2004 15:57 PST
maniac, you can take a stab at this question too if you like:
http://answers.google.com/answers/threadview?id=310817

Clarification of Answer by maniac-ga on 25 Feb 2004 17:50 PST
Hello Davious,

Thank you. I will be looking at it shortly.

  --Maniac
davious-ga rated this answer:5 out of 5 stars
Great answer, thanks.  You saved me a lot of time!

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy