[en] Fix irregularity of Java Timer and ScheduledThreadPoolExecutor

Using Java Timer class one can schedule a task for recurring execution. Even though ScheduledThreadPoolExecutor makes it possible to create timers with nanosecond resolution (but beware of underlying operating system clock precision!), regularity of task execution is by default awful.

I have run into this once and had to explain the customer that it’s not fixable. When I measured the delay between timer executions, etc. it turned out that doing as much as new Thread(runnable).start() usually takes 1-5 milliseconds, but at times it takes two orders of magnitude longer: even half a second!

Same customer, other project and this time I thought of a reason for this behaviour: garbage collection. I started with calling System.gc() explicitly inside measured code and it takes 200-500 milliseconds! So it must be it.

Is there a solution? Of course there is. It’s called The Concurrent Low Pause Collector and has been in Java since version 5. Read the linked article for many, many details, but shortly just add:

-XX:+UseConcMarkSweepGC

to the usual java -jar command and the garbage collection will be done in parallel with your code execution. Of course it’s no golden bullet, it makes overall performance worse (now instead of 1-5 milliseconds, a single loop pass takes 4-10 milliseconds), but for this particular use, it makes Timer regularity better by two orders of magnitude.

[en] Solution to SIL3124-2 „no valid device”

SIL3124 is a PCI (as in old PCI, not PCI express) SATA-II controller which I had to buy because my NAS’ old Gigabyte motherboard supports (downspeeded) SATA-II drives only to 750GB size. Of course I got to know this AFTER buying 1,5TB drive 😉

Anyway, it’s always uphill and even though SIL3124 card sees the drive and I’ve installed Ubuntu Server with no problems to it, I couldn’t boot the card. It kept saying „no valid device”. Turns out it has a RAID-only BIOS by default so if someone – like me – wants to use it as an JBOD (Just a Bunch Of Disks) controller, BIOS upgrade is needed. How user friendly not to mention it in a – Czech-language – manual.

Of course, being mainly a Linux user with no CD- or DVD-drive, I have it even more uphill. BIOS flashing tools are available for Windows and DOS. Soooo the solution is:

  1. Use HP USB Disk Storage Format Tool to create bootable DOS pendrive, here’s Polish language tutorial: http://forum.purepc.pl/Dyski-twarde-cdromy-dvd-pendrive-inne-pamieci-f55/Boot-Pendrive-t254005.html if You don’t speak Polish, just google „boot pendrive dos”, in the tutorial is a link to Win98 boot files You might use.
  2. Download UPDFLASH and the newest BIOS zip from http://www.siliconimage.com/support
  3. The zip file has more than one BIOS inside, read the README and see which one is „IDE” BIOS or „non-RAID” BIOS. Copy the file together with UPDFLASH to the pendrive.
  4. Boot the PC with the PCI SATA Controller from the pendrive.
  5. Run „updflash biosfile.bin”
  6. If you don’t have a UPS, pray to Atheist’s God(TM) that there’s no blackout during flashing process.
  7. Use motherboard’s (not SATA controller’s) BIOS to set Hard Drive as first boot priority, make sure there’s „Bootable Add-In Cards” enabled somewhere.
  8. Reset and enjoy bootable large drives.

Note: Drive’s UUIDs change because of that so it’s best to do it BEFORE installing Ubuntu, otherwise You get a maintanance console.

[en] Ubuntu 9.04 Jaunty on my AMD64 system – notes to myself

Update 2009-11-18, using Ubuntu 9.10 now

  • Wine has finally font anti-aliasing, to enable do this in regedit: ============ REGEDIT4 [HKEY_CURRENT_USER\Control Panel\Desktop] "FontSmoothing"="2" "FontSmoothingType"=dword:00000002 "FontSmoothingGamma"=dword:00000578 "FontSmoothingOrientation"=dword:00000001 ============

