Click here to get back home

Does sleep increase server load?

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Does sleep increase server load? Jason Carlton 06-19-2008
Posted by Jason Carlton on June 19, 2008, 3:47 pm
Please log in for more thread options
I'm pretty sure that this is a basic question, but I simply don't know
the answer. Does the sleep command increase the server load at all
while running?

The reason I ask, I have a contact form that spam robots typically try
to use to send junk. I have some very basic filters in place that
catch 99.9% of it, which is great, but the robots still waste my
server resources in trying to utilize it. So, I was thinking of
dropping them into a loop; something along the lines of:

if ($spam_criteria eq "true") {
while (1 > 0) {
sleep 200;
}
}

else {
# send email
}

I know that the while statement would use a little of the resources,
but if sleep doesn't then the sleep 200 would at least give the server
a break in between. And when the robots attack, it's usually at a rate
of 5 or 10 per second, so this is significantly better.

But, of course, it only works if sleep 200 doesn't increase the server
load!

TIA,

Jason

Posted by J. Gleixner on June 19, 2008, 4:03 pm
Please log in for more thread options
Jason Carlton wrote:
> I'm pretty sure that this is a basic question, but I simply don't know
> the answer. Does the sleep command increase the server load at all
> while running?
>
> The reason I ask, I have a contact form that spam robots typically try
> to use to send junk. I have some very basic filters in place that
> catch 99.9% of it, which is great, but the robots still waste my
> server resources in trying to utilize it. So, I was thinking of
> dropping them into a loop; something along the lines of:
>
> if ($spam_criteria eq "true") {
> while (1 > 0) {
> sleep 200;
> }
> }
>
> else {
> # send email
> }
>
> I know that the while statement would use a little of the resources,
> but if sleep doesn't then the sleep 200 would at least give the server
> a break in between. And when the robots attack, it's usually at a rate
> of 5 or 10 per second, so this is significantly better.
>
> But, of course, it only works if sleep 200 doesn't increase the server
> load!

It won't "work" because it'll never exit the while. Calling sleep()
will tie up the process, which would be bad if you got a few thousand
requests in a short amount of time. It'd probably be best to
stop processing the message as soon as you determine $spam_criteria
is 'true'.

You could also look at many very good filters that are available,
instead of rolling your own, or using some spam aversion techniques,
like Captcha, or embedding some javasacript in your form to set
a field.

Posted by Ted Zlatanov on June 19, 2008, 4:26 pm
Please log in for more thread options
wrote:

JC> I'm pretty sure that this is a basic question, but I simply don't know
JC> the answer. Does the sleep command increase the server load at all
JC> while running?

No, it just puts the calling process to sleep.

JC> The reason I ask, I have a contact form that spam robots typically try
JC> to use to send junk. I have some very basic filters in place that
JC> catch 99.9% of it, which is great, but the robots still waste my
JC> server resources in trying to utilize it.

sleep() would be the wrong way to handle that, because the connections
will still be coming while you're idle. Better to handle them as soon
as possible. Even better, provide just a mailing address and no contact
form if possible.

Ted

Posted by Jason Carlton on June 19, 2008, 4:48 pm
Please log in for more thread options
> On Thu, 19 Jun 2008 12:47:06 -0700 (PDT) Jason Carlton <jwcarl...@gmail.c=
om> wrote:
>
> JC> I'm pretty sure that this is a basic question, but I simply don't kno=
w
> JC> the answer. Does the sleep command increase the server load at all
> JC> while running?
>
> No, it just puts the calling process to sleep.
>
> JC> The reason I ask, I have a contact form that spam robots typically tr=
y
> JC> to use to send junk. I have some very basic filters in place that
> JC> catch 99.9% of it, which is great, but the robots still waste my
> JC> server resources in trying to utilize it.
>
> sleep() would be the wrong way to handle that, because the connections
> will still be coming while you're idle. =A0Better to handle them as soon
> as possible. =A0Even better, provide just a mailing address and no contac=
t
> form if possible.
>
> Ted


Ahh, good points, from both of you. I do prefer to create my own
processes, mainly for the fun of it, so I might set up a catcha-type
process, instead.

I dread that, though, because some of my site visitors are (please
forgive me) about as dumb as a box of hammers! LOL For instance, I
have a significant portion that don't bother to enter the part of
their email address after the @; they just ASSUME that I would know
who their provider is!

People have taught me a whole new meaning to "keep it at a 3rd grade
level" :-)

Posted by Ted Zlatanov on June 20, 2008, 12:14 pm
Please log in for more thread options
wrote:

JC> Ahh, good points, from both of you. I do prefer to create my own
JC> processes, mainly for the fun of it, so I might set up a catcha-type
JC> process, instead.

Ah, I hate those with a passion.

JC> I dread that, though, because some of my site visitors are (please
JC> forgive me) about as dumb as a box of hammers! LOL For instance, I
JC> have a significant portion that don't bother to enter the part of
JC> their email address after the @; they just ASSUME that I would know
JC> who their provider is!

I don't know the purpose of your setup, but maybe you will have to use
mod_perl to process these forms quickly. It's very efficient with
repeated requests; compared to regular Perl CGI I've experienced a 2-10x
speed improvement. If you can stuff incoming data in a file and then
process it offline as a batch, your form handler just needs to check the
fields so it will be even faster. Finally, you can use Javascript to
validate form fields before they hit the form handler (there are many
such libraries, some decent), which will not eliminate bad data but will
make it less frequent and thus your handler will run less frequently.

JC> People have taught me a whole new meaning to "keep it at a 3rd grade
JC> level" :-)

Yes, unfortunately reality is that most people don't have time or
interest in instructions, they just want to get through the form and go
home to watch TV...

Ted

Similar ThreadsPosted
how to load a picture to an oracle database with the Load a pictureto Oracle with DBI perl module December 3, 2004, 3:37 pm
increase performance June 9, 2005, 3:43 am
Strange speed-increase by separating "if"s July 21, 2005, 11:51 am
Re: need help with a cart I inherited, need to increase number of total characters allowed October 22, 2007, 2:07 am
Re: need help with a cart I inherited, need to increase number of total characters allowed October 22, 2007, 2:13 am
Re: need help with a cart I inherited, need to increase number of total characters allowed October 22, 2007, 10:34 am
Using "Sleep " September 9, 2004, 2:09 pm
Sleep for less than a second? December 2, 2005, 10:30 pm
FAQ 8.16 How can I sleep() or alarm() for under a second? March 3, 2005, 6:03 pm
FAQ 8.16 How can I sleep() or alarm() for under a second? June 7, 2005, 5:03 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap