Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 25th, 2001, 12:43 PM
DeNasio's Avatar
DeNasio DeNasio is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 91 DeNasio User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 h 17 sec
Reputation Power: 8
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?

Reply With Quote
  #2  
Old July 2nd, 2001, 05:08 PM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 10
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

Reply With Quote
  #3  
Old July 3rd, 2001, 02:01 PM
dsb dsb is offline
PerlGuy
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2001
Posts: 714 dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 15 h 44 m 20 sec
Reputation Power: 36
Send a message via AIM to dsb
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

Reply With Quote
  #4  
Old July 3rd, 2001, 04:11 PM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 10
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 .

Reply With Quote
  #5  
Old July 3rd, 2001, 04:14 PM
dsb dsb is offline
PerlGuy
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2001
Posts: 714 dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level)dsb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 15 h 44 m 20 sec
Reputation Power: 36
Send a message via AIM to dsb
Eating up memory is easy enough. The one-liner I used ate up processing power as well. Pretty nifty.

Reply With Quote
  #6  
Old July 3rd, 2001, 07:47 PM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 10
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

Reply With Quote
  #7  
Old July 3rd, 2001, 08:31 PM
footinmouth footinmouth is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: North Vancouver, BC, Canada
Posts: 44 footinmouth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
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

Reply With Quote
  #8  
Old July 4th, 2001, 02:53 PM
linear linear is offline
Embittered Cynic
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: 38.97° N, 94.67° W
Posts: 11 linear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
take a look at sbox.
__________________
+++linear+++
PHP Security Questions? start here

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Scripts that uses too much resources


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT