|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Scripts that uses too much resources
I've just read this on another message board:
"I can run a script that brings down a PIII 900 in minutes with less than 1000 hits per day. Imagine if your script is using a lot of memory or takes 20 sec to complete." Which factors do you have to pay attention to when making a Perl script so that it won't use too much memory? What kind of scripts uses too much system resources? Is the size (in Kb) of a script an important factor? |
|
#2
|
|||
|
|||
|
You don't want to store very much in memory (such as reading entire log files into memory). Also, if you're in a while() loop that goes extremely fast, it might be a good idea to slow it down by using a need select() trick to 'sleep' 1000th of a second each loop (saves a ton of cpu). I'd only do this if time wasn't important, and you had lots of it:
Code:
while(something) {
# do stuff
select(undef, undef, undef, .001); # Sleep for .001 seconds
}
But the biggest thing is reading entire files into memory. Just using a while() loop while reading in a file and process it line-by-line (and thereby 'ditching' each line as soon as that loop is over)
__________________
Jon Coulter ledjon@ledjon.com |
|
#3
|
|||
|
|||
|
At the request of an employer I wrote a script that crashed my companies dev server in a matter of about 6 seconds. I will not post it here because there are some not-so-nice people lurking that would like nothing better than to go be naughty with my script.
However, if you email or IM me, I will share the script with you so that you can see how I did and thus understand very well what sort of measures can be taken to protect system resources.
__________________
- dsb - ![]() Perl Guy |
|
#4
|
|||
|
|||
|
That would be easy to do. Just get it to fill up memory fast (which perl can do very easily) and then try to do processing on whatever it is you used to fill the memory (usually a string), such as many complex regex's in a while() loop. You can crash stuff pretty fast if you want
. |
|
#5
|
|||
|
|||
|
Eating up memory is easy enough. The one-liner I used ate up processing power as well. Pretty nifty.
|
|
#6
|
|||
|
|||
|
Well there are a million ways to do it. Taking all the memory and all the cpu is the fastest way to a crash though
![]() |
|
#7
|
|||
|
|||
|
Or how to stop bad guys
I have tried using :
Code:
use CGI;
$CGI::POST_MAX=1024 * 1; # max 1024 bytes posts
$CGI::DISABLE_UPLOADS = 1; # no uploads -- Smiley = "full-colonD"
on some of my scripts to try and stop "abuse". Any other thoughts welcome. Learning is all about success or failure, defeat, and finding the the ability to ask for help. Is ??? True or False: The web is %80 normal people -- normal cgi scripts work = great ! The web is %15 wrong form submitters people -- normal cgi scripts work = fair or poor! The web is %5 hackers people -- normal cgi scripts work = fail or destroy the integrity of security for %100 ! So: do we create scripts for the %100 based on the %5 ?
__________________
Thanks Foot in Mouth ver 1.2.5 Onion |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Scripts that uses too much resources |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|