Friday, February 25, 2005

SSH Tunnelling

I just setup a SSH tunnel from my box to a distant server. It worked fine, with one minor problem.

When I first tried the tunnel, I would get timeouts on the client, and this message on the server session:

channel 3: open failed: connect failed: Connection timed out

What I didn't realize is that in the command ssh -TCN -L 1234:baz.bar.com:2345 foo@baz.bar.com, the first 'baz.bar.com' is relative to the host machine, not the client. As a result, the command connected to the server, but the port forwarding didn't work because the server didn't know about baz.bar.com. Using ssh -TCN -L 1234:localhost:2345 foo@bar.com did the trick, since the server did know about localhost relative to itself, and the client process connected immediately.

Friday, February 18, 2005

Gentoo Reload, Part 2

My Gentoo reload continues fairly well, with a minor hiccup.

I mentioned that the network didn't come back up after my first reboot into the installed system. I found an old post (c. 2002) that mentioned removing certain kernel options; this is outdated info, as removing those options gave an error message saying, in essence, "put them back in".

The actual error message was "cardmgr[nnnnn]: no pcmcia driver in /proc/devices". Loading the 'ds' module (modprobe ds) took care of that, and gave me messages in the system log (/var/log/messages or /var/log/everything/current, depending on which logger you're using) complaining about what module wasn't found. In my case, I had to turn on 3c574_cs and serial_cs, and it worked fine. The only annoyance was that because I had been using genkernel, (which compiles many, many modules), each recompile took several hours. (In my case, several 10-minute evenings, as I made changes, then did the make dep && make clean bzImage ... dance and let it run overnight.)

I'm still left with a question and a curiosity. The question is why the difference between the install and the first boot? (The answer is probably that the installer is a LiveCD, and the installed system is not, but I'm going to ask on the forums to know for sure.)

The curiosity is the LiveCD stuff. There's this post that talks about rolling your own custom Gentoo LiveCD. That just sounds way cool; I could have all my system stuff read-only on the CD, mount drives from other machines over the network for writeable files, and never touch the hard-drive on the local box. (Not sure why I'd want to, but that's not the point, is it.)

Wednesday, February 16, 2005

Strangest Darn Thing (PHP, Apache and a Firefox bug)

I've been running Postgres, and was told of a nifty web-based tool called phpPgAdmin that makes administering PG databases easier, so I tried to install it.

