Sunday, June 15, 2008

I'm a stickler for quality. And a cheapskate at heart. Conflict arises, especially when I'm getting into a new hobby or activity.

A couple of cases in point:

About a year ago I wanted to buy one of these new digital oscilloscopes. They have LCD displays, can capture signals, and do real-time analyses on the inputs. Neat stuff, and much better than their analog predecessors.

Like most things, they come in a variety of price points. The cheaper units has B&W LCD displays and narrower bandwidth. Being my first digital o-scope, I bought a used one off eBay for about $200. After playing with it for a few hours, I wanted more. More bandwidth, faster display, color.

My next purchase was a new, Chinese-made color LCD unit for about $1,000. It had great reviews online and, indeed, it's a nice unit. But although it had a huge memory for capturing digital signals, the display was kind of "noisy" and it didn't quite have the bandwidth I lusted after.

Finally, I purchased the unit I should have bought in the first place: a Tektronix TS3012 color LCD digital storage oscilloscope for about $1,200. It's fast, built like a tank, and still supported by Tektronix even though it's used (another eBay purchase).

In other words, I spent on my dream 'scope the same amount of money I spent on the first two 'scopes that are now sitting on a shelf. I spent double, needlessly.

Another case in point: as a teacher, I'm getting more into online instruction. And I might dabble in podcasting. So I bought the typical starter kit:

Basic condenser microphone (Audio-Technica 2020), $100.
Basic mixer (Behringer 802), $60.
iMic USB interface, $50.

But I quickly ran into limitations. Being a condenser mic, the AT2020 picked up way too much room noise for my taste. So I upgraded to the Electro-Voice ND767A super-cardioid dynamic, $130.

The wimpy Behringer mixer was quickly replaced with a Yamaha MW10C, $200.

Boy, that Heil PR-20 microphone sure is looking nice. Heil, known among podcasters for its PR-40 studio microphone, makes great microphones right here in the USA. Well, better order one of those. ($150)

Then I start really getting into different ways that might students might be "calling" into class: either through CCCConfer or through Skype. I need a way to cross-mix the two inputs. And I'd love to have Firewire so I can send all the audio inputs to the computer separately, rather than mixing them down to a single stereo track. That Yamaha mixer just isn't going to cut it.

So, off to eBay to get a Mackie Onyx 1220 Firewire mixer, $800.

After using it for a few hours, I still can't quite get the inputs to mix correctly. Next purchase, Behringer UB1622FX mixer along with a Behringer UCA202 USB interface (to be used in conjunction with the iMic). Total for this purchase: $170.

But wait! I think I might be able to get the Mackie to do what I want! Too late, the Behringer is on its way.

Finally, here we are on Sunday evening. I'm lusting after that Heil PR-40 again -- the microphone I should have bought in the first place.

Sigh.

Wednesday, March 12, 2008

Finding the median value in SQL

Most SQL dialects don't come with a median function. But one can be cobbled together using the procedural programming language that accompanies most databases.

They work like this:
1. Sort the list of values.
2. Count the number of items in the list.
3. Select the element at position n/2.

A function like this can't be expressed purely in SQL because SQL is not procedural.

I've come up with a median function that uses pure SQL:

select age
from person
where (select count(age) from person p1 where p1.age >= person.age) -
(select count(age) from person p2 where p2.age <= person.age) between 0 and 1;

This technique uses two correlated subqueries. The outer query works through the list of values (in this case, age). As it considers each age in turn, it counts the number of ages that are greater than the target age and the number of ages that are less. The difference between the two should be 0 or 1 (depending on whether there are an odd or even number of ages to consider).

When the difference is 0 or 1, you've found the median value.

This solution is O(n2). Expect it to take a long time on large data sets.

Sunday, March 9, 2008

I'm so excited, and I just can't hide it!

As you know from one of my previous posts, I have a list of things I'd like to do during my lifetime. My upcoming sabbatical is going to give me some elbow room to get a few of the items checked off!

During my spring break, I'm going to make a hologram. I've already got all the raw materials: laser, holographic plates, chemicals. After a quick trip to Home Depot, I'll have the pieces needed to build the table on which holograms are made.

Right after school lets out, in May, I'm heading to Florida to watch the next Space Shuttle liftoff. I've built into my schedule a few extra days in case it doesn't blast off on time. As long as liftoff is within three days of the scheduled date, I'll be OK.

