Hi,
I've got a script that loops quite alot of times and well it uses lots of ram... it's tasks is EXTREMELY simple and when i loop only a few times, it uses hardly any ram... so i'm wondering how to use less ram....the script loops many times and runs for hours until out of ram....
so.. i'm running some via cron, and others via screen, but lately i've been running only via cron since last reboot.
I need to know if this is anywhere in the ballbpark of being true....
my script outputs quite alot each time it recurses in the for loop, therefore... i think all this output is like being outputted siltenly since cron is running the script....
is that true? and if it is, that will use quite a bit of ram right?
how would i best minimize the use of ram, like cleaning the output so it's discarded immediately ( and therefore save ram yes or no? I hope i'm not way off base with a total n00b question... )
How to optimize and use LESS ram ?
Moderator: General Moderators
Re: How to optimize and use LESS ram ?
As Feyd says, it's difficult to say without seeing the code. However, it sounds like your script isn't cleaning up after itself properly. You should be calling unset(), mysql_free_result(), imagedestroy() etc when you've finished with resources. Also, make sure the script ends nicely even if something goes wrong .. liberal use of die() will help. If it doesn't, and cron is firing up a new process every so often, then eventually you'll have lots of them running and the server will die.Deseree wrote: I've got a script that loops quite alot of times and well it uses lots of ram... it's tasks is EXTREMELY simple and when i loop only a few times, it uses hardly any ram... so i'm wondering how to use less ram....the script loops many times and runs for hours until out of ram....
Re: How to optimize and use LESS ram ?
onion2k wrote:As Feyd says, it's difficult to say without seeing the code. However, it sounds like your script isn't cleaning up after itself properly. You should be calling unset(), mysql_free_result(), imagedestroy() etc when you've finished with resources. Also, make sure the script ends nicely even if something goes wrong .. liberal use of die() will help. If it doesn't, and cron is firing up a new process every so often, then eventually you'll have lots of them running and the server will die.Deseree wrote: I've got a script that loops quite alot of times and well it uses lots of ram... it's tasks is EXTREMELY simple and when i loop only a few times, it uses hardly any ram... so i'm wondering how to use less ram....the script loops many times and runs for hours until out of ram....
exactly, i've got MANY of them running in "ps" showing right now, but how about the output?
What i'm moST worried about is the echo "" commands i'm sending text and html to the browser, and when i'm running in cron, WHERE does that output go?
IF I run the script via ssh, it outputs so much that after one hour, ONE browser ( IEXPLORER ) is upto 800 mb ram usage. now I've got 2 gb ram in my linux server and like 60 of these scripts running in "ps" right now, and the ram usage ATM is 1.5 gb ram, BUT sometimes it spikes to 2.5 gb ram ( 500-600 mb from swap ).
k yea, i just added a global variable so i can turn off output when using via cron!!!feyd wrote:If you intend to run it without using the output, don't have output.
as far as this goes....
Code: Select all
unset()
mysql_free_result()
imagedestroy()
die()And the command
Code: Select all
exit;I've also got everything separated into functions, and i believe after a function is finished running, it destroy's all data right? Since everything in a function is local...
and my sql statements are all $sql = , so i don't think unset is needed since each time sql calls, it overwrites the same variable, correct me if i'm wrong.
also, if i put ob_start() at the beginning of the script, and then ob_clean() every for loop...... do you get where i'm heading, is ob_ going to work throughout the main and functions?
like:
Code: Select all
ob_start() // AT THE ABSOLUTE BEGINNING
here is the main coding....
do_this_1000_times()
blah blah blah
morefucntions()
etc...
ob_end_clean() // I think this wipes any output and ends the ob call without outputting anything..... . but everything was still ran just OUTPUT was suppressed right? any filecreation i had going did ok right?, wasn't effected?
fucntion do_this_1000_times()
{
ob_clean();
do whatever you need here
ob_clean();
}
rest of fuctions down here....