Wednesday, November 7, 2007

Wireshark on U3

Wireshark (former known as Ethereal) is a great tool for network diagnostics. I have been using it extensively to monitor network performance of my network applications. Recently I discovered that they have release a U3 package for it!
If you have a U3 flash drive and you frequent need to perform network diagnostics on various computers, I would really recommend you to try it out.
When you launch Wireshark from U3 launchpad, it will prompt you if you would like to install winpcap on the computer if it has not been installed. After winpcap has been installed, it will launch wireshark.
Once you have finished using wireshark, when you click on the eject button on U3 launchpad, it will also automatically uninstall the winpcap!
While this installation/uninstallation of winpcap seems a bit clumsy, it is still very useful as I can bring wireshark anywhere, stick it into any Windows PC and start troubleshooting the network!

Wednesday, October 24, 2007

Ubuntu 7.10 Gutsy Gibbon has been release

[K]ubuntu Gutsy has just been released last week. So I'm thinking of upgrading my current Feisty but I'll have to spend some time to image the root partition as backup just in case the upgrade procedure screws up. Upgrade instructions is available at http://kubuntu.org/announcements/7.10-release.php

I'll probably post more info and a short review on it once when I have completed upgrade.

Sunday, August 26, 2007

Now my car roars with 110db twintone horn

About 2 years ago, I had an auto accident (luckily no one was seriously injured) and damaged my front bumper and the horn was also replaced. But after I got my car back from the workshop, I realized that they gave me an cheap horn that is soft and squeak like a little kitten, far worse that the stock horn.

I have been wanting to change it for some time and recently, there was a few occasion when some reckless drivers dangerously cuts in front of me, forcing me to slam the brakes and also horn, but what came out was a mere little kitten squeak. So yesterday, I finally decided I had enough of the ineffective horn.

As I am sorta the DIY guy and also I been wanting to learn more about fixing my car,I decided to fix it myself. I could learn more about car wiring and save some money. First, I took a spanner to remove the horn, took it back into my room and experimented with it. I found that electric horn connection terminal are not polarized, so we can connect +12V and GND from my power supply to any of the two terminals. Using a multimeter to measure the current consumption, the horn drains about 4.2A or approximately 50W.


Old horn removed

Next, I went to an auto accessories and bought a Hella New Generation Twin Tone Horn for RM58.00. On the box, it states the sound pressure level is 110db and rate input power of 2 x 72W. I also bought a few connector for the wiring.

Later, I went home to install the horn. There are generally several types of horn connection for cars as shown in the installation instruction at the back of the box.


The existing horn has the 3rd configuration - one wire. After a few minutes of wiring and screwing the new pair of horn in place:


New Horns

Finally, a quick press on the horn button on the steering wheel... HORN!!!
Yeah, it is loud and the twintone sounds nice. I would like to try a few more times, but that will probably disturb the neighbours... hehehe..

Tuesday, August 21, 2007

Hosting WCF in WPF app

In an application that I am developing, I have encountered a problem when the WPF GUI freezes when a client access the services in the server. Both client and server are WPF applications and the service operations typically takes several seconds to complete. So, the server GUI became unresponsive when the client performs service operation calls to the server. After some investigation, I found that the default behavior for WCF is to use the default synchronization context for the current AppDomain for synchronizing client access. Thus, when it is hosted in a GUI application, it locks the UI thread too.

To disable this behavior, I have disable the UseSynchonizationContext switch in the ServiceBehavior attribute of the service implementation class.

[ServiceContract]
public interface IMyService
{
[OperationContract]
void DoSomething();
}

[ServiceBehavior(
UseSynchonizationContext = false)]
public class MyServiceImpl : IMyService
{
public void DoSomething()
{
...
}
}


Unfortunately, setting this flag to false also means I have to be extra careful with the golden rule of GUI and multithreading programming:

"Thou shalt only update UI using code that runs on the same thread as the UI."

Disabling UseSynchonizationContext causes WCF to process incoming client request using background thread. Thus, if we need to update the UI during the service operation execution, I'll need to use Dispatcher.BeginInvoke to marshal the call to the UI dispatcher thread to perform the UI update operations. For more information on multithreading and GUI, see this article from WPF SDK blog:
Thou Shalt Not Break the Golden Rule of Windows Multithreading. Or, Why the Dispatcher Rocks.

