• New server power consumption

    Power consumption of various computers, as measured with the handy Kill-o-Watt
    • 2012 Linux server. 50W – 120W
    • 2011 iMac. 50W – 210W
    • 2010 Windows PC. 120W (always!)
    • 2003 Linux server. 50W

    I like how the iMac numbers line up. The iMac has a GPU and a large LCD, so it maxes out higher, but when idle it’s about the same as the Linux server. It’s a very similar motherboard and the same CPU, so that all makes sense.

    I don’t quite understand why the idle Linux box is using 50W and not, say, 10W. I don’t think the Intel CPUs will completely shut down a core when idle, that’s part of it.

    Update: some useful notes from Intel and on SuperUser. Taking cpus offline via /sys/devices/system/cpu/cpu3/online didn’t save me any power. Either idle CPUs take very little power (unlikely) or the comment on SuperUser is right that this doesn’t halt the processor. The /sys/devices/system/cpu/sched_smt_power_savings also didn’t save me any power. I think sched_mc_power_savings would be useful, but it’s missing on my system. Apparently I need to rebuild the kernel with my processor family to enable it.

    Update2: according to this article at low power an i7-2600 uses about 5W. Their measured idle system power (whole computer) is about 70W, so my 50W is in line. Where does it all go?!

    At $0.33276/Kwh, every extra watt costs me $0.25 a month.

  • Python script to find Amazon store MP3 files

    I’m working on rationalizing my MP3 collection.  Here’s a Python script to print out the names of all songs that seem to have been bought from Amazon MP3. It uses the presence of “Amazon” in the ID3v2 comment tag. It’s not entirely reliable; songs I bought in 2007, 2008 are missing that tag.

    
    #!/usr/bin/python
    
    """Print out names of MP3 files that are from Amazon.
    Works by looking for the Amazon ID3v2 comment tag with a song ID.
    This method is not complete: some early Amazon sales don't have this."""
    
    import sys, os
    from mutagen.id3 import ID3
    
    def isAmazon(fn):
      "Return the Amazon comment if it's an Amazon MP3, else None"
      id3=ID3(fn)
      for c in id3.getall('COMM'):
        if "Amazon" in str(c):
          return str(c)
      return None
    
    for dirpath, dirnames, files in os.walk('.'):
      for name in files:
        if name.endswith(".mp3"):
          fn = os.path.join(dirpath, name)
          try:
            if isAmazon(fn):
              print fn
          except:
            pass # ignore errors
    
    sys.exit(0)
    
  • Realtek ethernet drivers: r8169 vs r8168

    Update Jan 2013: this driver issue was fixed in Ubuntu 12.04 / kernel 3.2.0-14 or so.

    Ubuntu doesn’t work out of the box with my ethernet adapter. The ethernet interface is very slow to come up after boot, taking 10-120 seconds. The problem is the Realtek 8111 or 8168, a very common motherboard ethernet adapter. The motherboard docs say it’s a Realtek 81111E. The Linux drivers are broken. Apparently this is a common problem across many Linux variants and people report other problems, too, packet loss and dropped packets. It’s a four year old bug in Ubuntu! How to fix it? (Other than buying a new NIC; Realtek NICs are not well loved.)

    I did a lot of research. One proposed fix is to get a different device driver, from Realtek, not the Linux kernel sources. (More notes). Another suggestion is to enable Wake-on-LAN (via Windows), but I don’t really believe that will work. A third option is to upgrade kernels, there’s some possibility that the mainline Linux driver is better. (Most recent Ubuntu bug is 864196).

    I decided to try Realtek’s driver. r8168-8.027.00. md5sum:
    98155ce1ad5c248eeb7a93c9954d8344  /tmp/r8168-8.027.00.tar.bz2

    Sadly, it doesn’t fix my problem. The NIC still takes 10-200 seconds to come up after boot. I also tried enabling wake-on-lan (via Linux, ethtool) and that didn’t fix it either. No surprise but I thought I’d give it a shot. I’m left with the conclusion there is no fix for this bug right now, despite the superstitions about Wake-on-LAN, or r8168 drivers, or whatever.

    BTW, the autorun.sh script that comes with the r8168 driver from Realtek is pure evil. First, it unloads your ethernet driver. Completely killing your machine if you’re logged in via ssh and don’t have physical access! Then it goes and rewrites a bunch of stuff in /lib/modules and rebuilds your initram disk. It seems to get this right, but it’s awfully intrusive. I finally removed r8168.ko by hand and did an “apt-get install –reinstall  linux-image-3.0.0-15-server” to set things back.

    I’m going to try living with this bug; I never reboot the box anyway. The first time I experience massive packet loss, or the ethernet doesn’t come up after boot, I’m getting a real NIC and putting it in a PCI slot. And never again buying a motherboard with a Realtek NIC for Linux use.

    Details from lspci -v from stock Ubuntu, before I tried adding the r8168 driver:

    
    03:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller (rev 06)
     Subsystem: ASUSTeK Computer Inc. P8P67 and other motherboards
     Flags: bus master, fast devsel, latency 0, IRQ 45
     I/O ports at e000 [size=256]
     Memory at d0004000 (64-bit, prefetchable) [size=4K]
     Memory at d0000000 (64-bit, prefetchable) [size=16K]
     Capabilities: <access denied>
     Kernel driver in use: r8169
     Kernel modules: r8169
    
    
  • Configuring lm-sensors for Asus P8Z68-M-Pro

    The temperature, fan, and voltage sensors in my fancy new Asus P8Z68-M-Pro motherboard weren’t recognized right out of the box. I fixed it by installing a custom kernel module and then telling the sensors(8) program to ignore some bogus readings.

    The motherboard has two sets of sensors. coretemp-isa-0000, from the Intel chip, and nct-6776-isa-0290, from the motherboard. That second chip requires a custom kernel modules which I got from Guenter Roeck: w83627ehf. Easy to build and install, and afterwards sensors(8) shows lots of data.

    Some of the data is bogus (see  this github issue), so I fixed it by dropping the following file in /etc/sensors.d:

    
    # Configs by nelson to hide bogus values on my ASUS P8Z68-M PRO motherboard,
    # which uses an nct6776-isa-0290 chip.
    
    chip "nct6776-*"
     # These are not configured in sensors3.conf
     ignore in1
     ignore in4
     ignore in5
    
    # Fans I don't have plugged in
     ignore fan1
     ignore fan3
     ignore fan4
     ignore fan5
    
    # ignore CPUTIN and AUXTIN; bogus values
     ignore temp2
     ignore temp3
    
    

    Those in and temp sensors are returning meaningful data, but they’re not configured correctly in the default /etc/sensors3.conf and I’m too lazy to track down exactly what they might mean. One of those fan sensors probably is for the chassis fan, but mine isn’t plugged in to my motherboard.

  • Disk and data transfer rates

    All these disks and stuff have me confused about what fast transfer rates are. Here’s some numbers, mostly practical rates, not theoretical. All numbers are Megabits / second. See also the Wikipedia List of device bit rates.

    • 168,000: RAM for an i7-2600 (theoretical) (ref)
    • 10,000: HDMI v1.3
    • 6400: PCI (64 bit, 100MHz)
    • 5000: USB 3.0 (theoretical)
    • 4800: 6.0Gbit SATA
    • 2400: 3.0Gbit SATA
    • 800-4000: SSD drives (ref)
    • 1000: 7200 rpm hard drive disk-to-buffer (ref)
    • 1000: gigabit ethernet
    • 800: IDE, UDMA 5 aka Ultra ATA/100 (ref)
    • 250-480: USB 2.0 hard drive (ref)
    • 100: 100M ethernet
    • 30: fast US home Internet
    • 20: 802.11g wifi (ref)
    • 12: USB 1.0
    • 6: my crappy home DSL
    • 1: AT&T 3G downloads (ref)
    • 0.05: old acoustic modems
    Bottom line: USB 2.0 is a little slower than a desktop hard drive. And SATA is significantly faster than a hard drive. I wish I could narrow the SSDs down, I think performance on those things varies quite a bit. My friend Lars just built a RAID 5 array of SSDs that’s showing about 10,000 Mbit/sec.
    Some practical tests on my brand new Sandy Bridge server with 7200 RPM disks plugged into SATA/6 and formatted ext4fs. All numbers are Megabits/second
    • 1000: hdparm -t, testing disk read throughput from the platter
    • 110,000: hdparm -T, testing read from RAM cache (ie: never touching SATA or disk)
    • 1088: writing 16 gigs of zeroes
      dd if=/dev/zero of=zeros bs=1M count=16384
    • 440: copying 16 gigs of zeroes on a single drive
      dd if=zeros of=zeros3 bs=1M
    • 872: copying 16 gigs of zeroes from one drive to another. Parallelism!
      dd if=zeros2 of=/tmp/zeros bs=1M
    • 570: rsyncing 300 gigs of files from a FAT32 drive over USB-3 to an SATA/6 drive.
    • 20,000: writing 1 gig of zeroes. ext4fs must fully cache this before commit
      dd if=/dev/zero of=zeros5 bs=1M count=1024
    • 88: creating a file of random bits from /dev/urandom. I had no idea that driver was that slow.
    These tests are all for big files. Linux gets a lot slower when dealing with lots of little files. Running rsync from a USB 2 disk copying to an SATA disk I’d see a factor of 10 difference in disk throughput between giant files and lots of tiny files.

  • The new Linux server

    Here’s the parts I’m getting for my new server. Many thanks to Adam for sharing his system build of a few months ago. This system’s remarkably similar to a new iMac, albeit without the SSD. By all accounts this Sandy Bridge stuff is terrific.

    1 of: Antec 380 Watt Power Supply Mid Tower Case NSK4482B (Black) $89.99
    2 of: Western Digital 1 TB Caviar Blue SATA III 7200 RPM 32 MB Cache Bulk/OEM Desktop Hard Drive – WD10EALX $129.08
    1 of: Intel Core i7-2600 Processor 3.4GHz 8 MB Cache Socket LGA1155 $295.00
    1 of: ASUS SATA 6 Gb/s DisplayPort Intel Z68 Micro ATX DDR3 2200 Intel LGA 1155 Motherboards P8Z68-M Pro $119.99
    1 of: Corsair 16 GB (4x4GB) Vengeance Blue Low Profile 1600mhz PC3-12800 240-pin Dual Channel DDR3 Memory Kit 16 Dual Channel Kit – CML16GX3M4A1600C9B $89.99

    Junky case and very simple disk system. I won’t even run RAID, don’t trust it. No SSDs either, don’t trust those consumer parts. Just simple spinning platters. Some of the details matter. The i7-2600K is more popular because it’s overclockable. But I never overclock, and it turns out the i7-2600 has some virtualization capabilities that the i7-2600K doesn’t. It’s clear the Z68 chipset is the best motherboard, and I went with ASUS just because I always have. But they make like 6 Z68 motherboards and I can’t really tell one from the next. (After building this I learned the Realtek ethernet chip in the P8Z68 M Pro doesn’t work well in Linux. The P8Z68-V boards have Intel ethernet chips, may be a better choice.)

    I told myself years ago I’d never build another computer from parts. Yet here I am. The local screwdriver shops are charging too high a premium, and then it’s a struggle to get them to understand you really want no graphics card, no OS, really just the simple server. “Oh, a server? How about this $4000 2U rackmount?”

    At least I already know all about Ubuntu server.

  • IDE, the obsolete standard

    My home Linux server died. We had an ugly power outage and when the power came back up and when I turned on the computer, out came the magic smoke. I hope that just the power supply fried, or maybe the motherboard, because I don’t have a backup of the data on the hard drives. 15 years of data, programming, photos, financial records, email, writing. It’s very unlikely that the data is gone; worst case, I send the platters to a data recovery service. But it sucks.

    I’ve ordered the parts to build a fancy new computer. It’ll be an awesome fast upgrade based around Sandy Bridge parts. My plan was to install Ubuntu on the fancy new SATA drives, get things sort of working, then plug in the old IDE/PATA drives to copy the data over.

    The motherboard doesn’t even have IDE ports.

    When did that happen? When did IDE become so obsolete they don’t even put ports for it on a motherboard? I mean, the motherboard still has PS/2 keyboard, old school serial, parallel. No IDE. Ugh. I’ve ordered a USB adapter to get data off the old drive. Amazon is full of these jobbies for $7, complete with 10+ one star reviews saying “the power supply is junk and fried my drive”. Awesome. The one I picked has the most reviews and almost all are positive.

    I’m not so stupid as to not have any sort of backups of the data. I have a complete rsnapshot mirror. On a second drive, in the dead machine, the one that might have sent a surge of death through every plugged in component. Yeah, didn’t think through all failure modes. I am committed to doing real offsite backup of all my computers now. I have CrashPlan on the Mac already; something for Linux will be coming.

    While I’m waiting for the adapter I tried playing with an old USB drive enclosure I had lying around, thinking I could put the drives in and plug them into my Mac to reassure myself the data is still there. Turns out mounting ext3fs on MacOS is a clusterfuck. fuse-ext2 is the recommended way but MacFuse doesn’t work on Lion and is abandoned and all the Fuse folks have scattered every which way. This blog post claims that OSXFuse + Fuse-ext2 will work on Lion, but I don’t have enough confidence in all this jury rigging to bother trying it. I’m much more comfortable recovering data in a Linux system.

  • Organizing all my git

    I use git enough now that my repositories are getting a bit messy. I decided to centralize them all in one place so I can access them over the network. (You know, the distributed part of DVCS). There’s lots of options, I settled on just using a bunch of bare repositories on a host I can ssh to.

    Alternatives I considered.. Dropbox is a good alternative for the central git repository but I’ve got my own server so I’m using that. The git:// protocol seems like unnecessary complication. As for hosting and web frontends.. GitHub is too expensive for my 10+ private repos,, charging per repo. Sites like repositoryhosting, gitorious, codeplane, and bitbucket have cheap or free options, but I don’t really need a centralized host since I’m mostly working alone. I could also have gotten fancy and installed something like gitolite to have a webapp front end, but that’s overkill for me now. Maybe I’ll set up gitweb at some point.

    Here’s how I migrated my exisiting ad-hoc repos to one canonical gitrepos directory on a server. I found a lot of conflicting and incomplete info on how to do this, for instance these notes, this blog post, and this stackoverflow post. Correctly getting all branches into the new canonical repo and then patching up the config of the old ad-hoc repo is not straightforward. I’m not confident this is really correct, either, but it seems to work for simple things.

    
    Find all the .git repos. Still have to hand-edit this list.
    $ find ~ -type d -name .git | egrep -v '/d3|polymaps/'
    
    Create a new bare repo in my new ~/gitrepos directory, based on code from ~/src/dotfiles.
    $ cd ~/gitrepos
    $ git clone --bare ~/src/dotfiles dotfiles
    $ # is this a good idea? necessary?
    $ # cd dotfiles; git remote rm origin
    
    Change my old ad-hoc repo to consider this bare repo as its origin.
    $ git remote add origin ~/gitrepos/dotfiles
    $ git push
    $ git branch --set-upstream master origin/master
    

    That bit about pushing and then setting the upstream is 100% black magic for me, I have no idea what it does. It seems to be necessary to create the magic so that later “git status” will tell you if your local branch is ahead of the canonical copy in ~/gitrepos.  The push is necessary for some git config reason, even though there’s nothing to push. I find it confusing how git uses branches to track remote repos.

    Also useful: “git remote -v” for seeing what remotes are configured, and “git branch -avv” for seeing more about git’s local view of various branches and remotes.

    None of those examples above use a really remote repository, it’s all just Unix file paths. You can so name repositories like “nelson@example.com:~/gitrepos/dotfiles” and it will ssh to example.com and everything just works.

  • NTP phase lock loop

    This Munin graph is a nice example of NTP dialing in accurate time. X axis is 24 hours, Y axis is jitter. ±1ms of jitter. It’s absurdly accurate.

  • About this blog

    A few folks have subscribed to this blog recently. Welcome! I am not writing for you. I am truly, only, writing work notes for myself. Stuff I learn and don’t want to forget. You’re welcome to read along, comment, share, whatever. But this post is probably the last time I’ll ever think about what you think, dear reader.

    My real blog was also intended to be written for myself but somewhere along the way became a publication medium. When I write there I care to be clear, grammatical, concise, interesting. Here, not so much.