Saturday, August 14, 2010

Trivial but important - Java Random Number

Summer 2010 in Bloomington is nearly end (I hope it ends sooner since it's freaking hot here). I've worked as a researcher on TeraGrid project for entire summer. My main task is to create a test library (program) to use against GRAM5 gateway which will be deployed on TeraGrid (soon). It is coded in Java and used for both scalability and reliability test. The problem comes up when I try to submit multiple jobs to GRAM5 gateway from multiple machines. If I start submission at the same time for all machines, program will get a connection reset from a server. I think it is caused by the fact that network router or server has a mechanism to prevent flooding.

At first, I use a simple solution which is delaying a job submission randomly in each machine using java.util.Random class. It worked fine up to around 50 machines then it started to get connection reset again. The situation becomes worse when I use 100 nodes, 90% of jobs fail. Therefore, I google around knowing in my mind that there must be something wrong about Random class. Finally, I found this site[1]. The important properties of Random class are
  • Random number is generated in deterministic way based on a given number called seed
  • Default constructor will use System.currentTimeMillis()as seed.
So, if we give the same seed number to Random class, it will generate a same sequence of random number. In my case, it's likely that each machines create a Random object at the same time, so they get the same seed. The solution is simple, we need to give a different seed on different machines. I use java.util.UUID to generate a unique ID across multiple machines (the odd is very low for different JVM to generate the same UUID) and create a seed from it. Here is my final code

Random random = new Random(UUID.randomUUID().hashCode());
int sleepTime = random.nextInt(120)
Thread.sleep(sleepTime * 1000l);

[1] -

Saturday, May 15, 2010

Ubuntu 10.04 Lucid Lynx and Nvidia Problem

Eventually, First year of my graduate study is passed (time flies). When the semester ends, it's about time to clean my laptop. Before reinstalling Windows, I decided to try Lucid Lynx on my new laptop (Sony Vaio CW). An obvious improvement in this version is User Interface which I quite like it.

First obstacle is installation and live CD mode cannot run properly on my machine. It always display only black screen. I found that the problem is with my Nvidia Geforce GT230M. The solution[1] is to enable 'nomodeset' option when trying to boot (using F6).

After finish installation, Ubuntu still cannot be booted since it suffers from the same problem. So, I need to go into live mode and edit grub file (/etc/default/grub) to add 'nomodeset' parameter. But, because instance that run is not installed instance, I cannot use 'update-grub' script to update boot loader. Therefore, I also need to edit grub.conf (/boot/grub/grub.conf) to make sure that next boot will be started with 'nomodeset'.
Note: instead of going into live mode, you can press shift during grub2 load to change boot option. I've not tried it myself but found it on an article.

Ubuntu 10.04 on Sony VAIO CW

Not yet, using a free OS is not that easy :p. After I installed Nvidia driver for my machine, the screen is not correctly displayed. It is the problem that Nvidia's driver cannot detect my monitor (I experienced a Nvidia's problem with Ubuntu since Intrepid Ibex). The solution[2-4] is to custom xorg.conf (/etc/X11/xorg.conf) file to use custom EDID (Extended display identification data). So, I have to reinstall windows and export EDID using programe named 'softMCCS'. Then, reinstall Ubuntu and going through a whole process again. Finally, make a reference to a EDID exported by windows by adding this code
Section "Device"
Identifier    "Device0"
Driver        "nvidia"
VendorName    "NVIDIA Corporation"
Option        "NoLogo"       "True"
Option        "ConnectedMonitor"   "DFP-0"
Option        "CustomEDID"         "DFP-0:/etc/X11/.bin"

And VoilĂ !! Working Lucid Lynx on laptop with Nvidia card.

[1] -
[2] -
[3] -
[4] -