2008 is going to be a great year!

Monday, October 22, 2007

Time Machine: not just for backups

Time Machine occupies just a few bullet points in Apple's list of 300+ new features in Leopard. But it has the ability to fundamentally change the way you and I use our computers.

Disclaimer: I have not actually used Time Machine. My only knowledge of it comes from the public videos and demos and from reading the Mac sites like MacInTouch and The Unofficial Apple Weblog.



From the Apple literature, Time Machine is an easy way to retrieve your lost files. It's being introduced it like that because it's simple to understand. If you've accidentally (or purposefully) deleted a file, you can simply use Time Machine to find it and bring it back. For this use, it's not much different from any other backup software. But the similarity ends there. This is not SuperDuper.

Time Machine maintains a complete history (at hourly intervals) of every file on your computer. To put it a different way, every hour it takes a "snapshot" of your computer and stores the way it looked at that moment. These snapshots comprise a set of "versions" of your files. Time Machine gives you a way to retrieve those versions.

Time Machine is not simply a backup of the way your computer's files currently look. The term "backup" implies a second copy of your current files. Stop thinking about backups. Start thinking about versions. Think about three, four, ten, hundreds of copies of your files, each representing the way it looked at a particular point in time.

Here are a few scenarios that use versions--rather than backups of lost files--as their centerpieces.

Have you ever worked on a long-term project? One that spanned more than a few hours? It could be a project for work. Or it could be that Great American Novel you've been writing. Or an iMovie project of your last vacation. You haven't deleted it; you've simply been changing it. Have you ever messed it up so badly (and saved your mess) that you wished you could go back to the way it was earlier in the day? With Time Machine you can. Just roll back through time to find the last good version of your project. You can use Quick Look to glance at the document to verify it's the one you want. When you find it, restore it.

Some documents are ever-evolving. For example, a real estate office may have a letter they mail out to new clients periodically. When they want to send out a letter, they just change the address and a few words here and there to customize it. Because the document evolves, today's version bears little resemblance to the one they sent out six months ago. What if they wanted to see what the letter looked liked back then and compare it to today's? They can with Time Machine. They don't even have to restore it; just use Quick Look to peek at it.

I'll leave you with this one final revolutionary usage of Time Machine. Most of us have an ever-increasing number of files on our computer. Organizing it all is becoming a chore. We download new files or create them constantly. They clutter up our folders and Desktop. It's maddening. And we should be backing it all up. Of course, you know that Time Machine will help you do the backups.

But think about this: Download or create a new file. Use it for its intended purpose now. Keep it around for an hour or two. Then throw it in the Trash. That's right: don't think about how you might want to use the file later. Never mind that your co-worker will be needing it next week. Or that you might want to refer to it next month. Throw it away now. De-clutter your life. Or at least your Mac.

Ah, don't worry. Time Machine has it. You can always get it back later. Spotlight can help you find it.

This may change the way we build computers. No longer will you need a gigantic primary hard drive that holds all your files, plus an equally monstrous hard drive to back up it all. Instead, your computer has a lean, fast primary storage device big enough to hold the files you're using right now. A few GBs of flash memory will do for most people. The rest--a complete history of every file you've ever worked on--is stored on a large-capacity Time Machine device.

That's the future of computing. Look out, because in a near-future release of OS X, I predict that Time Machine will be the filesystem. There will be no distinction between your "current files" and your "backup files." All your files, current or not, will simply be versions stored in a searchable database. Solaris' ZFS technology will help make that happen.

Saturday, October 6, 2007

Lifetime To-Do List

Doesn't everyone have a list of things they'd like to accomplish/do/see before they die? Here's mine, in no particular order.

See a space shuttle launch.

Experience weightlessness.

Visit Antarctica.

Visit Alaska.

Visit China.

Write an application that gets used by more than 100 people.

Make a hologram.

Make a daguerreotype.

What's yours?

Tuesday, August 21, 2007

iPhone features I'd like to see

OK, I'm thiiiis close to getting an Apple iPhone. I'd have to break my contract with Verizon. But there have been so many times that I've been out and about and wanted to quickly look up something on the web. Or check my email to see if I've been outbid in the last 10 seconds on a digital oscilloscope auction, again.

I've used my friends' iPhones and played with them in the store. As a result, I'm tempted to wait until software updates or a new iPhone model comes out. There are some nifty features missing on the current version that it desperately needs to be really, really usable.

