Lightweight vs. Regular Threading

Just for “fun” I ran a few tests to compare the performance of “lightweight threading” based on the ucontext calls available on Linux, vs. the standard pthreads kind of threading. Basically I just wanted to see how many context switches per second each could manage, ping-ponging between two contexts. Here are some results, in thousands per second.

hardware kernel pthread ucontext improvement
2.4GHz P4 2.6.6 253 815 3.2
2.4GHz Xeon * 2 2.4.19 117 1320 11.3
2.2GHz Xeon * 2 2.4.18 184 758 4.1

Surprisingly, the difference between 2.4 and 2.6 (with its supposedly much-improved thread scheduler) wasn’t all that big. Still, a 3-11x difference is pretty significant, and a million switches per second is nothing to sneeze at. The lightweight approach also allows finer control over both scheduling (if the OS’s guesses turn out not to be correct for your situation) and stack size. With those characteristics, a context per request might actually be a viable alternative to the stack-ripping approach I’ve been talking about. The stack ripper has some pretty unavoidable limitations (e.g. weaknesses in handling string constants). It’s also a bit inconvenient in the way that dealing with generated code always tends to be, and some of its performance is also lost by ping-ponging between “inner” and “outer” functions in the ripped code. About its only real strength at this point might be that it’s transportable to just about any environment, while even the lightest of lightweight threading won’t quite work inside a kernel. The lightweight-threading alternative even has an advantage that it will work with C++ (I think, except possibly for a few language constructs). None of that changes any of what I’ve said about this topic in my server-design article, but it does provide an interesting alternative means of implementing a staged design.

Hypocrisy

Michelle Cottle has an interesting article on The New Republic called J’Accuse, about hypocrisy.

Perhaps nothing gets liberals’ blood boiling quicker than the stench of hypocrisy on a public figure. You see it again and again: Whether it’s morality czar Bill Bennett’s slot machine fetish or Clinton-impeachment leader Henry Hyde’s ancient affair, the left is downright desperate to help the rest of America realize the perniciousness of hypocrisy. The rest of America, in turn, typically responds with a big yawn.

Unfortunately, this hypocrisy focus doesn’t generally serve liberals well


as a derivative sin, hypocrisy just doesn’t pack the same gut-level punch as a primary sin. It’s a little too cool, too high-brow, too cerebral to get most Americans fired up. Certainly, we shouldn’t expect it to bring down the likes of a Rush or Bill Bennett.

I’m definitely an example of someone who (as Cottle says) thinks hypocrisy is among the most mortal of sins. Perhaps people have noticed that I’m a little bit of a stickler for internal consistency – whether it be logical, moral, or technical. Of course, consistency can be in the eye of the beholder; consistency is always relative to a set of distinctions considered meaningful, and applying one person’s distinctions to another’s words or actions can often lead to a false conclusion about whether those words or actions are consistent. That’s why I focus on internal consistency. As far as I’m concerned, a hypocrite is someone whose behavior is inconsistent with their own stated beliefs, not mine.