Monday, July 9, 2007

cpufreq and measuring power consumption

Since everyone are talking about Live Earth and global warming recently, I have decided to check my personal power consumption. Other than my car, I guess the second most power consuming device is my PC. So I decided to measure how much power it consumes. Especially as I have recently discovered the cpufreqd that can adjust my Pentium 4 processor speed from 2.4GHz down to 300MHz.

Unlike some hardware review sites where they could afford to buy good quality power meters like the Watts Up, all I have is just two multimeter laying around my toolbox and they can't even measure AC current. So, I also can't measure power as the method described in the article in TwistedMod. I has to create my own method to measure the current that goes into my PC. The circuit is as shown below:

circuit to measure PC power consumptionThe resistor 5.1ohm, 5W was used because it is the only suitable resistor that is in my toolbox. Basically, any low resistance high power resistor should be suitable. The power dissipation of the resistor must be less than its rated power. For instance, I would expect my PC to draw less than 200W average and the mains provides 250V, thus the current is I = P/V = 200W/250V = 0.8A. Therefore, resistor power dissipation is P = I2R = 0.82 x 5.1 = 3.264W, which is still safe and below 5W. Of course, a 10W resistor would be safer and if your mains is 110V, the current would be twice and there for a 2ohm, 10W resistor is probably more suitable as the voltage drop across the resistor is lower.

BTW, if you do not really understand the above paragraphs about voltage, current and power, PLEASE DO NOT ATTEMPT THIS AT HOME!

Ok, I have completed modifying the above circuit as shown below:


The setup showing multimeter measuring VR

Next, I set my two multimeters to measure AC voltage. And finally, I plugged in the power cord and I pressed the power button....

... fans and hard disk spins up ..... beep ...

Yes, it works. The VAC shows 252V and VR fluctuates around 1.8V as Kubuntu boots up. Also, resistor power dissipation, PR = 1.8V / 5.1ohm = 0.35A.

After the system boots up and once the system reaches idle (cpufreqd is set to ondemand and ksensors show 300MHz), the VR is 1.6A with my LCD monitor on and 1.2A when the LCD monitor is switched off.




