<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tech Debug &#187; perl</title>
	<atom:link href="http://techdebug.com/blog/category/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://techdebug.com</link>
	<description>Why talk when you can fly</description>
	<lastBuildDate>Thu, 26 Aug 2010 07:30:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Perl while loop memory hog</title>
		<link>http://techdebug.com/blog/2007/10/30/perl-while-loop-memory-hog/</link>
		<comments>http://techdebug.com/blog/2007/10/30/perl-while-loop-memory-hog/#comments</comments>
		<pubDate>Mon, 29 Oct 2007 23:16:57 +0000</pubDate>
		<dc:creator>lantrix</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[IO::file]]></category>
		<category><![CDATA[cpu]]></category>
		<category><![CDATA[hog]]></category>
		<category><![CDATA[openbsd]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://techdebug.com/blog/2007/10/30/perl-while-loop-memory-hog/</guid>
		<description><![CDATA[I was trying to use someone elses script for logging dansguardian events to an RDBMS.The script was chewing up 99% of my CPU! I got chatting to a friend and a perl coder about this, and got some ideas. He showed me about the perl debugger using the -d switch. Awesome. I finally got my [...]]]></description>
			<content:encoded><![CDATA[<p>I was trying to use <a href="http://dansguardian.org/downloads/kusar/sqllogfifo.pl">someone elses script</a> for logging <a href="http://dansguardian.org/?page=extras">dansguardian</a> events to an RDBMS.The script was chewing up 99% of my CPU! I got chatting <a href="http://90kts.com/blog/">to a friend and a perl coder about this</a>, and got some ideas. He showed me about the perl debugger using the -d switch. Awesome. I finally got my perl script working. Installing the DBI package on OpenBSD was a snap with pkg_add (<code>pkg_add -v p5-DBD-Pg-1.47.tgz</code>). My logical debugging was as follows.</p>
<p>first I read that DBI was a memory hog so I wrote it out and put in a native postgres call, but the pgsql for perl was borked.<br />
(comment from coding friend &#8220;DBI is fine man, works for the massess&#8221;). Next I changed the while loop over the the file to a Tail::File method, but the module was badly documenting and had issues.</p>
<p>I actually ended up using IO::File to tail the log and looped over the lines (in a mad loop), but it was still broken.<br />
So I went back to DBI, which as my friend pointed out was never a problem. It worked!</p>
<p>It turned out the loop was the CPU hog and all I had to do was put in a <code>sleep 1;</code> if there was no new line in the tail.<br />
In the process I rewrote the whole script and it barely resembles the original except for the idea. <em>Now it has 0.5% CPU load at best</em>. A win for coding. I&#8217;ll post the script soon and also send it to dansguardian.</p>
<p>Comment from perl coding friend: of course &#8211;  i guessed that after u left. <img src='http://techdebug.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://techdebug.com/blog/2007/10/30/perl-while-loop-memory-hog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