Cottle’s characterization of hypocrisy as “one of the precious few weapons in their [liberals'] moral arsenal” is pretty much correct, though IMO her point would have been better made without throwing in the “moral relativism” newspeak. Liberal values can be just as absolute (i.e. non-relative) as conservative ones, in their own way; they’re just based on reason instead of faith. More importantly, Cottle makes a pretty good point that treating hypocrisy as the most serious charge one can level might not be very effective when dealing with people for whom consistency is not such a big deal. The problem of moral inadequacy must be addressed in the terms of those who exhibit it, not those who already occupy the moral high ground. I’m not sure how to do that, though, except for the special cases where one can shame an avowed Christian by quoting from their very own Bible. The same approach seems less effective when applied to those whose holy scripture is the US Constitution, and no general solution presents itself.

Simple Tools

At work today I realized that I needed a certain very simple kind of program, which at first I thought must already exist in ready-to-use form, but when I looked I couldn’t find it so I ended up writing my own. Basically I wanted to be able to “tail” a logfile to watch the progress of a build, but I also wanted to have lines highlighted if they contained certain patterns (such as “error”). So I wrote hilite.py. It’s a really dirt-simple script, doing something that would be quite possible – though at the cost of more typing – with a simple sed script, but maybe it will make a useful if minor addition to someone else’s toolbox.

More Amy Pictures

The gallery (four pictures) is here. I also have a special bonus picture of myself and the results of my experiments with growing facial hair during my two-week parental leave. That one’s not nearly as nice as those of Amy, but maybe some people are morbidly curious.

Accusations of Self-Interest

It’s a common but mistaken belief among libertarians and their allies that people who hold more liberal beliefs do so because they (the liberals) don’t think they personally would do very well in an environment characterized more by competition than cooperation. What I wonder is why the contrary belief – that libertarians hold their beliefs because they feel that their lack of social skills would put them at a disadvantage in a more cooperative environment – doesn’t seem to be stated nearly as often. Surely it’s just as valid, and just as damning. Could it be just because liberals are more civilized, or can somebody else come up with a credible alternative explanation?

Writing Webservers in my Spare Time

Today’s hacking combined my recent webserver evaluations with my previous work on stack ripping. Just for “fun” (yeah, I have a weird idea of fun) I implemented the world’s lamest web server using the stack ripper. It’s lame because it really only supports enough of the HTTP 1.1 protocol to keep Python’s httplib happy so that my mini-benchmark will run, but it does actually serve the files I need and it’s still pretty sophisticated in terms of handling multiple simultaneous requests etc.

The result is that my untuned web server can just about exactly double the number of requests per second that the best of the Windows webservers I tried could manage…and this was on the Linux box in my office which is natively about half the speed of my laptop. This just makes me wonder what’s wrong with those Windows webservers, or with Windows itself, such that my feeble afternoon’s efforts can not only beat them but do so by a very considerable margin.

Ant Remedy

For over a year now, we’ve had a very large ant colony, maybe as much as ten square feet, in our back yard. I had tried some of the standard tricks – turmeric, vinegar, boiling and soapy water – but the colony kept growing. Finally, a couple of days ago I used a borax/sugar mixture. As far as I can tell, the ant colony has been completely destroyed. Today I noticed a few ants moving around, but they were of a different (smaller) type and seemed to be just visiting. None of the entrances to the colony showed any signs of becoming unblocked, and I swear the plants in that area are growing better than they have been. It looks like this is a very effective way to deal with our little six-legged visitors.

Home Hacking

In between Amy’s feedings and miscellaneous tasks/errands, I’ve been keeping myself amused with a combination of reading and various geekly activities. This has led to an amusing discovery about Wi-Fi reception, and some interesting ones about low-end Windows web servers. Read on for the details.

Rise of Theocracy

Just got this from the New York Times (free registraton required).

Republicans in the House of Representatives have quietly introduced a measure to make it easier for churches to support political candidates, just days after the Bush campaign came under fire from liberal groups for inviting church members to distribute campaign information at their houses of worship.

Representative Bill Thomas of California, chairman of the House Ways and Means Committee, added the measure to a much larger bill, introduced in the committee on Friday, that centers on revising certain corporate taxes.

Besides the obvious sleaze factor of trying to introduce this as part of a totally unrelated bill, this seems like a really obnoxious idea.

"Our impression is this means you get three sins with no penance," said Mr. Maffei, of the Ways and Means minority staff. "That means you can take the last three Sundays before the election and pass out a voter card and still retain your tax status as a church."

Churches are already centers of political activism, too often forfeiting any moral or rational claim to non-profit status that is contingent on refraining from overt political activity. If they’re going to act as part of the campaign for one political party, they should be taxed just like any other PAC and their records should be subject to scrutiny to ensure that they conform with campaign-finance laws. As has been noted here many times before, the separation between church and state exists for both parties’ benefit. If churches don’t want government meddling in their affairs, they shouldn’t go meddling in government’s. Render unto Caesar.

Home at Last

Amy’s home now, and boy is she hungry! She’s hardly giving Cindy a chance to rest, but I had a chance to put together some of the pictures from the last couple of days. Enjoy.