GPS

Think about it: how many times have you been in an unfamiliar town (or even a familiar one) and wanted to know something like "where are the Italian restaurants nearest to me right now?" or "where's the nearest Post Office?" With the current iPhone, you can bring up Google Maps, which is great, but you still need to know what city or ZIP code you are in. What if you don't know your exact current location? You're screwed, because either you can't search at all or you get way too many results.

What I'd like to see is a way for the iPhone to know its current location. GPS would be great, as it would give your location to within 10 feet or so, but for Google maps an exact location isn't necessary. Even knowing your approximate current location would be good enough. I don't know much about cell technology, but I imagine that each cell tower knows its own location. The iPhone could do some triangulation to figure out where it is in relation to the towers, at least well enough to make Google maps searching incredibly useful.

Voice Dialing, Done Right
I use voice dialing when I'm driving. With my headset on, I just touch a button on the phone and ask it to dial one of the people in my contact list. Here's how the conversation with my phone usually goes:

Me: Call Brenda
Phone: Did you say, "Call Brenda?"
Me: Yes
Phone: Which number?
Me: Mobile
Phone: Calling...

My phone has a voice-recoginition system that doesn't need training ("voice-independent recognition"). That is, out of the box, it's able to listen to the user's voice and match it with a name in the contact list. But because the voice recognition isn't tuned to a specific voice (mine), it needs to double-check the match. Hence, the question "Did you say...." What gets me is that it is always correct!

