<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>/contrib/famzah</title>
	<atom:link href="http://blog.famzah.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.famzah.net</link>
	<description>Enthusiasm never stops</description>
	<lastBuildDate>Tue, 07 Sep 2010 11:33:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blog.famzah.net' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/927def57f5a97d59e700bb7603b9a1f8?s=96&#038;d=http://s2.wp.com/i/buttonw-com.png</url>
		<title>/contrib/famzah</title>
		<link>http://blog.famzah.net</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.famzah.net/osd.xml" title="/contrib/famzah" />
	<atom:link rel='hub' href='http://blog.famzah.net/?pushpress=hub'/>
		<item>
		<title>Google App Engine &#8211; Datastore performance, and Memcache behavior</title>
		<link>http://blog.famzah.net/2010/08/31/google-app-engine-datastore-performance-and-memcache-behavior/</link>
		<comments>http://blog.famzah.net/2010/08/31/google-app-engine-datastore-performance-and-memcache-behavior/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 15:26:36 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[appengine datastore]]></category>
		<category><![CDATA[appengine memcache]]></category>
		<category><![CDATA[google appengine]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=862</guid>
		<description><![CDATA[Ever since I&#8217;ve been working with Google App Engine, there are two issues which bothered me a lot: Datastore performance &#8211; lots of people have already written about it (see links #1, #2, and #3). Currently, when working with small datasets, it&#8217;s far from being comparable even with a slow MySQL database, and you may [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=862&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Ever since I&#8217;ve been working with <a href="http://code.google.com/intl/bg/appengine/">Google App Engine</a>, there are two issues which bothered me a lot:</p>
<ol>
<li><a href="http://code.google.com/intl/bg/appengine/docs/python/datastore/overview.html">Datastore</a> performance &#8211; lots of people have already written about it (see links <a href="http://3.14.by/en/read/why-google-appengine-sucks">#1</a>, <a href="http://stackoverflow.com/questions/1902944/benchmarks-for-various-google-app-engine-datastore-operations">#2</a>, and <a href="http://code.google.com/status/appengine/">#3</a>). Currently, when working with small datasets, it&#8217;s far from being comparable even with a slow MySQL database, and you may also occasionally get internal errors, as well as increased latencies. I contacted Google about this, and asked them if the <a href="http://code.google.com/intl/bg/appengine/business/">Business customers of GAE</a> who pay for it would get better Datastore performance. Here is what I got as an answer from <a href="http://blog.notdot.net/">Nick Johnson</a>, a GAE developer:<br />
<blockquote><p>Business customers will receive paid support, which is prioritized, as well as the extra features we announced at I/O. System latency is not any different, however, as we try and make the system as fast as possible for all our users.</p></blockquote>
<p>So the bad news is that you cannot make the Datastore run faster, even if you pay.<br />
The good news is that we are all getting the same service in terms of speed, which is a good thing &#8211; when everybody is having difficulties, then the community will eventually find a solution.
</li>
<li><a href="http://code.google.com/intl/bg/appengine/docs/python/memcache/">Memcache</a> fairness &#8211; what happens if another website (on the same server) uses the Memcache service extensively, thus making the Memcache entries of my website expire too quickly, due to the memory pressure. Here is what Nick Johnson from Google replied:<br />
<blockquote><p>Memcache is segmented by application. Although there is some variation (so that apps that don&#8217;t use any memcache don&#8217;t take up usable space), every app is guaranteed a fair share of memcache space.</p></blockquote>
<p>Excellent system design GAE engineers. Keep up the good work!
</li>
</ol>
<p><strong>Update</strong>: Google App Engine engineers continue to do a very good work indeed! You should take a look at the new features announced with the <a href="http://googleappengine.blogspot.com/2010/08/multi-tenancy-support-high-performance_17.html">1.3.6 release of GAE</a>.</p>
<br />Filed under: <a href='http://blog.famzah.net/category/development/'>Development</a> Tagged: <a href='http://blog.famzah.net/tag/appengine-datastore/'>appengine datastore</a>, <a href='http://blog.famzah.net/tag/appengine-memcache/'>appengine memcache</a>, <a href='http://blog.famzah.net/tag/google-appengine/'>google appengine</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/862/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/862/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/famzah.wordpress.com/862/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/famzah.wordpress.com/862/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/famzah.wordpress.com/862/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/famzah.wordpress.com/862/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/famzah.wordpress.com/862/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/famzah.wordpress.com/862/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/famzah.wordpress.com/862/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/famzah.wordpress.com/862/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/famzah.wordpress.com/862/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/famzah.wordpress.com/862/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/famzah.wordpress.com/862/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/famzah.wordpress.com/862/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=862&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2010/08/31/google-app-engine-datastore-performance-and-memcache-behavior/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>USB: rejected 1 configuration due to insufficient available bus power</title>
		<link>http://blog.famzah.net/2010/08/11/usb-rejected-1-configuration-due-to-insufficient-available-bus-power/</link>
		<comments>http://blog.famzah.net/2010/08/11/usb-rejected-1-configuration-due-to-insufficient-available-bus-power/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 09:10:10 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Bifferboard]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[usb]]></category>
		<category><![CDATA[usb external power]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=851</guid>
		<description><![CDATA[If your USB device is not being recognized, execute the command &#8220;dmesg&#8221; and check if the following output is there: usb 1-1.4: rejected 1 configuration due to insufficient available bus power The &#8220;1-1.4&#8243; ID may be different for your configuration. If, and only if, you are absolutely sure that your USB hub and/or hardware configuration [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=851&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If your USB device is not being recognized, execute the command &#8220;<a href="http://en.wikipedia.org/wiki/Dmesg">dmesg</a>&#8221; and check if the following output is there:</p>
<blockquote><p>usb 1-1.4: rejected 1 configuration due to insufficient available bus power</p></blockquote>
<p>The &#8220;1-1.4&#8243; ID may be different for your configuration.</p>
<p>If, and only if, you are absolutely sure that your USB hub and/or hardware configuration have a safe way to actually supply enough power, you can override this barrier and force the device to be activated despite of the error message. A possible situation is where you manually applied 5V external power on your USB device and/or USB hub, like I did on my <a href="http://bifferos.bizhat.com/">Bifferboard</a>.</p>
<p>Here is how you can override the power safety mechanism:</p>
<blockquote><p>echo 1 &gt; /sys/bus/usb/devices/1-1.4/bConfigurationValue</p></blockquote>
<p>Replace &#8220;1-1.4&#8243; with your USB device ID. Be careful and have fun!</p>
<hr />
<p>Resources:</p>
<ul>
<li><a href="http://rt2x00.serialmonkey.com/phpBB/viewtopic.php?f=5&amp;t=5459">Error insufficient available bus power RT2573</a>.</li>
</ul>
<br />Filed under: <a href='http://blog.famzah.net/category/bifferboard/'>Bifferboard</a>, <a href='http://blog.famzah.net/category/hardware/'>Hardware</a>, <a href='http://blog.famzah.net/category/linux/'>Linux</a> Tagged: <a href='http://blog.famzah.net/tag/linux/'>Linux</a>, <a href='http://blog.famzah.net/tag/usb/'>usb</a>, <a href='http://blog.famzah.net/tag/usb-external-power/'>usb external power</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/851/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/851/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/famzah.wordpress.com/851/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/famzah.wordpress.com/851/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/famzah.wordpress.com/851/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/famzah.wordpress.com/851/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/famzah.wordpress.com/851/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/famzah.wordpress.com/851/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/famzah.wordpress.com/851/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/famzah.wordpress.com/851/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/famzah.wordpress.com/851/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/famzah.wordpress.com/851/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/famzah.wordpress.com/851/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/famzah.wordpress.com/851/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=851&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2010/08/11/usb-rejected-1-configuration-due-to-insufficient-available-bus-power/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>Secure NAS on Bifferboard running Debian</title>
		<link>http://blog.famzah.net/2010/08/08/secure-nas-on-bifferboard-running-debian/</link>
		<comments>http://blog.famzah.net/2010/08/08/secure-nas-on-bifferboard-running-debian/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 12:39:06 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Bifferboard]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[openssh]]></category>
		<category><![CDATA[nas]]></category>
		<category><![CDATA[NFS over SSH]]></category>
		<category><![CDATA[rsnapshot]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=841</guid>
		<description><![CDATA[This NAS solution uses OpenSSH for secure transport over a TCP connection, and NFS to mount the volume on your local computer. The hardware of the NAS server is the low-cost Bifferboard. I&#8217;m using an external hard disk via USB which is partitioned in two parts &#8211; /dev/sda1 (1GB) and the rest in /dev/sda2. Once [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=841&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This <a href="http://en.wikipedia.org/wiki/Network-attached_storage">NAS</a> solution uses <a href="http://www.openssh.com/">OpenSSH</a> for secure transport over a TCP connection, and <a href="http://en.wikipedia.org/wiki/Network_File_System_%28protocol%29">NFS</a> to mount the volume on your local computer. The hardware of the NAS server is the low-cost <a href="http://bifferos.bizhat.com/">Bifferboard</a>.</p>
<p>I&#8217;m using an external hard disk via USB which is partitioned in two parts &#8211; /dev/sda1 (1GB) and the rest in /dev/sda2. Once you have installed <a href="http://blog.famzah.net/2009/11/20/running-debian-on-bifferboard/">Debian on Bifferboard</a>, here are the commands which further transform your Bifferboard into a secure NAS:</p>
<pre class="brush: bash;">
apt-get update
apt-get -y install nfs-kernel-server

vi /etc/default/nfs-common
  # update: STATDOPTS='--port 2231'
vi /etc/default/nfs-kernel-server
  # update: RPCMOUNTDOPTS='-p 2233'

mkdir -m 700 /root/.ssh
  # add your public key for &quot;root&quot; in /root/.ssh/authorized_keys

echo '/mnt/storage 127.0.0.1(rw,no_root_squash,no_subtree_check,insecure)' &gt;&gt; /etc/exports
mkdir /mnt/storage
chattr +i /mnt/storage # so that we don't accidentally write there without a mounted volume

cat &gt; /etc/rc.local &lt;&lt;EOF
#!/bin/bash

# allow only SSH access via the network
/sbin/iptables -P FORWARD DROP
/sbin/iptables -P INPUT DROP
/sbin/iptables -A INPUT -i lo -j ACCEPT
/sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT
/sbin/iptables -A INPUT -p tcp -m state --state ESTABLISHED -j ACCEPT # TCP initiated by server
/sbin/iptables -A INPUT -p udp -m state --state ESTABLISHED -j ACCEPT # DNS traffic

# mount the storage volume here, so that any errors with it don't interfere with the system startup
/bin/mount /dev/sda2 /mnt/storage
/etc/init.d/nfs-kernel-server restart
EOF

# allow only public key authentication
fgrep -i -v PasswordAuthentication /etc/ssh/sshd_config &gt; /tmp/sshd_config &amp;&amp; \
  mv -f /tmp/sshd_config /etc/ssh/sshd_config &amp;&amp; \
  echo 'PasswordAuthentication no' &gt;&gt; /etc/ssh/sshd_config

reboot
</pre>
<p>There are two things you should consider with this setup:</p>
<ol>
<li>You must trust the &#8220;root&#8221; user who mounts the directory! They have full shell access to your NAS.</li>
<li>A not-so-strong SSH encryption cipher is used, in order to improve the <a href="http://blog.famzah.net/2010/06/11/openssh-ciphers-performance-benchmark/">performance of the SSH transfer</a>.</li>
</ol>
<p>On the machine which is being backed up, I use the following script which mounts the NAS volume, starts the <a href="http://www.rsnapshot.org/">rsnapshot</a> backup process and finally unmounts the NAS volume:</p>
<pre class="brush: bash;">
#!/bin/bash
set -u

HOST='192.168.100.102'
REMOTEPORT='22'
REMOTEDIR='/mnt/storage'
LOCALDIR='/mnt/storage'
SSHKEY='/home/famzah/.ssh/id_rsa-home-backups'

echo &quot;Mounting NFS volume on $HOST:$REMOTEPORT (SSH-key='$SSHKEY').&quot;
N=0
for port in 2049 2233 ; do
	N=$(($N + 1))
	LPORT=$((61000 + $N))
	ssh -f -i &quot;$SSHKEY&quot; -c arcfour128 -L 127.0.0.1:&quot;$LPORT&quot;:127.0.0.1:&quot;$port&quot; -p &quot;$REMOTEPORT&quot; &quot;root@$HOST&quot; sleep 600d
	echo &quot;Forwarding: $HOST: Local port: $LPORT -&gt; Remote port: $port&quot;
done
sudo mount -t nfs -o nfsvers=2,proto=tcp,rsize=8192,wsize=8192,intr,rw,bg,port=61001,mountport=61002 &quot;127.0.0.1:$REMOTEDIR&quot; &quot;$LOCALDIR&quot;

echo &quot;Doing backup.&quot;
time sudo /usr/bin/rsnapshot weekly

echo &quot;Unmounting NFS volume and closing SSH tunnels.&quot;
sudo umount &quot;$LOCALDIR&quot;
for pid in $(ps axuww|grep ssh|grep 6100|grep arcfour|grep -v grep|awk '{print $2}') ; do
	kill &quot;$pid&quot; # possibly dangerous...
done
</pre>
<hr />
<p>Resources:</p>
<ul>
<li><a href="http://www.howtoforge.com/nfs_ssh_tunneling">Tunneling NFS over SSH &laquo; HowtoForge</a>.</li>
</ul>
<br />Filed under: <a href='http://blog.famzah.net/category/bifferboard/'>Bifferboard</a>, <a href='http://blog.famzah.net/category/linux/'>Linux</a> Tagged: <a href='http://blog.famzah.net/tag/bifferboard/'>Bifferboard</a>, <a href='http://blog.famzah.net/tag/debian/'>debian</a>, <a href='http://blog.famzah.net/tag/nas/'>nas</a>, <a href='http://blog.famzah.net/tag/nfs-over-ssh/'>NFS over SSH</a>, <a href='http://blog.famzah.net/tag/openssh/'>openssh</a>, <a href='http://blog.famzah.net/tag/rsnapshot/'>rsnapshot</a>, <a href='http://blog.famzah.net/tag/ssh/'>ssh</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/841/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/841/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/famzah.wordpress.com/841/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/famzah.wordpress.com/841/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/famzah.wordpress.com/841/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/famzah.wordpress.com/841/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/famzah.wordpress.com/841/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/famzah.wordpress.com/841/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/famzah.wordpress.com/841/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/famzah.wordpress.com/841/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/famzah.wordpress.com/841/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/famzah.wordpress.com/841/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/famzah.wordpress.com/841/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/famzah.wordpress.com/841/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=841&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2010/08/08/secure-nas-on-bifferboard-running-debian/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>Beware of leading zeros in Bash numeric variables</title>
		<link>http://blog.famzah.net/2010/08/07/beware-of-leading-zeros-in-bash-numeric-variables/</link>
		<comments>http://blog.famzah.net/2010/08/07/beware-of-leading-zeros-in-bash-numeric-variables/#comments</comments>
		<pubDate>Sat, 07 Aug 2010 12:40:48 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bash force decimal representation]]></category>
		<category><![CDATA[bash remove leading zeros]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=831</guid>
		<description><![CDATA[Suppose you have some (user) value in a numeric variable with leading zeros. For example, you number something with zero-padded numbers consisting of 3 digits: 001, 002, 003, and so on. This label is assigned to a Bash variable, named $N. Until the numbers are below 008, and until you use the variable only in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=831&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Suppose you have some (user) value in a numeric variable with leading zeros. For example, you number something with zero-padded numbers consisting of 3 digits: 001, 002, 003, and so on. This label is assigned to a Bash variable, named $N.</p>
<p>Until the numbers are below 008, and until you use the variable only in text interpolations, you&#8217;re safe. For example, the following works just fine:</p>
<div class="sourcecode">
<pre class="brush: bash; light: true;">
N=016
echo &quot;Value: $N&quot;
# result is &quot;016&quot;
</pre>
</div>
<p>However&#8230; <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
If you start using this variable as a numeric variable in arithmetics, then you&#8217;re in trouble. Here is an example:</p>
<div class="sourcecode">
<pre class="brush: bash; light: true;">
N=016
echo $((N + 2))
# result is 16, not 18, as expected!
printf %d &quot;$N&quot;
# result is 14, not 16, as expected!
</pre>
</div>
<p>You probably already see the pattern &#8211; <strong>&#8220;016&#8243;</strong> is not treated as a <strong>decimal number</strong>, but as an <strong>octal</strong> one. Because of the leading zero. This is explained in the <a href="http://www.gnu.org/software/bash/manual/bashref.html#Shell-Arithmetic">man page of bash</a>, section &#8220;ARITHMETIC EVALUATION&#8221; (aka. &#8220;Shell Arithmetic&#8221;).</p>
<p>In order to <strong>force decimal representation and as a side effect also remove any leading zeros for a Bash variable</strong>, you need to treat it as follows:</p>
<div class="sourcecode">
<pre class="brush: bash; light: true;">
N=016
N=$((10#$N)) # force decimal (base 10)
echo $((N + 2))
# result is 18, ok
printf %d &quot;$N&quot;
# result is 16, ok
</pre>
</div>
<p>Note also that there&#8217;s another caveat &#8211; forcing the number to decimal base 10 doesn&#8217;t actually validate that it contains only [0-9] characters. Read the very last paragraph of the <a href="http://www.gnu.org/software/bash/manual/bashref.html#Shell-Arithmetic">man page of bash</a>, section &#8220;ARITHMETIC EVALUATION&#8221; (aka. &#8220;Shell Arithmetic&#8221;), for more details on how digits can be represented by letters and symbols. My tests however show that you can&#8217;t operate with invalid numbers in base 10, though I&#8217;m no expert here. In order to be on the safe side, I would suggest that you validate your numbers with a strict regular expression, just in case, and if you don&#8217;t trust the data input.</p>
<hr />
<p>Resources:</p>
<ul>
<li><a href="http://zcentric.com/2010/03/12/remove-leading-0s-in-bash/">Remove Leading 0’s in Bash &laquo; Mike Zupan&#8217;s Random Blog</a></li>
</ul>
<br />Filed under: <a href='http://blog.famzah.net/category/development/'>Development</a>, <a href='http://blog.famzah.net/category/linux/'>Linux</a> Tagged: <a href='http://blog.famzah.net/tag/bash/'>bash</a>, <a href='http://blog.famzah.net/tag/bash-force-decimal-representation/'>bash force decimal representation</a>, <a href='http://blog.famzah.net/tag/bash-remove-leading-zeros/'>bash remove leading zeros</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/831/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/831/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/famzah.wordpress.com/831/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/famzah.wordpress.com/831/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/famzah.wordpress.com/831/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/famzah.wordpress.com/831/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/famzah.wordpress.com/831/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/famzah.wordpress.com/831/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/famzah.wordpress.com/831/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/famzah.wordpress.com/831/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/famzah.wordpress.com/831/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/famzah.wordpress.com/831/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/famzah.wordpress.com/831/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/famzah.wordpress.com/831/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=831&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2010/08/07/beware-of-leading-zeros-in-bash-numeric-variables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>Validator for the Model key_name property in Google App Engine datastore (Python)</title>
		<link>http://blog.famzah.net/2010/08/04/validator-for-the-model-key_name-property-in-google-app-engine-datastore-python/</link>
		<comments>http://blog.famzah.net/2010/08/04/validator-for-the-model-key_name-property-in-google-app-engine-datastore-python/#comments</comments>
		<pubDate>Wed, 04 Aug 2010 11:54:59 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[google datastore]]></category>
		<category><![CDATA[google app engine]]></category>
		<category><![CDATA[data validation]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=817</guid>
		<description><![CDATA[The Google App Engine datastore provides convenient data modeling with Python. One important aspect is the validation of the data stored in a Model instance. Each data key-value is stored as a Property which is an attribute of a Model class. While every Property can be validated automatically by specifying a &#8220;validator&#8221; function, there is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=817&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://code.google.com/intl/bg/appengine/docs/python/datastore/overview.html">Google App Engine datastore</a> provides convenient data modeling with Python. One important aspect is the validation of the data stored in a <a href="http://code.google.com/intl/bg/appengine/docs/python/datastore/modelclass.html">Model</a> instance. Each data key-value is stored as a <a href="http://code.google.com/intl/bg/appengine/docs/python/datastore/propertyclass.html">Property</a> which is an attribute of a Model class.</p>
<p>While every Property can be validated automatically by specifying a &#8220;<a href="http://code.google.com/intl/bg/appengine/docs/python/datastore/propertyclass.html#Property">validator</a>&#8221; function, there is no option for the Model <a href="http://code.google.com/intl/bg/appengine/docs/python/datastore/keysandentitygroups.html#Kinds_Names_and_IDs">key name</a> to be automatically validated. Note that we can manually specify by our code the value of the key name, and therefore this key name can be considered user-data and must be validated. The key name is by the way the only unique index constraint, similar to the &#8220;primary key&#8221; in relational databases, which is supported by the Google datastore, and can be specified manually.</p>
<p>Here is my version for a <strong>validation function for the Model&#8217;s key name</strong>:</p>
<pre class="brush: python; wrap-lines: false;">
from google.appengine.ext import db
import re

def ModelKeyNameValidator(self, regexp_string, *args, **kwargs):
	gotKey = None
	className = self.__class__.__name__

	if len(args) &gt;= 2:
		if gotKey: raise Exception('Found key for second time for Model ' + className)
		gotKey = 'args'
		k = args[1] # key_name given as an unnamed argument
	if 'key' in kwargs:
		if gotKey: raise Exception('Found key for second time for Model ' + className)
		gotKey = 'Key'
		k = kwargs['key'].name() # key_name given as Key instance
	if 'key_name' in kwargs:
		if gotKey: raise Exception('Found key for second time for Model ' + className)
		gotKey = 'key_name'
		k = kwargs['key_name'] # key_name given as a keyword argument

	if not gotKey:
		raise Exception('No key found for Model ' + className)

	id = '%s.key_name(%s)' % (self.__class__.__name__, gotKey)
	if (not re.search(regexp_string, k)):
		raise ValueError('(%s) Value &quot;%s&quot; is invalid. It must match the regexp &quot;%s&quot;' % (id, k, regexp_string))

class ClubDB(db.Model):
	# key = url
	def __init__(self, *args, **kwargs):
		ModelKeyNameValidator(self, '^[a-z0-9-]{2,32}$', *args, **kwargs)
		super(self.__class__, self).__init__(*args, **kwargs)

	name = db.StringProperty(required = True)
</pre>
<p>As you can see, the proposed solution is not versatile enough, and requires you to copy and alter the <strong>ModelKeyNameValidator()</strong> function again and again for every new validation type. I strictly follow the <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself">Don&#8217;t Repeat Yourself principle</a> in programming, so after much Googling and struggling with Python, I got to the following solution which I actually use in my projects (click &#8220;show source&#8221; to see the code):</p>
<pre class="brush: python; collapse: true; light: false; toolbar: true; wrap-lines: false;">
from google.appengine.ext import db
import re

def re_validator(id, regexp_string):
	def validator(v):
		string_type_validator(v)
		if (not re.search(regexp_string, v)):
			raise ValueError('(%s) Value &quot;%s&quot; is invalid. It must match the regexp &quot;%s&quot;' % (id, v, regexp_string))
	return validator

def length_validator(id, minlen, maxlen):
	def validator(v):
		string_type_validator(v)
		if minlen is not None and len(v) &lt; minlen:
			raise ValueError('(%s) Value &quot;%s&quot; is invalid. It must be more than %s characters' % (id, v, minlen))
		if maxlen is not None and len(v) &gt; maxlen:
			raise ValueError('(%s) Value &quot;%s&quot; is invalid. It must be less than %s characters' % (id, v, maxlen))
	return validator

def ModelKeyValidator(v, self, *args, **kwargs):
	gotKey = None

	if len(args) &gt;= 2:
		if gotKey: raise Exception('Found key for second time for Model ' + self.__class__.__name__)
		gotKey = 'args'
		k = args[1] # key_name given as unnamed argument
	if 'key' in kwargs:
		if gotKey: raise Exception('Found key for second time for Model ' + self.__class__.__name__)
		gotKey = 'Key'
		k = kwargs['key'].name()
	if 'key_name' in kwargs:
		if gotKey: raise Exception('Found key for second time for Model ' + self.__class__.__name__)
		gotKey = 'key_name'
		k = kwargs['key_name']

	if not gotKey:
		raise Exception('No key found for Model ' + self.__class__.__name__)

	v.execute('%s.key_name(%s)' % (self.__class__.__name__, gotKey), k) # validate the key now

class DelayedValidator:
	''' Validator class which allows you to specify the &quot;id&quot; dynamically on validation call '''
	def __init__(self, v, *args): # specify the validation function and its arguments
		self.validatorArgs = args
		self.validatorFunction = v

	def execute(self, id, value):
		if not isinstance(id, basestring):
			raise Exception('No valid ID specified for the Validator object')
		func = self.validatorFunction(id, *(self.validatorArgs)) # get the validator function
		func(value) # do the validation

class ClubDB(db.Model):
	# key = url
	def __init__(self, *args, **kwargs):
		ModelKeyValidator(DelayedValidator(re_validator, '^[a-z0-9-]{2,32}$'), self, *args, **kwargs)
		super(self.__class__, self).__init__(*args, **kwargs)

	name = db.StringProperty(
		required = True,
		validator = length_validator('ClubDB.name', 1, None))
</pre>
<p>You probably noticed that in the second example I also added a validator for the &#8220;<strong>name</strong>&#8221; property too. Note that the <strong>re_validator()</strong> and <strong>length_validator()</strong> functions can be re-used. Furthermore, thanks to the <strong>DelayedValidator</strong> class which accepts a validator function and its arguments as constructor arguments, the <strong>ModelKeyValidator</strong> class can be re-used without any modifications too.</p>
<p>P.S. It seems that all &#8220;validator&#8221; functions are executed every time a Model class is being instantiated. This means that no matter if you are updating/creating the data object, or you are simply reading it from the datastore, the assigned values are <strong>always validated</strong>. This surely wastes some CPU cycles, but for now I have no idea how to easily circumvent this.</p>
<p>Disclaimer: I&#8217;m new to Python and Google App Engine. But they seem fun! <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Sorry for the long lines&#8230;</p>
<hr />
<p>Resources:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/2413945/google-app-engine-model-integrity-constraints">Google App Engine: Model integrity constraints? &lt;&lt; Stack Overflow</a></li>
</ul>
<br />Filed under: <a href='http://blog.famzah.net/category/development/'>Development</a> Tagged: <a href='http://blog.famzah.net/tag/data-validation/'>data validation</a>, <a href='http://blog.famzah.net/tag/google-app-engine/'>google app engine</a>, <a href='http://blog.famzah.net/tag/google-datastore/'>google datastore</a>, <a href='http://blog.famzah.net/tag/python/'>python</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/817/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/817/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/famzah.wordpress.com/817/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/famzah.wordpress.com/817/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/famzah.wordpress.com/817/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/famzah.wordpress.com/817/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/famzah.wordpress.com/817/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/famzah.wordpress.com/817/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/famzah.wordpress.com/817/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/famzah.wordpress.com/817/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/famzah.wordpress.com/817/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/famzah.wordpress.com/817/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/famzah.wordpress.com/817/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/famzah.wordpress.com/817/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=817&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2010/08/04/validator-for-the-model-key_name-property-in-google-app-engine-datastore-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>C++ vs. Python vs. Perl vs. PHP performance benchmark (part #2)</title>
		<link>http://blog.famzah.net/2010/08/02/cpp-vs-python-vs-perl-vs-php-performance-benchmark-part-2/</link>
		<comments>http://blog.famzah.net/2010/08/02/cpp-vs-python-vs-perl-vs-php-performance-benchmark-part-2/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 08:50:33 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[c++ benchmark]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[perl benchmark]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php benchmark]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[python benchmark]]></category>
		<category><![CDATA[python psyco]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=811</guid>
		<description><![CDATA[This time we will focus on the startup time. The process start time is important if your processes are not persistent. If you are using FastCGI, mod_perl, mod_php, or mod_python, then these statistics are not so important to you. However, if you are spawning many processes which do something small and live for a very [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=811&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This time we will focus on the startup time. The process start time is important if your processes are not persistent. If you are using <a href="http://en.wikipedia.org/wiki/FastCGI">FastCGI</a>, <a href="http://perl.apache.org/">mod_perl</a>, <a href="http://www.php.net/">mod_php</a>, or <a href="http://www.modpython.org/">mod_python</a>, then these statistics are not so important to you. However, if you are spawning many processes which do something small and live for a very short time, then you should consider the CPU resources which get wasted while the script interpreter is being initialized.</p>
<p>The benchmarked scripts do only one thing &#8211; say &#8220;Hello, world&#8221; on the standard output. They do not include any additional modules in their source code &#8211; this may, or may not be your use-case. Though, very often the scripting languages have pretty many built-in functions, and for simple tasks you never need to include other modules.</p>
<p>Here are the benchmark results:</p>
<table border="1" style="border-collapse:collapse;" cellpadding="4">
<thead>
<tr>
<th rowspan="2" align="center">Language</th>
<th colspan="3" align="center">CPU time</th>
<th colspan="2" align="center">Slower than</th>
</tr>
<tr>
<th align="center">User</th>
<th align="center">System</th>
<th align="center">Total</th>
<th align="center">C++</th>
<th align="center">previous</th>
</tr>
</thead>
<tbody>
<tr>
<td>C++ <em>(with or w/o optimization)</em></td>
<td align="right">2.568</td>
<td align="right">3.536</td>
<td align="right">6.051</td>
<td align="center">-</td>
<td align="center">-</td>
</tr>
<tr>
<td>Perl</td>
<td align="right">12.561</td>
<td align="right">6.096</td>
<td align="right">18.723</td>
<td align="right">209%</td>
<td align="right">209%</td>
</tr>
<tr>
<td>PHP <em>(w/o php.ini)</em></td>
<td align="right">20.473</td>
<td align="right">13.877</td>
<td align="right">34.918</td>
<td align="right">477%</td>
<td align="right">86%</td>
</tr>
<tr>
<td>Python</td>
<td align="right">27.014</td>
<td align="right">11.881</td>
<td align="right">39.318</td>
<td align="right">550%</td>
<td align="right">13%</td>
</tr>
<tr>
<td>Python + <a href="http://psyco.sourceforge.net/">Psyco</a></td>
<td align="right">32.986</td>
<td align="right">14.845</td>
<td align="right">48.132</td>
<td align="right">695%</td>
<td align="right">22%</td>
</tr>
</tbody>
</table>
<p>The clear winner among the script languages this time is&#8230; Perl. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>All scripts were invoked 3000 times using the following Bash loop:</p>
<blockquote><p>time ( i=3000 ; while [ "$i" -gt 0 ]; do $CMD &gt;/dev/null ; i=$(($i-1)); done )</p></blockquote>
<p>For complete information about the test environment, please review <a href="http://blog.famzah.net/2010/07/01/cpp-vs-python-vs-perl-vs-php-performance-benchmark/">the previous article</a>.</p>
<hr />
<p>The <strong>C++</strong> implementation follows, click &#8220;show source&#8221; below to see the full source:</p>
<pre class="brush: cpp; collapse: true; light: false; toolbar: true;">
#include &lt;iostream&gt;
using namespace std;

int main() {
	cout &lt;&lt; &quot;Hello, world!\n&quot;;
	return 0;
}
</pre>
<p>The <strong>Perl</strong> implementation follows, click &#8220;show source&#8221; below to see the full source:</p>
<pre class="brush: perl; collapse: true; light: false; toolbar: true;">
use strict;
use warnings;

print &quot;Hello, world!\n&quot;;
</pre>
<p>The <strong>PHP</strong> implementation follows, click &#8220;show source&#8221; below to see the full source:</p>
<pre class="brush: php; collapse: true; light: false; toolbar: true;">
&lt;?php
echo &quot;Hello, world!\n&quot;;
</pre>
<p>The <strong>Python</strong> implementation follows, click &#8220;show source&#8221; below to see the full source:</p>
<pre class="brush: python; collapse: true; light: false; toolbar: true;">
#import psyco
#psyco.full()

print 'Hello, world!'
</pre>
<br />Filed under: <a href='http://blog.famzah.net/category/development/'>Development</a> Tagged: <a href='http://blog.famzah.net/tag/c/'>c++</a>, <a href='http://blog.famzah.net/tag/c-benchmark/'>c++ benchmark</a>, <a href='http://blog.famzah.net/tag/perl/'>perl</a>, <a href='http://blog.famzah.net/tag/perl-benchmark/'>perl benchmark</a>, <a href='http://blog.famzah.net/tag/php/'>php</a>, <a href='http://blog.famzah.net/tag/php-benchmark/'>php benchmark</a>, <a href='http://blog.famzah.net/tag/python/'>python</a>, <a href='http://blog.famzah.net/tag/python-benchmark/'>python benchmark</a>, <a href='http://blog.famzah.net/tag/python-psyco/'>python psyco</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/811/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/811/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/famzah.wordpress.com/811/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/famzah.wordpress.com/811/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/famzah.wordpress.com/811/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/famzah.wordpress.com/811/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/famzah.wordpress.com/811/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/famzah.wordpress.com/811/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/famzah.wordpress.com/811/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/famzah.wordpress.com/811/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/famzah.wordpress.com/811/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/famzah.wordpress.com/811/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/famzah.wordpress.com/811/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/famzah.wordpress.com/811/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=811&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2010/08/02/cpp-vs-python-vs-perl-vs-php-performance-benchmark-part-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>Speed up RRDtool database manipulations via RRDs (Perl)</title>
		<link>http://blog.famzah.net/2010/08/01/speed-up-rrdtool-database-manipulations-via-rrds-perl/</link>
		<comments>http://blog.famzah.net/2010/08/01/speed-up-rrdtool-database-manipulations-via-rrds-perl/#comments</comments>
		<pubDate>Sun, 01 Aug 2010 14:09:56 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[rrdtool]]></category>
		<category><![CDATA[rrd]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=795</guid>
		<description><![CDATA[Use case You are doing a lot of data operations on your RRD files (create, update, fetch, last), and every update is done by a separate Perl process which lives a very short time &#8211; the process is launched, it updates or reads the data, does something else, and then exits. The problem If you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=795&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><u>Use case</u><br />
You are doing a lot of data operations on your RRD files (create, update, fetch, last), and every update is done by a separate Perl process which lives a very short time &#8211; the process is launched, it updates or reads the data, does something else, and then exits.</p>
<p><u>The problem</u><br />
If you are using <a href="http://oss.oetiker.ch/rrdtool/">RRDtool</a> and Perl as described, you surely have noticed that running many of these processes wastes <strong>a lot of CPU resources</strong>. The question is &#8211; can we do some performance optimizations, and lessen the performance hit of loading the <a href="http://oss.oetiker.ch/rrdtool/prog/RRDs.en.html">RRDs</a> library into Perl? We know that launching often Perl itself is quite expensive, but after all, if we chose to work with Perl, this is a price we should be ready to pay.</p>
<p>The RRDtool shared library is a monolithic piece of code which provides <a href="http://oss.oetiker.ch/rrdtool/doc/index.en.html">ALL functions of the RRDtool suite</a> &#8211; data manipulation, graphics and import/export tools. The last two components bring huge dependencies in regards to other shared libraries. <strong>The library from RRDtool version 1.4.4 depends on 34 other libraries</strong> on my Linux box! This must add up to the loading time of the RRDtool library into Perl.</p>
<p><u>Resolution and benchmarks</u><br />
In order to prove my theory (actually, it was more a theory of <a href="http://blog.lifepattern.org/">zImage</a>, and I just followed, enhanced and tried it), I commented out the implementation of the &#8220;graphics&#8221; and &#8220;import/export tools&#8221; modules from the source code of RRDtool. Then I re-compiled the library and did some performance benchmarks. I also re-implemented the RRDs.pm module by replacing the <a href="http://search.cpan.org/~jesse/perl-5.12.1/ext/DynaLoader/DynaLoader_pm.PL">DynaLoader</a> module with the <a href="http://search.cpan.org/~saper/XSLoader-0.10/XSLoader.pm">XSLoader</a> one. This made no difference in performance whatsoever. The re-compiled RRD library depends on only 4 other libraries &#8211; linux-gate.so.1, libm.so.6, libc.so.6, and /lib/ld-linux.so.2. I think this is the most we can cut down. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So here are the benchmark results. They show the accumulated time for 1000 invocations of the Perl interpreter with three different configurations:</p>
<ul>
<li>Only Perl (baseline): <strong>5.454s</strong>.</li>
<li>With RRDs, no graphics or import/export functions: <strong>9.744s</strong> (+4.290s) <strong>+78%</strong>.</li>
<li>With standard RRDs: <strong>11.647s</strong> (+6.192s) <strong>+113%</strong>.</li>
</ul>
<p>As you can see, you can make Perl + RRDs start <strong>35% faster</strong>. The speed up for RRDs itself is 44%.</p>
<hr />
<p>Here are the commands I used for the benchmarks:</p>
<ul>
<li>Only Perl (baseline): time ( i=1000 ; while [ "$i" -gt 0 ]; do perl -Mwarnings -Mstrict -e &#8221; ; i=$(($i-1)); done )</li>
<li>Perl + RRDs: time ( i=1000 ; while [ "$i" -gt 0 ]; do perl -Mwarnings -Mstrict -MRRDs -e &#8221; ; i=$(($i-1)); done )</li>
</ul>
<br />Filed under: <a href='http://blog.famzah.net/category/development/'>Development</a>, <a href='http://blog.famzah.net/category/linux/'>Linux</a> Tagged: <a href='http://blog.famzah.net/tag/benchmark/'>benchmark</a>, <a href='http://blog.famzah.net/tag/linux/'>Linux</a>, <a href='http://blog.famzah.net/tag/performance/'>performance</a>, <a href='http://blog.famzah.net/tag/perl/'>perl</a>, <a href='http://blog.famzah.net/tag/rrd/'>rrd</a>, <a href='http://blog.famzah.net/tag/rrdtool/'>rrdtool</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/795/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/795/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/famzah.wordpress.com/795/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/famzah.wordpress.com/795/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/famzah.wordpress.com/795/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/famzah.wordpress.com/795/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/famzah.wordpress.com/795/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/famzah.wordpress.com/795/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/famzah.wordpress.com/795/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/famzah.wordpress.com/795/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/famzah.wordpress.com/795/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/famzah.wordpress.com/795/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/famzah.wordpress.com/795/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/famzah.wordpress.com/795/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=795&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2010/08/01/speed-up-rrdtool-database-manipulations-via-rrds-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>Free SSL certificates</title>
		<link>http://blog.famzah.net/2010/07/09/free-ssl-certificates/</link>
		<comments>http://blog.famzah.net/2010/07/09/free-ssl-certificates/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 07:19:43 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[StartSSL]]></category>
		<category><![CDATA[StartCom]]></category>
		<category><![CDATA[pki]]></category>
		<category><![CDATA[SSL]]></category>
		<category><![CDATA[SSL certificate]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[OpenSSL]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=775</guid>
		<description><![CDATA[More and more people start telling me about the StartSSL SSL authority, which is a daughter company of StartCom. The rumor that they are giving free SSL certificates looked too unbelievable to me, so I decided to review this more carefully. After much reading at their page, what people say was confirmed &#8211; StartSSL really [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=775&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>More and more people start telling me about the <a href="http://www.startssl.com/">StartSSL</a> SSL authority, which is a daughter company of <a href="http://www.startcom.org/">StartCom</a>. The rumor that they are giving free SSL certificates looked too unbelievable to me, so I decided to review this more carefully.</p>
<p>After much reading at their page, what people say was confirmed &#8211; <strong><a href="http://www.startssl.com/?app=1">StartSSL really issue SSL certificates for free</a></strong>, when they are about to be used by individuals on their websites. This means that your personal name stays in the SSL certificate information which can be reviewed if you click on the SSL bar in your web browser.</p>
<p>Business or other legal entities <a href="http://www.startssl.com/?app=37">verify their company&#8217;s information once for an annual fee</a> and can then issue an <strong>unlimited count of SSL certificates too</strong>, including wild-card ones. Once verified, a business customer can purchase EV certificates for US$ 49.90 per year.</p>
<p>You can compare these prices with any other SSL certificate authority and you&#8217;ll see it yourself that <a href="http://www.startssl.com/">StartSSL</a> are the most affordable one, and the only one which doesn&#8217;t charge you for what doesn&#8217;t cost them money either &#8211; that&#8217;s why they can offer &#8220;loosely verified&#8221; SSL certificates for personal websites for free. It&#8217;s unbelievable but true.</p>
<p>My IT brain immediately started to doubt the technical side. I had to check if web browsers accept these SSL certificates without issuing an SSL warning about the certificate being signed by an unknown SSL authority. The test results were successful and the SSL root authority of <a href="http://www.startssl.com/">StartSSL</a> was recognized by the latest version of:</p>
<ul>
<li>Internet Explorer 8 on Windows.</li>
<li>Chrome on Windows.</li>
<li>Firefox on Windows and Linux.</li>
<li>Chromium on Linux.</li>
</ul>
<p>Furthermore, the Debian &#8220;lenny&#8221;, &#8220;squeeze&#8221; and Ubuntu Lucid <a href="http://packages.ubuntu.com/lucid/ca-certificates">CA repositories</a> also recognize the <a href="http://www.startssl.com/">StartSSL</a> root certificate. You can verify this yourself by the following command:<br />
<code>openssl s_client -CApath /etc/ssl/certs -connect startssl.com:443</code></p>
<p><a href="http://www.startssl.com/">StartSSL</a> have a long list with platforms and browsers which recognize their certificates. You can review the list at the <a href="http://www.startssl.com/?app=40">products comparison page</a>.</p>
<p>No more <a href="http://en.wikipedia.org/wiki/Self-signed_certificate">self-signed SSL certificates</a> for personal use, hurray! <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />Filed under: <a href='http://blog.famzah.net/category/linux/'>Linux</a>, <a href='http://blog.famzah.net/category/misc/'>Misc</a> Tagged: <a href='http://blog.famzah.net/tag/free/'>free</a>, <a href='http://blog.famzah.net/tag/openssl/'>OpenSSL</a>, <a href='http://blog.famzah.net/tag/pki/'>pki</a>, <a href='http://blog.famzah.net/tag/ssl/'>SSL</a>, <a href='http://blog.famzah.net/tag/ssl-certificate/'>SSL certificate</a>, <a href='http://blog.famzah.net/tag/startcom/'>StartCom</a>, <a href='http://blog.famzah.net/tag/startssl/'>StartSSL</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/775/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/775/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/famzah.wordpress.com/775/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/famzah.wordpress.com/775/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/famzah.wordpress.com/775/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/famzah.wordpress.com/775/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/famzah.wordpress.com/775/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/famzah.wordpress.com/775/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/famzah.wordpress.com/775/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/famzah.wordpress.com/775/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/famzah.wordpress.com/775/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/famzah.wordpress.com/775/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/famzah.wordpress.com/775/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/famzah.wordpress.com/775/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=775&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2010/07/09/free-ssl-certificates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>The Super Micro IPMI Console + Java are killing me</title>
		<link>http://blog.famzah.net/2010/07/05/the-super-micro-ipmi-console-plus-java-are-killing-me/</link>
		<comments>http://blog.famzah.net/2010/07/05/the-super-micro-ipmi-console-plus-java-are-killing-me/#comments</comments>
		<pubDate>Mon, 05 Jul 2010 07:27:18 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[ATEN Java iKVM Viewer]]></category>
		<category><![CDATA[IPMI Console Redirection]]></category>
		<category><![CDATA[Super Micro IPMI BMC X8DTL]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=761</guid>
		<description><![CDATA[I don&#8217;t know if it&#8217;s Java or the Super Micro IPMI developers to blame, or both. One thing is for sure &#8211; I rarely need it, but almost each time I want to use the server-critical &#8220;Console Redirection&#8221; feature on our Super Micro servers, there is some problem with the Java applet. Thus I&#8217;m not [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=761&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know if it&#8217;s Java or the Super Micro IPMI developers to blame, or both. One thing is for sure &#8211; I rarely need it, but almost each time I want to use the server-critical &#8220;Console Redirection&#8221; feature on our Super Micro servers, there is some problem with the Java applet. Thus I&#8217;m not able to access the remote console of the server quickly, which in turn gets me real headache.</p>
<p>Today, it&#8217;s the &#8220;Launch Console&#8221; button doing absolutely nothing on my Kubuntu desktop &#8211; no errors, no action after clicking it, no nothing. I (always) have a &#8220;backup option&#8221; &#8211; a Windows 7 virtual machine running on my desktop, as Java tends to work better for me on Windows (cross-platform, eh?). Same problem on the Windows too. As I&#8217;m a real paranoid about having a backup, I have a backup of the &#8220;backup option&#8221; &#8211; X over VNC, running on<br />
some not-so-bleeding-edge Linux machines, in order to have a &#8220;stable&#8221; Java installation there. Though the Java failed on them today as well, as they are running Debian &#8220;lenny&#8221;, which seems to be having the latest Java version 1.6.20 too.</p>
<p>Well&#8230; sorry Java applets + Super Micro IPMI, you really disappoint me! :-/</p>
<p>The fix is to downgrade your Java to 1.6.19 (and disable automatic Java updates):<br />
<a href="http://www.webhostingtalk.com/showthread.php?t=953055">http://www.webhostingtalk.com/showthread.php?t=953055</a></p>
<p><em>Update #1:</em> I downgraded to Java 1.6.19 on my Windows 7 by:</p>
<ol>
<li>Uninstalling the Java 1.6.20 JRE update.</li>
<li>Installing the Java 1.6.19 JRE update which I downloaded from the <a href="http://java.sun.com/products/archive/">&#8220;Archive: Java[tm] Technology Products Download&#8221;</a> page.</li>
<li>Being able to get this working only with Chrome. Firefox and IE 8 failed to work.</li>
</ol>
<p><strong>Update #2</strong>: Linux doesn’t seem to be having any problems. Firefox 3.6.3 on Ubuntu and Gentoo with Sun Java 1.6.20 works fine.</p>
<p><strong>Update #3</strong>: If you upgrade the IPMI firmware to version 2.02, the Windows problem is fixed.</p>
<hr />
<p>Here is some debug info from the Debian &#8220;lenny&#8221; Iceweasel browser, the only one which issued an error:</p>
<blockquote><p>Unable to launch ATEN Java iKVM Viewer.<br />
An error occurred while launching/running the application.</p>
<p>Title: ATEN Java iKVM Viewer<br />
Vendor: ATEN<br />
Category: Download Error</p>
<p>Unable to load resource: (https://%IP%/iKVM.jar, 1.56.3.0&#215;0)</p>
<p>Wrapped Exception: java.io.IOException: HTTP response 404.
</p></blockquote>
<p>At the same time, the <a href="http://www.java.com/en/download/help/testvm.xml">Java test page</a> works fine. The version on the Debian &#8220;lenny&#8221; &#8220;sun-java6-jre&#8221; package is &#8220;6-20-01lenny1&#8243; (Java JRE 1.6.20).</p>
<p>The same problem is re-produced on:</p>
<ul>
<li>Windows 7, running Java 1.6.20, under IE 8, Firefox 3.6.3 and Chrome 5.0.375.99.</li>
<li>Kubuntu Lucid, running OpenJDK 6 build b18, under Firefox 3.6.3.</li>
</ul>
<p>The Firmware Revision of the <a href="http://blog.famzah.net/2010/03/14/review-of-the-super-micro-bmc-ipmi-card-for-the-x8dtl-motherboards/">IPMI interface on the X8DTL motherboard</a> is 01.29, dated 2010-01-06. It&#8217;s not the latest one, but surely not a very old one. After all, you can&#8217;t reboot your production servers for every IPMI firmware release&#8230;</p>
<p>Anyway, I try not to write articles with negative attitude, but this time I just couldn&#8217;t resist.<br />
Java, Java, Java&#8230; <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />Filed under: <a href='http://blog.famzah.net/category/hardware/'>Hardware</a>, <a href='http://blog.famzah.net/category/linux/'>Linux</a> Tagged: <a href='http://blog.famzah.net/tag/aten-java-ikvm-viewer/'>ATEN Java iKVM Viewer</a>, <a href='http://blog.famzah.net/tag/ipmi-console-redirection/'>IPMI Console Redirection</a>, <a href='http://blog.famzah.net/tag/super-micro-ipmi-bmc-x8dtl/'>Super Micro IPMI BMC X8DTL</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/761/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/761/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/famzah.wordpress.com/761/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/famzah.wordpress.com/761/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/famzah.wordpress.com/761/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/famzah.wordpress.com/761/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/famzah.wordpress.com/761/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/famzah.wordpress.com/761/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/famzah.wordpress.com/761/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/famzah.wordpress.com/761/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/famzah.wordpress.com/761/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/famzah.wordpress.com/761/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/famzah.wordpress.com/761/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/famzah.wordpress.com/761/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=761&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2010/07/05/the-super-micro-ipmi-console-plus-java-are-killing-me/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
		<item>
		<title>C++ vs. Python vs. Perl vs. PHP performance benchmark</title>
		<link>http://blog.famzah.net/2010/07/01/cpp-vs-python-vs-perl-vs-php-performance-benchmark/</link>
		<comments>http://blog.famzah.net/2010/07/01/cpp-vs-python-vs-perl-vs-php-performance-benchmark/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 10:50:23 +0000</pubDate>
		<dc:creator>Ivan Zahariev</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[c++ benchmark]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[perl benchmark]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php benchmark]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[python benchmark]]></category>
		<category><![CDATA[python psyco]]></category>

		<guid isPermaLink="false">http://blog.famzah.net/?p=732</guid>
		<description><![CDATA[Update: There is a part #2 of the benchmark results. This all began as a colleague of mine stated that Python was so damn slow for maths. Which really astonished me and made me check it out, as my father told me once that he was very satisfied with Python, as it was very maths [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=732&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Update: There is a <a href="http://blog.famzah.net/2010/08/02/cpp-vs-python-vs-perl-vs-php-performance-benchmark-part-2/">part #2 of the benchmark results</a>.</p>
<hr />
<p>This all began as a colleague of mine stated that Python was so damn slow for maths. Which really astonished me and made me check it out, as my father told me once that he was very satisfied with Python, as it was very maths oriented.</p>
<p><strong>The benchmarks here</strong> do not try to be complete, as they are showing the performance of the languages in one aspect, and mainly: <strong>loops, arrays with numbers, basic math operations</strong>.</p>
<p><em>Update: Give your ideas and use-cases on what to benchmark, and I&#8217;ll try to implement it for you. I.e. &#8220;benchmark the languages for reading a file, then splitting it to tokens by white-space and finally outputting all unique elements and their count&#8221;.</em></p>
<p>Out of curiosity, Python was also benchmarked with and without the <a href="http://psyco.sourceforge.net/">Psyco Python extension</a>, which people say could greatly speed up the execution of any Python code without any modifications.</p>
<p>Here are the benchmark results:</p>
<table border="1" style="border-collapse:collapse;" cellpadding="4">
<thead>
<tr>
<th rowspan="2" align="center">Language</th>
<th colspan="3" align="center">CPU time</th>
<th colspan="2" align="center">Slower than</th>
</tr>
<tr>
<th align="center">User</th>
<th align="center">System</th>
<th align="center">Total</th>
<th align="center">C++</th>
<th align="center">previous</th>
</tr>
</thead>
<tbody>
<tr>
<td>C++ <em>(<a href="http://gcc.gnu.org/onlinedocs/gcc-4.4.4/gcc/Optimize-Options.html#Optimize-Options">optimized with -O2</a>)</em></td>
<td align="right">2.456</td>
<td align="right">0.400</td>
<td align="right">2.856</td>
<td align="center">-</td>
<td align="center">-</td>
</tr>
<tr>
<td>C++ <em>(not optimized)</em></td>
<td align="right">4.352</td>
<td align="right">0.404</td>
<td align="right">4.756</td>
<td align="right">67%</td>
<td align="right">67%</td>
</tr>
<tr>
<td>Python + <a href="http://psyco.sourceforge.net/">Psyco</a></td>
<td align="right">12.693</td>
<td align="right">0.320</td>
<td align="right">13.013</td>
<td align="right">356%</td>
<td align="right">174%</td>
</tr>
<tr>
<td>Python</td>
<td align="right">28.866</td>
<td align="right">0.208</td>
<td align="right">29.074</td>
<td align="right">918%</td>
<td align="right">123%</td>
</tr>
<tr>
<td>Perl</td>
<td align="right">42.515</td>
<td align="right">0.184</td>
<td align="right">42.699</td>
<td align="right">1395%</td>
<td align="right">47%</td>
</tr>
<tr>
<td>PHP</td>
<td align="right">85.873</td>
<td align="right">0.560</td>
<td align="right">86.433</td>
<td align="right">2926%</td>
<td align="right">102%</td>
</tr>
</tbody>
</table>
<p>The clear winner among the script languages is&#8230; Python. <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The times include the interpretation/parsing phase for each language, but it&#8217;s so small that its significance is negligible. The math function is called 10 times, in order to have more reliable results. All scripts are using the very same algorithm to calculate the prime numbers in a given range. The correctness of the implementation is not so important, as we just want to check how fast the languages perform. The original Python algorithm was taken from <a href="http://www.daniweb.com/code/snippet216871.html">http://www.daniweb.com/code/snippet216871.html</a>.</p>
<p>All tests were done on a Kubuntu Lucid box. The versions of the used software packages follow:</p>
<ul>
<li>g++ (GNU project C and C++ compiler) 4.4.3</li>
<li>Python 2.6.5</li>
<li>Python Psyco 1.6 (1ubuntu2)</li>
<li>Perl 5.10.1</li>
<li>PHP 5.3.2 (1ubuntu4.2 with Suhosin-Patch), Zend Engine 2.3.0</li>
</ul>
<hr />
<p>The <strong>C++</strong> implementation follows, click &#8220;show source&#8221; below to see the full source:</p>
<pre class="brush: cpp; collapse: true; light: false; toolbar: true;">
#include &lt;cstdio&gt;
#include &lt;cmath&gt;
#include &lt;vector&gt;

using namespace std;

vector&lt;int&gt; get_primes7(int n) { // ugly variable declarations but close to the other lang. syntaxes
	vector&lt;int&gt; res;

	if (n &lt; 2) return res;
	if (n == 2) {
		res.push_back(2);
		return res;
	}
	vector&lt;int&gt; s;
	for (int i = 3; i &lt; n + 1; i += 2) {
		s.push_back(i);
	}
	int mroot = sqrt(n);
	int half = (int)s.size();
	int i = 0;
	int m = 3;
	while (m &lt;= mroot) {
		if (s[i]) {
			int j = (int)((m*m - 3)/2);
			s[j] = 0;
			while (j &lt; half) {
				s[j] = 0;
				j += m;
			}
		}
		i = i + 1;
		m = 2*i + 3;
	}
	res.push_back(2);
	for (vector&lt;int&gt;::iterator it = s.begin() ; it &lt; s.end(); ++it) {
		if (*it) {
			res.push_back(*it);
		}
	}

	return res;
}

int main() {
	vector&lt;int&gt; res;
	for (int i = 1; i &lt;= 10; ++i) {
		res = get_primes7(10000000);
		printf(&quot;Found %d prime numbers.\n&quot;, (int)res.size());
	}

	return 0;
}
</pre>
<p>The <strong>Python</strong> implementation follows, click &#8220;show source&#8221; below to see the full source:</p>
<pre class="brush: python; collapse: true; light: false; toolbar: true;">
#import psyco
#psyco.full()

def get_primes7(n):
	&quot;&quot;&quot;
	standard optimized sieve algorithm to get a list of prime numbers
	--- this is the function to compare your functions against! ---
	&quot;&quot;&quot;
	if n &lt; 2:  return []
	if n == 2: return [2]
	# do only odd numbers starting at 3
	s = range(3, n+1, 2)
	# n**0.5 simpler than math.sqr(n)
	mroot = n ** 0.5
	half = len(s)
	i = 0
	m = 3
	while m &lt;= mroot:
		if s[i]:
			j = (m*m-3)//2  # int div
			s[j] = 0
			while j &lt; half:
				s[j] = 0
				j += m
		i = i+1
		m = 2*i+3
	return [2]+[x for x in s if x]

for t in range(10):
	res = get_primes7(10000000)
	print &quot;Found&quot;, len(res), &quot;prime numbers.&quot;
</pre>
<p>The <strong>Perl</strong> implementation follows, click &#8220;show source&#8221; below to see the full source:</p>
<pre class="brush: perl; collapse: true; light: false; toolbar: true;">
use strict;
use warnings;

sub get_primes7($) {
	my ($n) = @_;

	if ($n &lt; 2) { return (); }
	if ($n == 2) { return (2); }
	# do only odd numbers starting at 3
	my @s = ();
	for (my $i = 3; $i &lt; $n + 1; $i += 2) {
		push(@s, $i);
	}
	# n**0.5 simpler than math.sqr(n)
	my $mroot = $n ** 0.5;
	my $half = scalar @s;
	my $i = 0;
	my $m = 3;
	while ($m &lt;= $mroot) {
		if ($s[$i]) {
			my $j = int(($m*$m - 3) / 2);
			$s[$j] = 0;
			while ($j &lt; $half) {
				$s[$j] = 0;
				$j += $m;
			}
		}
		$i = $i + 1;
		$m = 2*$i + 3;
	}
	my @res = (2);
	foreach (@s) {
		push(@res, $_) if ($_);
	}
	return @res;
}

my @res;
for (1..10) {
	@res = get_primes7(10000000);
	print &quot;Found &quot;.(scalar @res).&quot; prime numbers.\n&quot;;
}
</pre>
<p>The <strong>PHP</strong> implementation follows, click &#8220;show source&#8221; below to see the full source:</p>
<pre class="brush: php; collapse: true; light: false; toolbar: true;">
&lt;?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

function get_primes7($n) {
	if ($n &lt; 2) return array();
	if ($n == 2) return array(2);
	$s = array();
	for ($i = 3; $i &lt; $n + 1; $i += 2) {
		$s[] = $i;
	}
	$mroot = sqrt($n);
	$half = count($s);
	$i = 0;
	$m = 3;
	while ($m &lt;= $mroot) {
		if ($s[$i]) {
			$j = (int)(($m*$m - 3) / 2);
			$s[$j] = 0;
			while ($j &lt; $half) {
				$s[$j] = 0;
				$j += $m;
			}
		}
		$i = $i + 1;
		$m = 2*$i + 3;
	}
	$res = array(2);
	foreach ($s as $v) {
		if ($v) {
			$res[] = $v;
		}
	}
	return $res;
}

$res = array();
for ($i = 1; $i &lt;= 10; ++$i) {
	$res = get_primes7(10000000);
	print &quot;Found &quot;.count($res).&quot; prime numbers.\n&quot;;
}
</pre>
<hr />
<p><em>Update (Jul/24/2010)</em>: Added the C++ optimized values.<br />
<em>Update (Aug/02/2010)</em>: Added a link to the benchmarks, part #2.</p>
<br />Filed under: <a href='http://blog.famzah.net/category/development/'>Development</a> Tagged: <a href='http://blog.famzah.net/tag/c/'>c++</a>, <a href='http://blog.famzah.net/tag/c-benchmark/'>c++ benchmark</a>, <a href='http://blog.famzah.net/tag/perl/'>perl</a>, <a href='http://blog.famzah.net/tag/perl-benchmark/'>perl benchmark</a>, <a href='http://blog.famzah.net/tag/php/'>php</a>, <a href='http://blog.famzah.net/tag/php-benchmark/'>php benchmark</a>, <a href='http://blog.famzah.net/tag/python/'>python</a>, <a href='http://blog.famzah.net/tag/python-benchmark/'>python benchmark</a>, <a href='http://blog.famzah.net/tag/python-psyco/'>python psyco</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/famzah.wordpress.com/732/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/famzah.wordpress.com/732/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/famzah.wordpress.com/732/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/famzah.wordpress.com/732/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/famzah.wordpress.com/732/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/famzah.wordpress.com/732/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/famzah.wordpress.com/732/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/famzah.wordpress.com/732/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/famzah.wordpress.com/732/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/famzah.wordpress.com/732/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/famzah.wordpress.com/732/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/famzah.wordpress.com/732/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/famzah.wordpress.com/732/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/famzah.wordpress.com/732/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.famzah.net&amp;blog=10109730&amp;post=732&amp;subd=famzah&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.famzah.net/2010/07/01/cpp-vs-python-vs-perl-vs-php-performance-benchmark/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e354dbace6659e6cfc6ec6f01d7d962d?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">famzah</media:title>
		</media:content>
	</item>
	</channel>
</rss>