2011/02/08

Nice one Google

I might complain about computers a bit. OK, maybe I complain about computers a lot. But last night something jumped out at me that is Just Right. I was trying to find details of a Western Digital hard drive. I'd forgotten that they have wdc.com, as opposed to to the completely unused wd.com. Anyway, I googled "western digital" and noticed the following:

YES! That is so useful, it makes you wonder why they didn't have it before. Or did they and I only just noticed.

Also works: Asus, CPAN, boardcom, youtube. (Woah, 'you' returns youtube. OK, maybe not so strange, considering who owns youtube.)

I wonder what it takes to get the site-search treatment, because the following don't work: Linux, Perl, Apple, Wacom.

2011/02/03

ZeroMQ

Chatting away on #POE last night, someone mentioned ZeroMQ. I'd heard of it before, but this time it stuck. I read the book. And I'm hooked. I keep thinking of new ways to use it. And old problems that could be better solved with ZeroMQ. POEx::ZeroMQ might be in my near future.

2011/02/02

CentOS4 and gcc4

Say you are merrily compiling someone else's code on CentOS4 and you get something resembling the following:
query_response_time.cc: In function `void query_response_time::add_time_atomic(query_response_time::TimeCounter*, uint64)':

query_response_time.cc:160: error: `__sync_fetch_and_add' was not declared in this scope
query_response_time.cc: In member function `void query_response_time::time_collector::collect(uint64)':
query_response_time.cc:261: error: `__sync_fetch_and_add' was not declared in this scope
make[3]: *** [query_response_time.o] Error 1
make[3]: *** Waiting for unfinished jobs....
make[3]: Leaving directory /usr/src/redhat/BUILD/Percona-Server/sql'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory /usr/src/redhat/BUILD/Percona-Server/sql'
make[1]: *** [all] Error 2
make[1]: Leaving directory /usr/src/redhat/BUILD/Percona-Server/sql'
make: *** [all-recursive] Error 1
error: Bad exit status from /var/tmp/rpm-tmp.49946 (%build)

You curse and swear. __sync_fetch_and_add is part of Intel's Itanium ABI and just plain isn't implemented in GCC 3, the default compiler in CentOS 4.

But the solution is easier then you think:
yum install gcc4 gcc4-c++

export CC=gcc4 CXX=c++4

OK, so maybe it's harder then that; you will probably have to add the following to your spec file:
BuildRequires: gcc4 gcc4-c++

%define cc_cmd ${CC:-gcc4}
%define cxx_cmd ${CCX:-g++4}

And replace any hardcoded reference to gcc or c++ with %{cc_cmd} or %{cxx_cmd}.

2011/01/21

Perl signals and fork aren't safe.

My very first Perl bug ever!

Long story short: there is a race condition between the safe signal handlers (which just update a flag) and pp_fork() invokes the system fork(). No, pp_fork() doesn't reset all the flags, so the signals could be dispatched in the child process, even if they were meant for the parent.

What boggles me is that this bug is easily over 10 years old. I find it hard to believe that no one noticed it before. Of course, it will take a while for a patch to make it into perl. And all the perls installed out their still have the bug.

The work around is to block signals, fork(), then unblock signals.

I'll write (or someone) IPC::SafeFork to do the above. But also draw attention to the issue.

Sphinx and daemontools

I'm moving the Big Document Warehouse Soon To Be Known As Quaero to using Sphinx for full-text searching. And of course I want to run searchd from daemontools. But searchd insists on backgrounding itself. Searching around I found people using fghack (which doesn't work) and --console (which isn't what is wanted).

However, peering into the source code to see if I could prevent it from backgrounding, I found just what I wanted: the undocumented --nodetach switch. Well, it has some documentation; there is a changelog entry that calls it a debug switch, which it isn't. Shame on you Sphinx-team!

Anyway, here is my daemontools run script:
#!/bin/bash


config=/opt/sphinx/etc/sphinx.cfg
servicename=sphinx

echo $(date "+%Y/%m/%d %H:%M:%S") $$ Sphinx searchd
exec setuidgid dw \
/opt/sphinx/bin/searchd --config $config --nodetach 2>&1 \
| /usr/bin/logger -p info -t $servicename


BTW, I have RPMs of Percona-Server (aka MySQL with a bunch of good patches) with SphinxSE.

2011/01/14

I need more RAM, Scotty!

Lookit this:
~ (root@corey:)# free
total used free shared buffers cached
Mem: 3913752 821824 3091928 0 38376 439640
-/+ buffers/cache: 343808 3569944
Swap: 0 0 0
4GB of RAM on Corey, boyee!

RAM is really cheap. I've been saying this for years. USD is also cheap these days. And I was finding Firefox really annoying at times. So I poked around Asus's site, discovered that Kingston claims that a M2N-MX SE can take 4GB of RAM. Out came the credit card. Thank you Newegg, thank you Purolator.

And yes, Firefox is subjectively much faster. Even though, as you can see above, I'm still using less then the 1 GB I had previously.

Or maybe it just stutters less. Or maybe it's the fresh reboot.

2011/01/13

Perl crumudgeon

Back last century, I read p5p-summaries, I participated in YAPC, I was active on #perl. I loved it when randal or tchrist would show us other, better, cleverer ways of doing things. I wrote some ambitious code and had some ambitious plans for all-dancing, all-singing frameworks. I one point I even looked into how to automagically build apps with Data::Flow.

Write the minimum of code and it would All Just Work.

Of course, I got over that. No framework can be all-dancing. There's a joke about a Clippy-a-like for an IDE: "I see you are writing a framework. Would you like me to a- erase this and Google for something that does what you want?"

But that's not all: I have a colocated server that runs some applications for clients. These apps were written for perl 5.004_05. I have no time nor want to get the running with a modern perl or mod_perl. But for years all the code I wrote had to with 5.004. And I insisted that POE would too.

And it now seems everyone is using Catalyst and Moose. And the shiny new things like "say" and "given/when." And perl 5.12. I JUST STARTED USING 5.8!

Of course "just" means a few years ago.

I think I've become a Perl curmudgeon, a more recent version of my associate Jean-Phillipp. When I first started working with him, he was using a modem to get to his customers, telnet and rlogin to communicate between servers, SCO and BASIC for everything. He's now accepted ssh (though I spotted an instance of rlogin last summer), gets me to install and sysadmin Linux. But still uses BASIC.

I guess I'm showing my years. "say" just looks ugly as a language construct; I have no problem typing "\n". Moose rubs me all wrong, despite it being very much aware of how much it is needed.

And while I've done a good deal of JavaScript recently, I haven't done any real AJAX, ie bidirectional. What they call comet.

In my defence, I've only really started 2 large projects in the last 6 years. These projects have taken most of my time. And with large projects, you should to stick with what the Way It Is Done or you get schizophrenic code. Not that my code isn't schizophrenic, but I've decided that just because you discovered some cool new way of doing something, you shouldn't use it the same day in an existing project. Magic is very hard to maintain.

What's more my toes are cold.

Now that I've identified the above, maybe I can change somethings and not be as hide-bound.