Mainly notes to myself, but maybe some random Googlers will find some of them useful. I may add more in time.

  • If many of texts in your system, including Firefox are not in your native language, make sure you have installed appropriate language-pack-XX package (language-pack-pl for Polish). It should be downloaded by Ubuntu installer but it never fully worked for me since 5.04.
  • Pidgin has a plugin for Tlen protocol. Just download the newest .tar.gz, unpack and make. You should have pidgin-dev package installed for it to succeed. I didn’t try make install, just copied over resulting libtlen.so to /usr/lib/purple-2 and .png files to /usr/share/pixmaps/pidgin/protocols, one file – renamed to just tlen.png – to each folder.
  • Nice Pidgin smiley pack which has original emotikons for protocols I use. Just go to Pidgin settings, smiley sets tab and click add.
  • Firetray contrary to what its name suggests, also works in Thunderbird, allowing it to minimize itself to system tray. Just open Thunderbird’s Add-ons window and drag install link there from Firefox to install this extension.
  • Polish set of Adblock filters I’ve been using for some time now.
  • Installing Aurora GTK Theme engine (most good themes seem to use it):
    aptitude install build-essential libgtk2.0-dev
    # download from 
    # http://www.gnome-look.org/content/show.php/Aurora+Gtk+Engine?content=56438 
    # unpack and cd to source directory
    ./configure --prefix=/usr --enable-animation
    make
    sudo make install
    
  • Download Myriad Pro font. Here’s Myriad in TTF version (thanks Misiek) which looks better in Java programs (think OpenOffice).
  • Fresh Dark – a very nice dark theme for Gnome. Also see matching icons. If Metacity/Emerald (window borders) theme doesn’t work, just check file and directory permissions of the unpacked theme. If windows run as root look ugly, make sure you copy the theme to /usr/share/themes instead of just ~/.themes.
  • Wine repository which usually has newer version than default Ubuntu repos.
  • A nice way to integrate MS Office (I have a license so I use it through Wine instead of OpenOffice, same goes to Photoshop which I prefer over Gimp in spite of all those holy wars about it) is to create /opt/wine-start.sh script with following contents
    #!/bin/bash
    wine start "z:$1"
    
    and then chmod +x it and use it with Gnome’s Open With function on .doc, .xls and .ppt files. That way I’m able to open those files in Word, Excel and PowerPoint just by double clicking them.
  • There is Java Plugin for Firefox on AMD64 at last (just install sun-java6-plugin package).
  • Wammu (nice mobile phone manager with a great feature of copying your SMSes to your e-mail inbox) just works in Jaunty with my Nokia 6021 over bluetooth which was never a case before.
  • SSH Menu is a nice little gnome applet to build a fast-access menu of SSH servers you connect to. Ubuntu repository is also there.
  • I always forget that Eclipse PDT (PHP Development Tools) all-in-one download is for 32bits only. To install it on AMD64 architecture, download 64-bit version of Eclipse for JavaEE and do the following:
    tar xzvf eclipse-jee-ganymede-SR1-linux-gtk-x86_64.tar.gz
    sudo mv eclipse /opt
    # you probably should think twice about chown and chmod, 
    # but I myself make my PC physically secure so don't care
    sudo chown -R user.group /opt/eclipse
    sudo chmod -R 770 /opt/eclipse
    sudo nano /etc/environment # put path to JDK by adding a 
    # line something like JAVA_HOME="/usr/lib/jvm/java-6-sun"
    /opt/eclipse/eclipse # choose your workspace location and start Eclipse
    
    When in Eclipse, just use their instructions on installing PDT:
    Help > Software Updates... > Available Software > Manage Sites...
      Add... > add the DLTK 1.0 interim site: http://download.eclipse.org/technology/dltk/updates-dev/1.0/
      Add... > add the PDT 2.0 interim site: http://download.eclipse.org/tools/pdt/updates/2.0/
      Enable the Ganymede Update site (if not already enabled): http://download.eclipse.org/releases/ganymede/
      Expand the DLTK site and select the Dynamic Languages Toolkit - Core Frameworks or Dynamic Languages Toolkit - 
                                                                                              Core Frameworks SDK Feature 
      Select the PDT or PDT SDK Feature
      Install...
    
  • To make Subclipse plugin work in Eclipse (to be able to use Subversion repositories), aptitude install libsvn-javahl and then nano /opt/eclipse/eclipse.ini and add a line that says (sans quotes) „-Djava.library.path=/usr/lib/jni” just under „-vmargs” line.
  • I’ve finally found a way to change Gnome’s clock appearance, fire up gconf-editor, go to /apps/panel/applets/clock_screen0/prefs, change „format” to „custom”, „custom_format” to something like „<span color=”#99ccff”><sup><b>%A, %d %B %Y</b></sup></span> <big><b><big>%H</big><sup>%M</sup></b></big>” and voila!
  • Even though dailystrips (a script that download comic strips for you) at sourceforge seems to be abandoned, they have updated dailystrips and strips.def at MisterHouse project.

[en] How to mount LVM VG and restore data from it when one of its PV drives has failed

However great LVM is in Linux, allowing one to span single „partition” over several hard drives, if the underlying „drives” are real hard drives and not RAID volumes, You can get pretty fucked when one of those disks fails.

It took me several hours of googling around and trials to find out how to recover as much data as is possible (meaning: all the data that is on remaining disks, the data on failed drive is obviously lost). So let’s try to add a short and working recipe to Google.

  1. You do NOT have to pvcreate any bogus empty PVs with fake UUIDs to replace the failed drive. LVM2 can be used in „partial” mode without all the drives.
  2. To use partial mode, You need to create /dev/ioerror device like this (I use Ubuntu, in other distros it might be different):
    • nano filename to create a text file where a single line „0 9999999999 error” sans quotes should be placed
    • dmsetup create ioerror filename to create a device LVM will read instead of missing PV
    • ln -s /dev/mapper/ioerror /dev/ioerror so it’s just where LVM will look for it
  3. After ioerror is created, just activate your volume group in partial mode using vgchange -P -ay VOLNAME
  4. Mount it (it will mount in read only mode) and copy your precious data

Cheers to these guys who finally written something I could use instead of pvcreate and bogus hard drives discussions.

Virtualmin on Ubuntu 8.04 Server

Notes to myself and Googlers on installing a virtual hosting control panel Virtualmin (a great add-on to Webmin) on Ubuntu server:

  • wget http://software.virtualmin.com/gpl/scripts/install.sh
    chmod 755 install.sh
    ./install.sh
    — installs Virtualmin automatically with all dependencies, with a nice skin which is also used by Webmin (which I remember used to be quite ugly by default)
  • chmod 711 /var/spool/postfix/var/run/saslauthd — fixes login failure when trying to send mail through virtual server
  • it seems apache vhost, ftp, e-mail and DNS is properly configured automatically, will add more info here as I move on with my hosting migration to Virtualmin probably