Then, I set my CPU frequency using cpufreq-set command (for example, cpufreq -f 1600 to set various frequency and various system load to determine the effect of CPU frequency and CPU load on power consumption. For more info on setting CPU frequence and power management in Linux, see
Debian HOW-TO : CPU power management

To simulate load, I used mencoder to trancode an episode of DL.tv using the following command:

mencoder dl.tv.173.i.mp4 -ovc lavc -oac lavc -o /dev/null

FYI, these are the major components of my machine's specs:
  • Intel Pentium 4 - 2.4Ghz
  • 512MB RAM - Corsair XMS 2ns
  • MSI 865P Neo motherboard
  • MSI Geforce FX 5200 - 128MB
  • Creative SB Audigy
  • 250GB WD Caviar SE
  • 40GB WD Caviar
  • LiteON DVD +/- RW drive
  • 17" Samsung LCD 173V

Results:


Power consumption with single CPU load


Power consumption at idle

As you can see, when the CPU is loaded, the power consumption reduces when the CPU frequency is reduced. However, on idle load, changing CPU frequency does not seems to any effect on power consumption. I guess the reason is because my old processor is not really design for frequency scaling for reduced power consumption. It would be interesting to see the difference on newer processors with Intel's Enhanced SpeedStep or AMD's Cool 'n' Quiet.

At idle power consumption at 60W is not exactly low compared to some latest 'green' machines. But it is relatively low compared to the those high-end gaming machines.

Another observation is that the 17" LCD takes approximately 30W.

Lastly, please try to use Live Earth online calculator to find out your lifestyle carbon footprint and so something about it. My Live Impact score is 215 and 4.7 tons of carbon output per year. Hmm.. I guess I can probably do something to reduce this.

Monday, July 2, 2007

The Economics of open source

An interesting and lively discussion thread has popped up at Ubuntu Forums with a title that is sure to invite a large reaction among the group of highly enthusiastic Ubuntu users in the forum:
*deep breath* For the most unpopular opinion of any Ubuntu user, please click here.
In summary, the original poster's opinion was that Ubuntu should be made closed-source so that programmers can make a lot money and improve their lives. He/She also said that by closing up Ubuntu, its quality will improve because paying more money will make things better.

It is unfortunate that he/she has such opinion, which makes many other posters in the thread believe that he/she has very little understanding of the dynamics of open-source softwares. Later in the thread, he/she has indicated that he is still in college and he would wish that the software industry would be a huge money pot for everyone to join. So, I guess he/she can be forgiven for being less knowledgeable in the dynamics of the software industry and life as a software developer.

The software industry is relatively new industry that is fast growing and thus getting huge and complicated. Writing a software product is not like writing a home-brew program or student project. For large projects involving many programmer, the overhead for many non-coding processes increases (on this topic, I would recommend reading the first few chapters of Steve McConnell's Code Complete book). It seems to him/her that life as a programmer will be better if people pay companies to make softwares. Unlike other traditional industry where the workflow is something like:
1. Product designers conceptualize and designs the product such as cars.
2. Engineers turns the design in to prototype and ensure that the design is good and reliable.
3. Finally, factory workers build/assemble the cars and its parts.

But in software, we are the engineer and also the construction worker because, we do the design and also the dirty work of constructing each and every part of the software.

Personally, two years ago, when I was still in university, I also had a similar opinion like him but less radical. To me, Linux was mainly a toy OS to learn about how computer and software works. At that time, I also believed that proprietary software are still superior. However, things changes as I started working in a large US-based technology corporation that makes products with proprietary codes, I came to understand the real deal in developing softwares. Businesses are still businesses, the goal of the company is to make profit for the shareholders. Shareholders invest money in company to make profit, not to pay programmers to do what they like to do. Now, as a software engineer, I came to realize that quite often, what we do to the piece of software is primarily a business decision that leads back to faster time to market, better profit, etc.

I think open-source is an alternative business model that might actually work for software industry. While it is still quite early to decide is open-source is definitely the future, it is quite entirely possible as software development in indeed very different from most traditional product development industry.

Anyway, these are mainly the opinion of mine as a young software engineer as I begin probably a life-long journey in the software industry and may not necessary represent those that are veteran in the industry. I'll probably write more on this in the future. Until then here's some interesting reading about Linux vs. Windows http://linux.oneandoneis2.org/LNW.htm

Tuesday, June 26, 2007

Moonlight: Silverlight for Linux/Mono

I just found out that the guys at Mono has hacked up a version of Linux clone of Microsoft's Silverlight that was just release a couple of months ago. They called it moonlight.
Another interesting fact is that the it was done in just 21 days of intensive hack-a-thon!
Working on a project that uses.NET Framework 3.0, I find that the XAML and WPF is pretty interesting technology for GUI as it allows "declarative programming" where UI design is separated from coding. While some may argue that Qt's ui files and GTK's Glade already offers such capability, XAML seems more easily readable and could be manually edited with notepad to create pretty powerful effects without a designer tool.
It would be interesting to monitor the progress of this project and also the future of Silverlight, if it will revolutionize the Web as claimed by Microsoft.
Another interesting component in .NET Framework 3.0 that I would really like to see on Linux is Windows Cardspace which provides a new approach to identification and authentication beyond the current widely used yet weak username/passwords because hey, I always forget my passwords for website that I frequent less often. Currently, I depend on password saving tools in Firefox, KDE Wallet but they aren't prefect.

Saturday, June 2, 2007

Kill the creeps on your desktop!


My colleague recently introduced me to a little flash game call Desktop Tower Defence. At first look, it seems to be a pretty simple game. Just place the defence towers and shoot down the creepy little creatures that tries to travel across the desktop area. After one round, I got hooked. If you just google for Desktop Tower Defence, you will realize how many people got addicted over this simple flash game. Usually, I'll just pass after playing most online flash games for 10-15 minutes but this got me hooked for hours and hours for days! It is challenging, fun and somewhat stress relieving! Try it out. After one week, I have finally completed the Hard level with 4689 points!
Hint: Be familiar with the keyboard shortcuts in the instruction section. You will need it when action heats up!

Saturday, May 5, 2007

Journey to Kubuntu 7.04 Feisty Fawn


Finally I have installed Kubuntu Feisty Fawn!
But I have to admit that the journey was not exactly smooth.

Initially, as I do not have a really reliable connection, I have downloaded the Alternate CD and tried to execute the cdromupgrade script. However, I found that it needs gksu which it not installed. Trying to cheat it. I changed that to kdesu and it successfully launched the Distribution Upgrade tool, but quickly failed due to a bug I discovered in DistUpgradeViewKDE.py and I submitted a bug report.

Next, I tried a new attempt using the new Kubuntu Distribution upgrade tool as described here. But it failed during the "Modifying Software Channels" stage due to some gzip error.

After some googling, I found that I could modify the /etc/apt/source.list to point to mirrors instead of the official source at http://archive.ubuntu.com/ubuntu/. To my disappointment, there are no mirrors in Malaysia. So I looked for mirrors in Asia. As I thought Thailand would be the closest neighbor, I changed all references to http://archive.ubuntu.com/ubuntu to http://mirror.in.th/ubuntu/archive/. Download speed was reasonably OK... about 60KBps but failed when installing a package called ttf-bengali-fonts and installation stalled after that. I closed the Distribution Upgrade tool and restarted the system to try again. But to my horror, Kubuntu failed to boot!

Luckily, I have a backup of the primary Kubuntu partition using Clonezilla tool. This time, I found this Official Archive Mirrors page to be better that the Ubuntu Wiki Mirrors page that is linked from Ubuntu download page. After a bit of testing using ping, tracepath and also download a small 1MB file. I discovered that Korea's KAIST is the fastest. Hence, I replaced all http://archive.ubuntu.com/ubuntu in /etc/apt/source.list to http://kr.archive.ubuntu.com/ubuntu/ and I tried to launch the Distribution Upgrade tool using Adept again. But the error happened again when installing ttf-bengali-fonts. But this time, I tried an advice from ubuntu forums by trying executing a "sudo dpkg-reconfigure -a" then followed by "sudo aptitude upgrade" before restarting. With my fingers crossed, Kubuntu Feisty was launched successfully! Yay!

After some testing around, everything seems fine. A quick check on the used space on the partition shows that it is about 3.7GB. Then I remembered that there was a final stage on the Distribution Upgrade tool for clean up. After a bit of browsing around the filesystem, I found that /var/cache/apt/archive has taken up 1GB. To clean that up, I did a "sudo apt-get clean" and that clears up the download packages and leaves me with 2.6GB of used space.

So, as you see, the journey was not too smooth but it works!

Saturday, April 14, 2007

KTorrent rediscovered and it ROCKS!

I have just rediscovered KTorrent and I find it as a great alternative compared to more mainstream Bittorrent clients. Previously, I was using Azureus as it is feature packed and portable. I have been using it for a couple of years when Windows was still my primay OS and Linux was mainly for fun. It has I have tried KTorrent earlier but it was not stable has less features.

After installing Kubuntu, I tried to reinstall Azureus and it worked with gcj/gij implementation of JAVA but it was somewhat slow and unreliable. But I was a little lazy to download real Java runtime from Sun. So I decided to try the KTorrent that is part of default installtion. It is KTorrent 2.1 and 10 minutes later... I loved it. It has all the feature that I need from a Bittorrent client such as:
  • PeerGuardian IP blocking

  • Protocol Encryption

  • DHT, which is compatible with mainline version

  • Web UI

  • and it's UI is more responsive that Azureus



  • So, if you are using KDE, try it out!

    New Western Digital Caviar SE 250GB EIDE harddisk and Kubuntu Edgy

    I have just bought a new Caviar SE 250GB EIDE harddisk. I am quite satisfied with it. It run quite and cool just as advertised at it's website.


    hddtemp shows 34°C when it is under light loading while my room temperature is 30°C:
    $ hddtemp /dev/hda
    /dev/hda: WDC WD2500JB-55REA0: 34°C

    It is currently cooled with a standard 5cm case fan. Even without the fan it seldom reaches 40°C.

    Anyway, these are some performance numbers which is pretty average and definitely nothing near high performance drives like those 10,000 rpm Raptors

    $ sudo hdparm -t /dev/sda

    /dev/sda:
    Timing buffered disk reads: 174 MB in 3.03 seconds = 57.48 MB/sec
    $ sudo hdparm -T /dev/sda

    /dev/sda:
    Timing cached reads: 1172 MB in 2.00 seconds = 585.58 MB/sec


    BTW, I have now switch to Kubuntu (yeap, I prefer KDE compared to gnome). I have been using many different distros in the past from Red Hat 4.2, Mandrake, Red Hat 9.1, openSUSE 10.0, then SUSE 10.1. All of them are uses Red Hat/RPM based package management. This is the first time I actually used a Debian-based distro. I have to say that I am pretty happy with its apt-get style of package management. It is quick and easy. To install hddtemp, I just typed:
    $ sudo apt-get install hddtemp

    and in a few seconds.... done. SUSE 10.1's zenworks is one of the things in sometimes pissed me off because it crashes as I mentioned in an earlier post and it is SLOW! it takes ages to load YaST especially when a new repository was added. I have read that openSUSE 10.2 has kinda fixed that but I was a little lazy to download the 5 CDs or DVD image.

    Kubuntu is simple, just one CD installation. Compared to SUSE, the default installation package is somewhat minimal. My girlfriend complained that it doesn't have any default games installed(she likes the Enigma game and even downloaded the Windows port for her laptop). However, the APT package management make installing additional software a breeze.

    Sunday, April 1, 2007

    KEEP YOUR HARDDRIVES COOL!

    Arg! There are dozens of bad blocks in my root partition and it does not boot properly anymore. It is a Maxtor 80GB HDD about 3 years old. This is the first time I had such a serious problem in my 12 years of experience with computers. I have help many people troubleshoot their computers with bad sectors in the past but this is the first time it happens to me! I have always kept my harddrives cool with a cooling fan.

    Well, this Maxtor drive is not really mine, it was my girlfriend's. Last year, I bought a 160GB drive as I needed a new drive for Linux as my old 4.3GB is aging and getting slower but still no bad sectors! And, since I don't really need so much space while my girlfriend always complain that she does not have enough diskspace, so we swapped. She has a laptop and the 3.5" 80GB HDD is in an external USB/IDE enclosure that was not too well ventilated compared to my other older 40GB drive that is still running well.

    Therefore, the lesson learnt is: KEEP YOUR HARDDRIVES COOL!

    Anyway, this site has pretty good description on handling bad blocks for ReiserFS: http://www.namesys.com/bad-block-handling.html

    Sunday, March 4, 2007

    openSUSE zen-updater crashes

    Today is the 2nd time I have encountered zen-updater crashes that shows the "Unhandled exception" dialog.
    After a little googling, I found the solution here http://en.opensuse.org/Using_zen-updater#Why_zen-updater_crashes
    Basically, it says that the zenworks database is corrupted and one way to fix it is to:
    1. kill the zmd and zen-updater processes
    2. delete the database at /var/lib/zmd/zmd.db
    3. restart zenworks and zen-updater.
    For more details, please refer to the link above.

    Sunday, January 14, 2007

    It's a monster and it's a 12cm, 12V DC Fan!

    I have just got a 12cm fan from my company's scrap parts. It is a poweful fan that I have just installed in computer. To do that I know a Dremel would be a great tool for case mod like this but I don't have one. Using a hacksaw, a plier and a set of files, I was able to cut a hole at the top of the casing and installed the fan. It wasn't great, but it works.

    I can't post any picture yet as I don't have a camera with me now and my camera phone was stolen :(

    Because the fan is so powerful, when it is powered at full speed, it will suck so much air out of the casing that it interrupted the air flow into the PSU. Therefore, I'll need to build a PWM controller circuit to control the fan speed.

    Wednesday, January 3, 2007

    Adobe Flash Player 9 beta for Firefox/Linux

    If you are getting fustrated that you are still using Flash Player 7 in Linux and many sites are started to require minimum version 8 or 9, you can try using the Flash Player 9 beta.
    The following are the few simple steps I took to update mine:
    1. Download the player from Adobe Labs: http://labs.adobe.com/downloads/flashplayer9.html
    2. Extract the GZip file which will contain 2 files: readme.txt and libflashplayer.so
    3. Following the instruction in readme.txt. For my SuSE 10.1, I just copy the libflashplayer.so to /usr/lib/firefox/plugins which of course requires root login.

    After that, most of the sites that require Flash Player 9 seems to work pretty well.


    UPDATE: Linux Flashplayer 9 is now release, go to http://www.adobe.com/go/gntray_dl_getflashplayer instead!