jimbus has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I've got a hand full of scripts running in cron on a sun box that basically process log files and insert the digested data into mysql. Things appear to work flawlessly when I run them by hand, but when left alone as cron scripts, I end up with 90 some processes and issues accessing the data in my web app because all connections are used up... Apparently, I'm not all that and a bag of chips :(
Have you guys got any pointers for DBI or cron script best practices?
Thanks,
Jimbus
|
---|
Replies are listed 'Best First'. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Re: cron script best practices
by 5mi11er (Deacon) on Aug 10, 2005 at 20:29 UTC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
If you're not doing that, then you really need to figure out why you get so many processes, because something is pretty obviously broken. Other potential traps to avoid include That's all I can think of for now, hope this helps your situation -Scott | [reply] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
by jimbus (Friar) on Aug 10, 2005 at 21:35 UTC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
reports@clarkkent/home/reports(7): crontab -l 00 06 * * * /home/reports/ftp/SMSC0/loadData.pl 00 06 * * * /home/reports/ftp/MMSC1/loadData.pl 20,35,50,05 * * * * /home/reports/ftp/YTSMSC50/loadData.pl 20,35,50,05 * * * * /home/reports/ftp/FDSMSC/loadData.pl 00 06 * * * /home/reports/ftp/proptima/ftp.pl loadData.pl is the script I'm checking on ("ps -ef|grep loadData|wc -l"). The first two should be running once a day at 6am and the second two every fifteen minutes... which is 96 times each per 24 hour period. I'm assuming the issue is with the second two, which are the same but for different boxes. These scripts digest a log file that is a series of reports from about 12 nodes, each one has between 50 and 225 key and value pairs, one per line. I loop through the nodes, building a hash of the key/value, then build a huge insert based from them... with upto 225 columns, the insert is built dynamically. I have filled /usr a couple times, once recently. I thought things would recover, but I end up with all these processes and mysqld running at 60-70% of cpu. I guess the real thing is I'm resource strapped and perl inexperienced and getting a bit overwhelmed by the amount of data being chucked at me and was hoping to find someone who had documented what it took to write mature cron/logging scripts :) With Perl and JDBC for JSP, I find all kinds of simplest case stuff on the web, but not a lot on what I would think would be typical useage patterns. Thanks,
Jimbus
Never moon a werewolf!
| [reply] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
by anthski (Scribe) on Aug 10, 2005 at 23:09 UTC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Do these scripts need to be run simaltaneously? You could immediately reduce the number of connections to your DB if one script ran, executed, exited, and then the other was fired off. i.e
I've got to ask - do any of your inserts work at all? As mentioned in another response, if your script is working fine from hand but not from cron, it may be an environment issue. I'd modify my cron to something like
and then check the contents of /tmp/env.output and compare them to the output of env when you run it at a command line for any important/potential differences. You could then set these env variables to your perl script. Some other obvious things would be to make sure that you're disconnecting from the db. And if it's not running properly from cron on a regular basis, then run it only once from cron and debug that and ensure that it does run fine from cron, before filling up your cron with multiple runs each hour. Finally, why is your /usr filling up on a regular basis as a result of this script? | [reply] [d/l] [select] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
by polettix (Vicar) on Aug 11, 2005 at 11:37 UTC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Flavio | [reply] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
by Anonymous Monk on Aug 11, 2005 at 13:02 UTC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [reply] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: cron script best practices
by IOrdy (Friar) on Aug 10, 2005 at 23:34 UTC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [reply] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Re: cron script best practices
by chanio (Priest) on Aug 11, 2005 at 04:11 UTC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
If you build good log files (at least updated when in doubt of what your cron is doing), you are going to know exactly what is not working. You could even add a perl script to the crontab that would check the results of your log files and email you about any trouble. Reading some lines of your log files, it is easier to know what is not working, the rest is just guessing.
| [reply] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
by jimbus (Friar) on Aug 11, 2005 at 18:33 UTC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
I'd like to think I'm a reasonable, perhaps even decent debugger... maybe a decent coder with more than 15 years experience. Unfortunately, most of that was as a consultant stuck in situations where I only learned enough of anything well enough to bodge together what I needed to integrate for that customer that week or month. Where I'm having an issue is that when I try too embace a technology, most of the materials available is about 1 + 1 = 2, when I already know that, albiet in another language, and I really want to learn calculus. So, I go about reinventing calculus... poorly. For example, perl cron scripts digesting logs and spewing reports have been around 30+ years and perl has been around for almost 20, this pattern should be well documented. Another example is using JDBC in JSP. I can find ten billion examples of how to do a basic query, but thats not the "correct" way to do things anymore. you're supposed to put the business logic and query code in beans and the presentation layer in the JSP page. Can I find any design patterns or tutorials on this? No, not unless I what to spend 500 pages learning a product like Struts. Anyhow, Chiano, I didn't mean to vent at you and don't think you deserved it... it just happened :). Thanks everyone for your input, you've given me a lot of ideas and I have a few of my own... I'll keep you posted. Thanks, :) Jimbus PS: I should have said I'm filling up /home. I'd thought /home was an alias for /usr/home like in freebsd, but I was mistaken
Never moon a werewolf!
| [reply] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
by chanio (Priest) on Aug 12, 2005 at 02:10 UTC | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
What I find dissapointing of Java is that there is a lot to learn. And that your are never sure that it wouldn't change in the next release. And so much Megas to download! Besides, you are right: perl is McGiver-like, all resourceful. You are able to record the output of every perl script at your crontab in a provisional log file to compare it later with the output that you would get after launching every script from command line. Is it the same? Perl allows us to return to our basical way of solving everything just by trying things out and perhaps, reinventing several wheels. But you don't have to ask for the rules any longer. You create your own rules...
| [reply] |