Somewhere early on in my attempts to verify my install, I started seeing this problem when I would try to access the app (i.e. http://localhost/phpPgAdmin/index.php). It would try to make me download the index.php page, and if I clicked okay on the dialog (that said "you have chosen to open ..."), it would save the page to my homedir. Not what I wanted.

So I fiddled, and I futzed, and I tried just about every config combo I could think of. Nothing worked. I reinstalled PHP. Nope. I copied index.php to dave.php, and that worked fine, but the original index.php didn't. (Permissions were identical between dave.php and index.php.)

I Googled several times, and finally decided to put in "you have chosen to open" as part of my search term. This took me to a page that gave me the idea to try replacing the current index.php with a very simple one, (basically just a Hello, World page). Nope, still asked me to download, and when I saved it, it gave me ... the old page?! Now wait a minute! Okay, let's restart Apache. Try again ... still the old page! Now come on...

Okay, let's shut down Apache. Same thing: "you have chosen to open ..."! So Firefox wasn't even going to the server for this. Restart Firefox, try again. Same thing. Yup, somebody's wedged.

I finally, rather than save the file, tried to get Firefox to open it. It sat there, paused; I clicked Cancel and Retry, and it finally said something about not being able to contact the server.

Now, then. Let's start Apache, and try again. Now it works.

Best I can tell, Firefox must've gotten wedged caching this file way early on. Not sure if Apache was complicitous or not, (and PHP and phpPgAdmin seem innocent enough). Grrr.

Tuesday, February 15, 2005

Email From A Coworker


Subject: obligatory linux gloating

Uptime on xxxxxx

10:17am up 648 days, 1:07, 2 users, load average: 1.91, 1.72, 1.40


Go ahead, LAX, boot every month or so. We're here, when you're ready.

Monday, February 07, 2005

Upgrading SuSE

This is old news from me at this point, as I performed this upgrade a while back, and just forgot to blog it, but I'm mentioning it, as it continues to nibble at my hind parts from time to time.

I upgraded my SuSE install. Apparently, I went from 9.1 Server to 9.2 Workstation, or somesuch, and it removed a bunch of stuff. Like PostgreSQL and Ant, among other things. And when I went back to install those two things off the 9.1 disks, it thought I wanted to downgrade everything. Harumph.

It would have been nice to have had YaST mention that I was doing this. Techically, it said that it was removing outdated packages, but during an upgrade, that's what's supposed to happen, IMO. I didn't make the connection that those particular packages wouldn't be reinstalled, and it wasn't until much later, when I couldn't even find PostgreSQL in the package list, that I realized I had switched products. (In my defense, Boss just handed me the disks and said "here, dude, upgrade your box".)

I "fixed" things by pointing YaST at a full online 9.2 mirror, at which point it had the full list of packages to choose from.

Then today, I reinstalled ant. Okay, fine. But from within Eclipse, ant found javah just fine; from the command line, it didn't. Solved it by installing SuSE's ant-nodeps package. Eclipse includes everything ant needs, apparently, and doesn't expose it to the command line version.

Wednesday, February 02, 2005

Postgres and bigint

We're putting together a database design. In this design, we decided to specify all of our primary keys as bigint, as we're going to make them unique across the system, and we'll (hopefully) have more than 2^32 rows system-wide.

Somewhat unrelated to this, Boss came up with a question about foreign keys, wondering what the performance would be on them if we wanted to do ON DELETE CASCADE between two large tables. So I went to investigate.

My first try, to delete a row on an ON DELETE RESTRICT table that still had fk referrers, went quite fast. Seems I picked a key that was at the top of both tables. Fortunately, I thought to try a key at the bottom of both, and sure enough, it was doing a table scan.

I checked my indexes, and added one, on the fk column. Seems like it would be reasonable to have the db add one as part of the fk constraint, but maybe not.

But even with indexes, it still did a full table scan. I poked around, and found that even a pk search was doing a table scan. After a good deal more poking, I Googled, and found that indexing bigints is buggy under PostgreSQL 7.mumble (i.e. the indexes won't get used, ever), but that under 8.0 works fine. Fortunately, one of our newer servers was already running 8.0, so I tried it, and voila, worked fine.

So now I'm moving my box up to 8.0 as well.

(Minor note: I didn't track down the actual source of the problem, but was just satisfied with moving up to 8.0. Just so you know.)

Tuesday, February 01, 2005

Gentoo Reload

Just for grins, I decided to reload my old laptop with Gentoo.

For those following along at home, I had put (and praised) SuSE 9.1 on this laptop, but it didn't detect my PCMCIA NIC, and the video card itself had been fritzing, making X less than usable, and displaying the root console with huge borders (i.e. using only 1/4 of the screen). I'm now wanting to run the laptop essentially as a server, with VNC handing the display, and letting another box do the actual I/O.

So I downloaded the universal CD via BitTorrent (in part to be able to seed it when I was finished), and popped it in. It detected all my stuff, including the PCMCIA NIC, and had no graphics problems (although it didn't run X, either). All went swimmingly, until I rebooted, at which point it didn't find PCMCIA, and the root console was small again. At present, I'm not all that interested in an extended troubleshooting session, especially as the install CD worked flawlessly.

But it also makes me curious what they use for the installer, and whether or not I could just use that. I glanced at Knoppix, as I have this vague feeling they do something similar, but I'm thinking that I'll go play in the Gentoo forums for a while and see if I can get any pointers.

More as it unfolds.

String vs StringBuffer

On a lark, while a particularly long data load was going on, I wrote some code to try out timing the differences between doing string concatenation with a StringBuffer, versus just writing out String math. The different in timing was surprising.

Of course, no entry like this would be complete without quoting Hoare and Knuth, that Premature optimization is the root of all evil. If String math is clearer, it should be used until there is a clear reason to do otherwise, IMNSHO. There, I said it.

Having said it, I wrote this:


String bigLongString = "cranky ";
bigLongString += "poodle ";
for ( int i = 0; i < 100; ++i )
bigLongString += "frank ";
bigLongString += 25;
bigLongString += " times. Hoorah!";
return bigLongString;


and ran it 10,000 times. On my machine, it took around 14.2 seconds to run. I changed it thusly:


StringBuffer sb = new StringBuffer();
sb.append( "cranky " );
sb.append( "poodle " );
for ( int i = 0; i < 100; ++i )
sb.append( "frank " );
sb.append( 25 );
sb.append( " times. Hoorah!" );
return sb.toString();


and it took around 0.92 seconds to run 10,000 times. I changed it again to reuse the same StringBuffer (via sb.delete( 0, sb.length() );), and it took around 0.5 seconds to run 10,000 times.

That's a pretty stark difference in times, and pretty surprising, too, that reusing the StringBuffer would halve the execution time again as well.

(For the curious, "Cranky Poodle" is a parody of "Yankee Doodle", as can be found in the book Take Me Out of the Bathtub, by Alan Katz, and is a hilarious book.)