Phone manufacturers, unfortunately, have decided that implementing voice-independent recognition is inherently a binay decision (either it's used for all contacts, or it is not used at all) and, if voice-independent recognition is not used, training it is inherently modal. That is, in order to train the phone to recognize names, the user must go into a special "training" mode.

What I want is a phone that learns.

When I answer "yes" to the query "did you say...", the phone should immediately remember what I just said. The next time I ask to call that name, the training will have already been done. That should be the extent of training the recognition system -- totally transparent to the user.

Games
I need my Tetris and Bejeweled!

VOIP
That's Voice Over IP or, in layman's terms, Skype. Not going to happen, though. The purpose of a mobile phone is to make the carrier rich by charging for minutes of airtime.

On the other hand, T-Mobile is rolling out a new service called T-Mobile Hotspot @ Home in which a WiFi-enabled mobile phone can make free call when in the presence of a WiFi hotspot.

So who knows, maybe we'll see Skype on the iPhone yet.

Saturday, August 18, 2007

Airport Extreme Cripples Write Throughput

There is a major problem with the Apple AirPort Extreme involving its "AirDisk" feature. I have the "older" 100BaseT model to which I have attached a USB hard drive to share among my various Macs. There have been many postings on the Apple Discussion Boards about poor disk performance when the Airport Extreme is used to share disks. While some users report slow throughput, others claim to have no issues at all.

I have confirmed, through testing, that some USB disks do indeed exhibit very poor write throughput when compared to other USB disks. This could have a serious impact for anyone using a USB disk with an AirPort Extreme, especially when used for its intended purpose: to do unobtrusive backups.

Background
This problem was first brought to my attention when I purchased an Other World Computing (OWC) Mercury Elite Pro "Quad Interface" enclosure. In it I placed a Seagate Barracuda 3.5" 400GB SATA drive. This enclosure, which sports four types of interfaces (USB 2.0, FW400, FW800, and eSATA) for attaching to a computer, performed admirably over FW800 when connected directly to my PowerMac G5 tower. But when I connected it to my Airport Extreme, throughput suffered. Writing to the drive was especially bad.

The drive enclosure is manufactured by Newer Technologies. Many emails with their technical support division turned up no solutions. In fact, Newer's tech support denied that there was any kind of performance issue.

In desperation, I connected up an old "generic" USB enclosure with an even older 20GB IDE hard drive. To my surprise, throughput was quite good. Clearly, there is some bad interaction between the AirPort Extreme, the USB enclosure and its internal driver circuitry, and the hard drive.

Ultimately, I wanted a nicer enclosure that would fit under my AirPort Extreme. I settled on the miniStack v3. Like the Mercury Elite Pro, the miniStack v3 is also a quad interface enclosure. It, too, is manufactured by Newer Technologies. I also purchased a 500GB Hitachi SATA drive. After hooking everything up, the results were the same: write performance through the Airport Extreme was poor.

Finally, at wit's end, I decided to settle this once and for all and run some tests. I suspect that there's something about the Newer Technologies driver circuitry that is reducing throughput. I wanted to pit the miniStack against the cheapest USB enclosure I could fine. In the tests, I attempted to eliminate as many variables as possible. The only variable would be the USB enclosure. I also tested a direct USB connection to the Mac to obtain baseline figures.

The Hardware
Two enclosures:
Newer Technologies miniStack v3 with quad interfaces ($120, from OWC);
AverTech SATA HDD Enclosure with only a USB 2.0 interface ($35, at Fry's).

One hard drive:
Seagate Barracuda 7200.10 3.5" 400GB SATA hard drive.

Two connection types:
Directly connected to the Mac via USB cable;
Via the AirPort Extreme, using 100BaseT Fast Ethernet (not wireless). AirPort Extreme running v 7.1.1 firmware.

Methodology
I ran eight tests. Four were "read" tests and four were "write" tests. All tests used the same 600MB mix of files and folders. The files ranged in sizes from under 1K to over 200MB. Before each write test, the drive was reformatted as HFS+ with journaling using the Apple Disk Utility.

The results are as follows (click for larger version):


In all tests, the miniStack is no faster than the "cheapie" USB enclosure. In fact, it's always slower. But most alarming is the write throughput via the AirPort Extreme. The miniStack is takes almost twice as long!

Also worth noting is the noise the drive makes when performing the tests. In seven of the eight tests (all except the slow write test noted above), the drive is nearly silent. All I can hear is the motor and a very quiet clicking as the heads move back and forth. In contrast, during the AirPort Extreme write test using the miniStack, the drive is very loud. The heads can be heard noisily clacking back and forth. Something different is clearly happening with the miniStack.

Conclusion
The OWC Mercury Elite Pro "Quad Interface" and the Newer Technologies miniStack v3 both behave nearly identically. I suspect that the internals of both enclosures are pretty much the same, as they are both made by the same manufacturer (Newer Tech) and both are quad interface devices. Both enclosure exhibit very slow write throughput and create lots of noise when connected to my Mac via the AirPort Extreme.

The AverTech USB enclosure (the cheapest thing I could find at my local Fry's) is identical in performance to the miniStack except when writing files via the AirPort Extreme. In that test, it is much faster and much quieter.

I suspect that there is some kind of bad interaction between the Apple AirPort Extreme and these "multi interface" enclosures. A no-name USB-only enclosure soundly beats a name brand multi-interface one. Someone, either Apple or the USB drive enclosure manufacturers, needs to explain these dismal throughput numbers.

I've learned one thing for sure: spending more -- a lot more -- on an enclosure doesn't necessarily get you better quality or higher speed.

Update (7:35 pm)
Just for grins, I included two more enclosure and drive combinations in my tests. All told, they are:

Newer Technologies miniStack v3 with Seagate 400GB SATA drive
AverTech "generic" USB with Seagate 400GB SATA drive
CompUSA "generic" USB with Quantum 20GB IDE drive
OWC Mercury Elite Pro Quad with Seagate 400GB SATA drive

Results (click for larger version):


Interestingly, the old Quantum IDE drive fared better in the AirPort write test than any of the others! I can't account for that, but I do know why its read speeed over direct USB is slower: it has a longer rotational latency and therefore takes longer to access data.

The whole point of the graph is to show that the Seagate SATA drive performs poorly in the Airport write test whether its in the miniStack or the Mercury Elite. Something is definitely wrong with this picture.

Update update (Aug. 21, 1:15 AM)
A reader suggested turning off HFS+ journaling on the external drive. I did so and clocked the fastest AirPort write time yet: 125 seconds for the 600MB of files. Throughput rises to an astonishing 4.8 Mbytes/sec! USB 2.0's maximum practical throughput is around 30 MBytes/sec. Fast ethernet can pump data at approximately 12 Mbytes/sec. Who knows what the internal disk transfer speed is of the Seagate drive, as Seagate does not publish that spec. I would expect performance of the overall system to be 6-9 Mbytes/sec.

Still, this points to a problem with the AirPort firmware: writing to HFS+ journaled multi-interface external disks is extremely slow. HFS+ with journaling is the default for newly-formatted disks, so there should be no reason why an ordinary user would need to turn it off.