/~colmmacc/ http://www.stdlib.net/~colmmacc An Irishman's Fiery Sun, 03 Jan 2010 15:14:14 +0000 http://wordpress.org/?v=2.9 en hourly 1 Holy Orders http://www.stdlib.net/~colmmacc/2010/01/02/holy-orders/ http://www.stdlib.net/~colmmacc/2010/01/02/holy-orders/#comments Sat, 02 Jan 2010 15:08:21 +0000 colmmacc http://www.stdlib.net/~colmmacc/?p=641 So, yesterday marked the day that the new Blasphemy law came into force in Ireland. It also marked the day when Atheist Ireland published 25 “blasphemous” quotes, in a supposed act of defiance.

Atheist Ireland have gone about it in a very strange way; the url in their blog post is not a hyperlink, and the quotes aren’t simply in their post or on their front page. That’s their prerogative, of course, but I do wonder if it’s a sign of overt caution. Either way, the circus seems to have worked, and CNN and the BBC have both picked it up, among many more.

As a press-stunt, it’s genius. Getting the attention of the international media like that is not easy, and through careful choice of celebrities to quote, and the right tone, Atheist Ireland have pulled off a well-executed PR coup.

But as an act of online advocacy, and of affecting political change, frankly it’s stupid. And I think that Atheist Ireland will have approximately zero success. Such is the magnitude of their “not getting it” that they are probably forever doomed to an existence of committeeism and tokenism in near-equal measure.

Firstly, the action itself is ineffective, it does not – in my opinion – constitute any kind of an offence. Let’s go to the source, the 2009 Defamation Act;

(2) For the purposes of this section, a person publishes or utters blasphemous matter if—

(a) he or she publishes or utters matter that is grossly abusive or insulting in relation to matters held sacred by any religion, thereby causing outrage among a substantial number of the adherents of that religion, and

(b) he or she intends, by the publication or utterance of the matter concerned, to cause such outrage.

(3) It shall be a defence to proceedings for an offence under this section for the defendant to prove that a reasonable person would find genuine literary, artistic, political, scientific, or academic value in the matter to which the offence relates.

Clearly there is political, scientific and academic value in Atheist Ireland’s statements. If they really wanted to engage in civil disobedience, it would take something akin to cartoons of the prophet, getting it on in a threesome with Buddha and Jesus while being bitten by some vampire Jehova’s Witnesses. That’s what the law was designed to impede. To be clear, I don’t agree with that law, I think freedom of speech is more important than a bizarre right not to be offended, but the law simply isn’t of the nature that Atheist Ireland and others imply.

I’m not sure if it’s willful misrepresentation, but by conveying the impression that the new law is designed to outlaw such trivial, and relatively innocuous, statements of the sort that Atheist Ireland quotes it is only serving to undermine Atheist Ireland’s own credibility. In light of the actual facts, it’s hard to take them seriously on the issue. Sacrificing integrity and accuracy for punchy-PR is never a great idea, long term.

To be fair to Atheist Ireland, they don’t actually claim that their statements are prosecutable, and are making the broader (but again, tokenistic) point that the law is simply silly and unworkable. Great, that’s an important point – but what use is making so much noise about it? This actually entrenches politicians and makes them less and less likely to respond favourably. It’s ironic that this the kind of reactionary “we must be listened to” tokenism that led to the law in the first place.

PR-led advocacy groups, which are really pressure groups almost never work in Ireland. There simply isn’t any political incentive to respond to pressure on these kind of issues. Across all of Ireland there are maybe 200 swing votes on the Blasphemy issue, thinly spread across the constituencies. Elected politicians, rightly, place it very low on the agenda. Going to 2 funerals, fixing some lamps, and changing a speed limit or two will get you as many votes – and in one parish.

Real, successful, advocacy groups don’t look like this. Instead there are small, targeted and strategic efforts. It’s lots of small meetings, tactically-directed briefs and letters and relationship building. The effective groups work somewhat within the system, more quietly, and get a lot more done. Groups like Barnardos get more mileage from lobbying the Department of Finance behind the scenes than they do out of a hundred press releases.

When we were running our campaigns against E-voting, I’m convinced we made ten times as much progress by working quietly behind the scenes than we ever did through PR-based activity. In order to run a successful effort, I think it’s important to keep some basics in mind;

  • Think in terms of the people you are trying to influence, and how they perceive it. How do you make your cause be in their interest? What can you do for them?

  • If it’s a political change you need, how do you frame the issue in terms of jobs, money or core political ideology (ideally patriotism)? If you need to influence a small number of politicians, how do you make the issue about their legacy?

  • If you plan to take your case to the courts, how do you influence the context in which judges rule? How do you develop and frame legal theory, how do you make it such that “your side” seems like the obviously equitable one, to judges and their peer-group. An article in a legal journal espousing your side will go a long way.

  • When you do make a press-release or PR effort, consider very carefully the question “How will this actually progress our cause? what are we aiming to achieve here”. Inciting rage, generating “pressure” and elevating one’s personal profile should be non-goals, they aren’t effective. A lot of progress can me made by suppressing your ego and not taking credit; ghost-writing political speeches and news editorials is incredibly common, for example. Have those been considered first?

    An effective goals would be “increasing awareness, and converting this into membership and resources”. A clueful organisation ends their campaign with a notice to donate money, rather than to sign a petition. It’s an important dictinction, the money can help make real change, most petitions are ignored.

Bottom line; always judge an advocacy group by the amount of actual progress they make on their issues, not column inches. And if you are an advocacy group, ask at every stage – for every action – “what is the sequence of events I hope to trigger that will actually cause the change I desire?”.

Now, to be more constructive. What would I do? Firstly, I think the priority should be to convert all of the PR into money, and to use that money to fund legal research. Small, but targeted academic briefs – aiming for 3 or more papers a year establishing the jurisprudence of the blasphemy law. The aim would be to establish a credible context in which it showed that the law is out of place, that it doesn’t fit with many of our international treaty commitments and is comparatively regressive.

Next priority would be to start to frame the issue as anti-republican. Ireland is at a very important cross-roads, in the wake of the Ryan and Murphy reports there are calls for more church-state separation. The way to capitalise on this is to make the case for a newly invigorated Republicanism, one of the great Irish political ideals. Republics are supposed to be by and for the people, relatively free of church interference. Our proclamation says;

The Republic guarantees religious and civil liberty, equal rights and equal opportunities to all its citizens, and declares its resolve to pursue the happiness and prosperity of the whole nation and all of its parts, cherishing all of the children of the nation equally and oblivious of the differences carefully fostered by an alien government, which have divided a minority from the majority in the past.

It’s not that hard to frame the blasphemy law as anti-republican.

With a few short years of that kind of hard work, it would be possible to create a context in which an Irish politician could see it as in their interest, and in the betterment of their legacy, that they bravely spear-head a new Republican ideal.

Backed by research and briefs which will help them not look stupid to their peer-group, or in the face of opposition questions, we can give them the confidence to propose it in the first place. This is what achieving real change looks like; careful groundwork. The system simply isn’t going to respond whining from a marginalised minority group.

The good news is that it’s doable. It took us a long time to get it finished, but a relatively small group of e-voting campaigners finally managed to get a key government policy 100% reversed. And this was in spite of far more political (and real economic) capital having been invested than in the new blasphemy law. There were many many small meetings, letters, briefing documents, ghost-written speeches and editorials, researched papers, legal strategies and only about 2 press releases per year on average – with a cluster around 2004 during the run up to the elections.

To me, based on experience with ICTE and other lobby groups, that’s a lot more like what this kind of successful advocacy looks like. I do hope Atheist Ireland, or another secular-interest group, can find the time and experience to develop these issues properly, but for now it doesn’t seem promising.

Update: Throwing caution to the wind, Atheist Ireland have now made the url I mentioned a hyperlink and published the quotes on their front page. Also, there’s some lively discussion in the comments to this post.

]]>
http://www.stdlib.net/~colmmacc/2010/01/02/holy-orders/feed/ 24
Point Break http://www.stdlib.net/~colmmacc/2009/12/28/point-break/ http://www.stdlib.net/~colmmacc/2009/12/28/point-break/#comments Mon, 28 Dec 2009 21:12:52 +0000 colmmacc http://www.stdlib.net/~colmmacc/?p=615 So, about 2 minutes after taking this photo;

Hot!

I slipped on the paraffin-laden solid granite pavement, everything went flying, and I ended up getting a very different kind of photo entirely;

That’s my right arm, and somewhere in there a minimally-deforming radial fracture that I don’t remotely have the training to actually see. Though I definitely don’t like the look of that suspiciously lumpy bit of bone. Here’s another look;

As fractures go, I think I got the best kind. It’s now 3 weeks later and I’m almost back to a full range of movement and strength is starting to return. I can write, type, take photos and most importantly, play music once again. The people at St. James’s Hospital have been very good, and if you ever plan to break anything I can recommend doing it near them.

Science is really really cool. Randomised control trials have shown that a simple millennia-old sling (not a cast) is the best treatment, so that’s what I got. About a century of rigourous bio-chemical engineering has led to little pills I could buy in a pharmacy that magically suppress complex sources of pain with minimal side-effects.

Over that same century we’ve progressed from a naive understanding of “Röntgen radiation” as mysterious emanations from a vacuum tube, to a complex quantum-mechanical model of X-Ray interactions that allows us to record these highly-ionising photon jet-streams on a semi-conductor, convert the impression into a digital image and then have it pop up on my clinicians desktop. Right now, reading a random blog on the internet, you can see inside my body – as easily as you might look out the window.

And social science is used too. Because people frequently forget their appointments, there are text message reminders; a few days, and one day before anything that’s scheduled. Again, a trial has shown that this is both cost-effective and clinically beneficial. And when I go to the physio-therapy clinic, I get given a simple set of tried and tested exercises that have been shown to lead to improvements.

Cooler still is that despite all of the science, and care and attention involved in the whole process – really it’s the body doing the work. Through some magic – mostly unknown – system of DNA signaling, controlled protein unfolding, stem-cells and “stuff”, tiny microscopic organic “bits” somehow communicate and coordinate the building of whole new bone, mostly in the right place. So without having to do all that much, I can play Fussball and write dumb blog entries again.

It’s almost worth doing just for the experience.

]]>
http://www.stdlib.net/~colmmacc/2009/12/28/point-break/feed/ 2
Con-science http://www.stdlib.net/~colmmacc/2009/12/16/con-science/ http://www.stdlib.net/~colmmacc/2009/12/16/con-science/#comments Wed, 16 Dec 2009 17:43:38 +0000 colmmacc http://www.stdlib.net/~colmmacc/?p=589 I’m sitting on a train, the Enterprise, moving along at about 140 kilometers per hour between Drogheda and Dublin. Something is causing practically every particle in my body to spark into a new life at a different position in space one instant to the next.

Dancing and spinning

For each one of those particles, there’s some chance it could just pop into life on the far side of the moon, or even the universe. But something, I guess “motion” is averaging everything out and look, there the sum of me pops, every tiny instant getting slightly closer to Dublin.

If the train was in the vaccuum of space – or somehow free from the effects of friction – it wouldn’t even take anything to keep this atomic leap-frogging going. Each small micro-part of me would just keep on dancing. And somehow at the same time, it’s exactly as if I were staying still all along – there’s no real difference. This has been tested.

But if for any reason a change of tempo was required, to move from a waltz to a samba, something intangible and ephemeral – mysteriously lumped into the word “energy” – is required. It’s weird and mystical and it doesn’t make a whole lot of sense, but it can be measured and described – and relied upon.

And as I sit here and write, using the word “I” like that, it feels like there’s a “me”. It seems as if there’s a real sense of ownership over my thinking, I can’t tell where my thoughts come from, but they are mine.

I feel like I’m free to choose things, when I get off of the train I could get straight into a taxi or walk to a tram. I don’t know which I’ll do yet, there are a lot of factors to consider, but neither choice seems pre-ordained, and once it happens it will feel like “I” owned that choice.

“Free will” seems as real to me as the forward motion of this train, it’s an inexplicable dance, but it’s my tune. And that makes less sense. Reality is describable by all of these symbols and equations, and we can make predictions with them. This has been tested.

There are even divisions between what is predictable in detail, and what is predictable only in the aggregate, random and unknowable at the finer grain.

Here in my head, it doesn’t seem like my thoughts are predictable, or could be. If they are just an inevitable cadence, then that “I” is merely an illusion. It also doesn’t seem like thoughts are random or unknowable, to me anyway. I have patterns of thinking, recurring themes, and a detectable personality. It can’t be the same dance.

How many miracles are there on this train? Motion is miraculous enough, that “I” can think, that the universe even exists seems miraculous too. But most astonishing, is that these simple realities are seemingly contradictory.

I’m still on that train, I haven’t gone anywhere, there haven’t been any angels visiting me, or deitious interventions. These thoughts haven’t led anyone to complicated dogmas, wars or ceremonies. Some say science is cold. Maybe the dance is a myth.

And if this mental dance should one day just end, where are the real love-songs? Songs that speak to the real meaning, the genuine warmth, of spending a fleeting, passing, bittersweet whirl around the floor with someone. Not an infinitesimal slice of eternity living in hope of a better dance; that’s cold. This has been tested.

]]>
http://www.stdlib.net/~colmmacc/2009/12/16/con-science/feed/ 4
Role Models http://www.stdlib.net/~colmmacc/2009/12/13/role-models/ http://www.stdlib.net/~colmmacc/2009/12/13/role-models/#comments Sun, 13 Dec 2009 18:00:21 +0000 colmmacc http://www.stdlib.net/~colmmacc/?p=553 Consciously, I’ve never been keen on the idea of role-models. Thinking it synonymous with hero-worship, it has always seemed a bit of an anti-pattern to me. Why try to emulate anyone? There are enough people in the world behaving the same as someone else, being different and original is definitely more useful, even if it makes you a bit crazy. When I did a dubious “leadership style” test I came up as “anti-follower”, so maybe it’s just another form of contrarianism on my part.

Over time, I’ve found that the best way to learn is by example, even if it’s a process of unconscious osmosis. And when I’ve spent time on what is sometimes called “personal development” I’ve found that there is real benefit in reading the biographies and the writings of truly awesome people. It certainly seems more productive than reading self-help books that are written in truisms and marketing crap.

I thought I’d share some of the people who I’ve really benefited from reading about, truly amazing people.

Richard P. Feynman

RPF is a legend; a nobel laureate physicist with an uncanny ability to explain complex ideas, an anti-authoritarian maverick who loved to screw with officialdom but most of all an incredibly generous, warm, loving guy (even if a womaniser at times). His writings on physics and his letters to his first, dying, wife are an inspiration.

Robert M. Pirsig

Pirsig, someone genuinely crazy enough to have been institutionalised, still managed to write one of the best sellers of the 20th century and to invent a philosophical system that many consider to have merit. ZMM is amazingly well written, all the more so when you consider that every paragraph was planned out in advance on index cards. Worrying, his narrator in ZMM is the only literary character I’ve ever strongly identified with.

Grace Hopper

Grace Hopper signed up for the US navy during World War 2, and rose (primarily as a reservist) to the rank of commodore/rear-admiral back when this was incredibly unusual. But more than this, she was an excellent experimenter, and kept a rigourous lab-book, despite being mainly a computer scientist. She was a strong believer in getting things done, and coined the phrases “dare to do” and “It’s easier to ask forgiveness than it is to get permission”. Seriously awesome woman. Oh yeah, and she invented the compiler.

Doc Watson

Doc Watson has been blind nearly his entire life, but that doesn’t stop him from being the truly most amazing guitar picker the world has ever seen, or doing crazy things like mending the tiles on his roof. His solo runs and accompaniment are incredibly good, and he’s somehow maintained humility in the face of multiple grammy awards and playing for the president on a regular basis. Another doer, he just kept going and became more productive after the tragic death of his duet partner and son Merle.

Dolly Parton

Dolly is a self-described mis-fit, but she is also a very very shrewd business woman as well as being a dedicated humanitarian and gifted songwriter. She is one of the really great singers, and is emotionally invested in every song she sings (even the ones that sound like bubblegum, listen to how sad she is in “Here you come again”).

CP Snow

CP Snow was basically a troll, but a very very good one. His arguments, lectures and writings weren’t always rigourous and balanced but they were always enlightening, thought-provoking and forward thinking. Most famously he identified the tension between literary and scientific cultures and made a great case for the unfair treatment of science. A scientist and a well-regarded author CP Snow is a great example that it is possible to straddle both worlds.

Peter Watson

Peter Watson is a prolific researcher and writer, the volume of his output and the breadth of his knowledge is unfathomable. I’m constantly reading something of his. He has methodically and thoroughly condensed practically all of known intellectual history, writing about all of the inventions of the human mind. His writing is great, but it also brings home how relatively ordinary our time in history really is, yet serves as a great reminder that so many things we take for granted even had to be invented.

No doubt I’ll think of more now that I’ve put a list together. I’ve been fortunate enough to meet some of these people, but I’ve also been even more fortunate in that other people I’ve come across in my life have served as role models (starting naturally enough with my parents). I don’t intend this post as meme, but if you have role-models, I’d be interested in hearing about them. As I mentioned, it’s definitely a great benefit to read about such inspiring people.

]]>
http://www.stdlib.net/~colmmacc/2009/12/13/role-models/feed/ 3
Period Pain 3 http://www.stdlib.net/~colmmacc/2009/11/26/period-pain-3/ http://www.stdlib.net/~colmmacc/2009/11/26/period-pain-3/#comments Thu, 26 Nov 2009 21:44:49 +0000 colmmacc http://www.stdlib.net/~colmmacc/?p=529 As promised, though it’s been a while coming, I wrote that there’d be a followup on scheduling periodic tasks.

The most important point to get is that for nearly all real-world use cases the actual time that a “scheduled” task runs at doesn’t matter. Tasks that have to occur at a specific time on Tuesday are vanishingly rare. cron is one of the most abused tools going, rather than encode specific times it would make more sense to let a scheduler decide when the tasks should be run based on criteria such as overall network and system load.

It’s not even hard. There are plenty of scheduling algorithms and theory to borrow from, and many large organisations even have private implementations that let you be a bit more fuzzy about when tasks are run. But there’s another level to the periodicity problem that is worth thinking about.

Rather than simply using numbers and values that come readily to humans, it can be worth putting more effort and research into the values of periods themselves. This isn’t meant in some fetishistic sense . Yes, for say virus updates, it’s possible to produce a gigantic linear algebra equation, with 100s of parameters, that would balance the likelihood and cost of a security breach against the cost and frequency of checking for updates and it would come out with some answer, but that’s a lot of work for little gain.

More interesting, and more tractable, are the effects that arise when multiple periodic tasks coincide. These are really common in distributed systems, and a real pain to debug and diagnose.

It could be as simple as the case we’ve been looking at; a cron job that runs once a day, but across many systems, or it could be as complex as a full-blown peer to peer app that’s got a control loop with multiple peers, a supernode or two and a user-interface polling loop.

And a pattern that’s repeated over and over again is that people choose “convenient” values for the periods .. and these choices are so common that when the periods end up in phase with each other we get constructive interference and elevated load events when the tasks coincide.

Aligned Events

Take for example 3 loops – one with a period of 5 minutes, one with 10 minutes and one with 30 minutes. If the loops end up in phase then every 30 minutes we have all three tasks running at once. It’s a mess, and it’s an easy one to prevent – use prime numbers for the values of the periods;

Aligned Events

at least that way the number of coincidental events is minimized, and if any load events show up with a periodicity it is very straightforward to identify what single event, or combination of events, should be responsible. Sometimes I can easily imagine a cron replacement that runs exactly like this, but never get to writing it.

And these sorts of loops show up in places you might not necessarily think of. Caches are a good example. If you serve every piece of content of your website with the same Max-Age, then you can expect a thundering herd of requests whenever a browser or proxy expires them all at the same time. One the other hand, if you use prime number cache lifetimes for each resource, you’ll get much more nicely staggered and spread out series of requests. It’s a really simple, neat, optimisation. Tuning things doesn’t have to be hard.

]]>
http://www.stdlib.net/~colmmacc/2009/11/26/period-pain-3/feed/ 4
Period Pain part 2 http://www.stdlib.net/~colmmacc/2009/09/27/period-pain-part-2/ http://www.stdlib.net/~colmmacc/2009/09/27/period-pain-part-2/#comments Sun, 27 Sep 2009 12:37:36 +0000 colmmacc http://www.stdlib.net/~colmmacc/?p=517 Last week I wrote about problems with periodicity but it was only half of the problem. But before moving on to the second half, it seems like a good time to post with some clarifications.

I wrote that using some locally unique well-distributed value, such as a mac address, was better than choosing a random number once. But crucially, I left out how to do such a thing. A few commenters asked what the best way might be, including some good examples.

To be a bit more rigourous about it, and make sure, the great people at HEAnet provided me with an anonymous list (the prefixes had been stripped) of over 200,000 IPv6 addresses that have used ftp.heanet.ie in the last month. Included in that list were over 150,000 EUI-64 style addresses, which look like this …

2001:880:18:1:214:4fff:fe02:e6ee

the last 4 octets include a slightly modified version of the user’s MAC address. The details are straightforward, but you can take it from me that “214:4fff:fe02:e6ee” corresponds to a MAC address of “00:14:4F:02:E6:EE”, and that the md5sum of that string is “d32227ed9a3bf7d8714590f837884286″.

Mac addresses, and the hash, are both really just numbers. A 48-bit number and a 128-bit number respectively. Bash can handle these kind of numbers natively, and if you need a well-distributed number between say 0 and 999 then the mod operator is perfect:

# Prove that bash can handle even 128-bit numbers
colmmacc@infiltrator (~) $ echo $(( 0xd32227ed9a3bf7d8714590f837884286 ))
8162089295436857990

# Use the MAC address directly to pick a number
colmmacc@infiltrator (~) $ MACADDR=`/sbin/ifconfig | grep HWad \
                               | awk '{print $5 }' | head -1`
colmmacc@infiltrator (~) $ echo $((  16#$MACADDR  % 1000 )) | sed 's/^-//'
174

# Use the md5sum of the MAC address to pick a number
colmmacc@infiltrator (~) $  echo $((  `echo $MACADDR | md5sum |\
                             cut -d\  -f1| sed 's/^/0x/'` \
                             % 1000 )) | sed 's/^-//'
363

As per one of the comments on the previous post, from brady, getting rid of any minus sign (the last sed operation), is a cheap form of abs().

But, which is better; randomness, mac addresses or the md5sums? To get rid of any temporal bias, I’ve graphed the distribution of the above operations for 18,365 real world MAC addresses from one day’s worth of requests to ftp.heanet.ie.

Mac address distributions

MD5Sums come out slightly ahead (stddev of 4.6 compared to 4.81), and essentially performed just as well as how random numbers should do (around a stddev of 4.55). Using the MAC addresses on their own, without md5suming should be good enough for most purposes too.

So why not use a random number? Well two reasons.

  1. It’s harder – you have to store the state somewhere. A mac address on the other hand is already stored state, if you can look it up each time and it will be relatively stable.
  2. A lot of the time automated tasks are being installed at provisioning time – there isn’t actually that much real entropy available, so the randomness either tends to be weak, or you contribute to exhausting entropy and denying it to more useful things.

And lastly, James pointed out that from the point of view of a single host half an hour of jitter doesn’t really matter. He’s dead right – and of course the combined effects do matter for the distributed system – and the next post will be how to exploit that property to get better scheduling.

]]>
http://www.stdlib.net/~colmmacc/2009/09/27/period-pain-part-2/feed/ 3
Period Pain http://www.stdlib.net/~colmmacc/2009/09/14/period-pain/ http://www.stdlib.net/~colmmacc/2009/09/14/period-pain/#comments Mon, 14 Sep 2009 16:15:27 +0000 colmmacc http://www.stdlib.net/~colmmacc/?p=473 Imagine it was your job – along with 1,000 other people – to pick a number between 1 and 60. You can use any method you like (though you must use the same one), but if more than 30 of you choose the the same number, those of you who did would be shot. Would you let the group pick numbers at random?

Probably not, there’s always a chance it could go horribly wrong. And that chance? We could derive the correct p-value for having to shoot people easily enough from the uniform distribution, but forget that, let’s do it with code. It’s a lot easier to understand – and it’s a good habit too.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import random

count = 0

# Simulate 10,000 runs of 1,000 people
#  picking a number between 0 and 59.
for runs in range(10000):
    numbers = [0] * 60

    for people in range(1000):
        r = random.randint(0, 59)
        numbers[ r ] += 1

    if sorted(numbers)[-1] >= 30:
        count += 1

print count/10000.0

If you run this, hopefully you’ll get an answer that’s around “0.1″. In other words, about 10% of the time we expect to have at least one number being chosen by 30 or more people. Those don’t seem like great odds, and I wouldn’t play Russian roulette with lives like that.

Yet this is almost exactly what we do with a lot of automated tasks in some large-scale distributed systems. A pattern than can be observed over and over again is that someone writes a scheduled task that runs once an hour, day, month or whatever but then sleeps a random amount of time (typically between 0 and 3600 seconds) when it starts- in a very naive attempt to distribute impact across the larger system evenly.

The march of time

The impacts can be pretty serious – it might be extended load on a dependent service, or it might simply be too many busy nodes in a cluster. Or it might be a two-day global outage of a popular Voip service. Too many things happening at once is usually a bad thing in distributed systems.

Security and anti-virus updates, apt/yum/ports repositories and auditing tools in particular seem to get this pattern wrong. Here’s a good example, from Ubuntu’s daily apt script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# sleep for a random intervall of time (default 30min)
# (some code taken from cron-apt, thanks)
random_sleep()
{
    RandomSleep=1800
    eval $(apt-config shell RandomSleep APT::Periodic::RandomSleep)
    if [ $RandomSleep -eq 0 ]; then
    return
    fi
    if [ -z "$RANDOM" ] ; then
        # A fix for shells that do not have this bash feature.
    RANDOM=$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -c"1-5")
    fi
    TIME=$(($RANDOM % $RandomSleep))
    sleep $TIME
}

This is a very bad pattern – I’d go so far as to say that it’s actually worse than letting everything happen at the same time in the first place. It has 2 particularly dangerous qualities;

  1. It increases the effective period of the task

    If a task is running once an hour – it’s probably because we need to do something once an hour. That may seem tautological, but there’s subtlety. The clock-time hours we define as humans are arbitrary, by once an hour we should really mean “at least once in a 60 minute interval”, not “once between 1PM and 2PM”.

    If we pick a random sleep time, we might end up running just under two hours apart. If at 1PM we pick 0 sleep seconds, and then at 2PM two we pick 3599 sleep seconds – look, we just ran two real hours apart!. Unsurprisingly the converse can happen, and we’ll run just 1 second apart, doing heavens knows what to load along the way.

  2. The system as a whole has to cope with dangerous load spikes

    Using our earlier example, If we allocated the numbers evenly, each value would get chosen only 16 or 17 times. We could plan for an impact of say 20 running at once. But as we’ve seen, if we pick random numbers every time, then 1 in every 10 runs, we’re going to have to cope with an impact of 30. That’s 50% more load, because of a one line error!

    If this task is running every hour, then about 1 in every 7 weeks, we’re going to have to deal with an impact of 40 or more. And it will appear totally out of the blue, it’s a random occurrence. Nice! To take it to the extreme, there is a small – but finite – chance all all 1,000 systems choosing the same value. But avoiding this is why we are spreading the load in the first place, so why leave it to chance?

    I used to run a busy Ubuntu mirror, and every day between 6:25 and 6:55 we’d see a gigantic wedge of load that could be distributed a lot more evenly. Though I think the worst of these problems have now been fixed.

The optimal fix for the problem is simple; coordinate – use a central allocator, or a gossip protocol, to ensure that every slot has at most N/M consumers.

This isn’t always possible though – Open Source security updates are usually polled from relatively dumb mirror servers, that don’t keep enough state to be able to divide load like this. But there are still two better approaches.

Firstly, you can pick a random number just once, and then reuse the same random number every time. This guarantees that the task does actually run once an hour, and it makes load predictable for the distributed system as a whole.

Secondly, you can use any uniformly distributed unique piece of data, local to the node, to choose your number. I like to use an MD5 hash of the MAC address, but even the hostname would do.

Probability-wise, the two approaches are identical, but in the real world you get fewer collisions with the latter – probably due to the similar state of entropy identical systems will be in when you mass boot a fleet of several hundred. In both cases, where aberrations emerge due to bad luck, they at least only have to be identified and fixed once. We’re no longer playing the load lottery once an hour.

But this is only half the story … what about other automated tasks with their own periods … how do we avoid colliding with them? And how do we architect timings in distributed systems in general to make them a lot easier to debug. That’s what the next blog post will be about. Stay tuned.

]]>
http://www.stdlib.net/~colmmacc/2009/09/14/period-pain/feed/ 14
N+1 http://www.stdlib.net/~colmmacc/2009/09/02/n1/ http://www.stdlib.net/~colmmacc/2009/09/02/n1/#comments Wed, 02 Sep 2009 09:35:10 +0000 colmmacc http://www.stdlib.net/~colmmacc/?p=430 I rarely write introspective or meta blog posts, in fact I rarely even use the word “I” on this blog (one of the habits you should develop as a manager or team-member is to use the word “we” almost all of the time) … so I hope you’ll forgive this brief, obnoxious, self-centered, round-up of the last year. I’ll try to smatter it with some useful observations to make up for it.

Today it’s one year since I started working for Amazon.com, and officially moved in to my new place and hence back to Dublin. Before that, I’d been spending most of my time in Amsterdam and traveling. By just September last year, I’d managed 78 flights in 2008. In the year since, it’s been a much more comfortable, and relatively conservative, 24. Some visits to Seattle, New York, New Orleans, Barcelona, Bristol and London keeping me occupied and worldly.

Me!

I’ve learned a lot in the last year, a lot more and in very different directions, than I expected. Amazon turns out to be even more interesting than I had anticipated, and getting thrown in at the deep end early on – with a new Amazon Web Service to help build and support – has been an amazing experience. Before I started, I naively thought that scale was mostly about understanding distributed systems problems and performant designs. It is about those things, but not mostly.

In reality (well, in my opinion) the hard problems of scale are the incredible attention to detail and testing it requires, because when your rapidly-changing code is handling billions of requests – even a tiny fault that is triggered on one in every million requests will get you paged in no time at all. I’m not sure that there is any other way to learn it than having to support it for real. I recommend it.

I’m getting a chance to work on stuff I enjoy, building some big things and making some important and critical code go really really fast. It’s always nice to feel that features exist – that the universe is different in some way – because of work you’ve been involved in. That should always be the measure of progress; “How has the universe been changed?”, everything else is meta-work.

I am learning technical things at Amazon; when I started I had never written a line of perl, now I’ve written entire perl frameworks, a very basic perl compiler, a bytecode analyzer, perform low-level code-reviews, and teach perl once a week. The experience has reinforced my opinion that the notion of “knowing programming language X” is itself a broken anti-pattern.

That said, Perl was comparatively difficult to learn. Coming to it with about 15 years programming experience in many languages, it still took about 5 weeks to become proficient in it to the point that I really understood all of the magic symbols, operators and patterns in front of me at a fundamental level. At a guess, it took just 2 weeks to reach the same level of proficiency in python.

But that learning is self-driven, the real learning experience at Amazon is how things are organised and managed. How a huge multinational can structure and orientate itself such that things can happen incredibly efficiently and quickly is fascinating to observe and participate in. It’s like getting a free MBA. I can recommend that too.

On the college front – it’s been a strange year, as it was also my final year doing my BSc. in Computer Science in Trinity College, Dublin. It was tough going, mostly just to stick through it, but I think worth it in the end. Somehow came out with a first class honours degree. I’ve decided not to progress with a part-time postgrad just yet – it seems like a good time to try not doing so much college for a change, but maybe next year.

In the last year, I’ve learned two new instruments, banjo – for the fun of it – to a level where I can now keep up in sessions – and piano – to a lesser level but I can now arrange and play relatively intricate pieces. My place has worked out very well, and a year on I’m still very happy to be living here, it’s ideal. Ups and downs in my personal life in the last year have been extreme, but I’ve learned a lot from those too and am mostly the better for it.

But now that I have some more free time, I have to admit I’m not entirely sure what to do with it. I’m finding things to do with my evenings, and catching up with friends properly, but still have itches to be a bit more productive. I haven’t done as much Apache stuff as I’d have liked in the last 2 years, but the urge to write a webserver from scratch using a more functional programming oriented approach (though not necessarily a lamba-calculus derived language) is strong … and also pointless.

This past year also saw the final, conclusive, victory of sense in the Irish E-voting debacle. In short; we were correct all along, and the system has been completely abandoned. I have to admit it was a bit fun to be able to gloat about it on the radio.

So now … what next for my free time … well maybe you can help. To further compound the impression of arrogance and self-obsession I have no doubt created, it’s like this; I’m pretty clever. I’ve got above average maths, analytical and linguistics skills. I’m an expert programmer/developer and builder of things. I’m a fairly decent musician and photographer with some basic sense of style, design and composition.

Oh god there’s more! I’m politically knowledgeable, and I know how to manipulate the political and press systems and strategise (with a proven track record through two lobby groups). I’ve worked for two start-ups, and I know how to make things happen. I’m a quick learner, and I know that when something is worthwhile, realistic and interesting I can throw a huge amount of effort and pragmatism right at it. I like doing cool things for free, and earn just enough to be able to.

Now all that said, to moderate things I’m also basically an introvert and can be pretty awkward and quiet around too many unfamiliar people, am about the last person you’d ever want to take to a bar (I don’t drink for a start), know close to nothing about popular culture and have read maybe only 4 or 5 fiction books in the last 10 years. So there’s a strong counter-argument that I’m also an illiterate anti-social bore to be kept in mind here too. But thankfully, not a terrible one.

But with all of that in mind, what does need doing? Especially in Ireland/Dublin – because it would be nice to involve meeting people and getting better at that whole social thing. Any ideas? the bigger the better. Any technical, political, or social gaps that really need filling? anybody need some help? What would you, or indeed, jesus do? There are a few ideas knocking around already, I’ll be sure to update when they are more concrete. How should we change the universe?

]]>
http://www.stdlib.net/~colmmacc/2009/09/02/n1/feed/ 12
Fylde Alexander Guitar http://www.stdlib.net/~colmmacc/2009/08/18/fylde-alexander-guitar/ http://www.stdlib.net/~colmmacc/2009/08/18/fylde-alexander-guitar/#comments Tue, 18 Aug 2009 21:59:17 +0000 colmmacc http://www.stdlib.net/~colmmacc/?p=418 Almost 6 months ago now, after a lot of trialling, some borrowing, and a serious think I order a new guitar. This time, it’s a Fylde Alexander guitar. It’s hand made, and now that it’s arrived – absolutely gorgeous and a joy to play.

Fylde Alexander Guitar

First things first though, I’ve managed to figure out how to work the H2 recorder to get decent sound … have a listen, these two tunes are a slow waltz-like “Heritage Close” and a hornpipe I can never remember the name of;

The tuning is DADGAD, played low to get a feel for the bass. As an experiment, I’ve made a video .. the sound quality isn’t as good, but you can get an idea of the kind of pull-offs and ornamentation the guitar enables, maybe this will get across just how much easier it is to play.

I also have one other recording – done through the pickup, of a jig in E-minor that I also can’t remember the name of – it gives a good sense of how great the pickup sounds.

I ordered the guitar through Monastery Music. If you’re ever thinking about getting a hand-made folk instrument, I’d give Fylde a serious look. Very very happy with it so far.

]]>
http://www.stdlib.net/~colmmacc/2009/08/18/fylde-alexander-guitar/feed/ 4
Hurling, the Musical http://www.stdlib.net/~colmmacc/2009/07/18/hurling-the-musical/ http://www.stdlib.net/~colmmacc/2009/07/18/hurling-the-musical/#comments Sat, 18 Jul 2009 09:57:59 +0000 colmmacc http://www.stdlib.net/~colmmacc/?p=407 Now that Riverdance is coming to a close, after 15 years as a raving success, we need another kitch Irish musical to uplift our times and kickstart an economic recovery. So, as an attempt, I give you “Hurling; The musical”, set to pipes, harps and the beat of a merry Irish heart.

Act 1:

When the curtains raise, it starts on a misty morning, in the time of Romantic Ireland – chieftains and warrior poets abound. Our hero, Setanta, is in an epic athletic struggle. It’s him against 5 other players, each armed with sticks. A ball is thrown around, and the movement of play is in the style of a interpretive dance half way between West Side Story dance-fighting and the well-oiled movements of a samurai. Gradually it becomes clear to the audience that the aim isn’t just to hit each other with the sticks (though that’s encouraged) but to get the ball past them. The programme will probably have some patronising comparisons to Ice Hockey in it anyway.

Insert a song about how wonderful it is to be young and carefree. Blow by blow, Setanta takes two players out with a skillful hit of the ball, skips around the other three, and pucks the ball along a guide-wire above the audience – where it explodes in a mini dazzle of green and sulfur.

Cut to Setanta’s uncle, Conor, leader of the brave and valiant red knights. He and the red knights are having a piss-up at Culain’s. This calls for nothing less than an over-the-top homo-erotic “Oh how great are we, we bunch of fighting men” number, immediately followed by a drinking song. Disgusted with their own drunkenness, Conor decides to call upon this nephew Setanta – the goody two-shoes with an ancient pioneer pin, to set an example. We might have an awful joke about using the “serf message service” to tell him, but only on the Broadway run.

So back to Setanta – singing a traveling song – as he skips along, on his way to his uncle. Oh how great it is to be young on carefree. But suddenly the mood changes, when he arrives to the castle, his idiot drunk of an uncle has forgotten to ask Culain to keep the hound in. And this is no ordinary hound .. this is a hound that’s represented by 3 expert dancers, chinese dragon style. More fight dancing, some explosive and aggressive tapping of feet, and then a face off. Cornered, battle-scarred and weary, our hero takes his hurl and pucks a ball straight into the hounds mouth. The hound died with a huge groan. The music reaches an epic climax, the pipes roar.

The Red Knights come out, now sobered up, Culain falls to his knees on the sight of his dead hound. There might be space for a “Man’s best friend” lament. Culain explains to Setanta that he now has a debt of honour, and that he should guard the castle in the hounds place. Setanta, young and carefree, doesn’t show much interest at first. Then, from behind the guards, emerges Caoimhe – gorgeous locks of long curly red hair and a shapely fit body that says “I dance a musical 10 times a week”. Spotlight on Setanta, who then sings a moving love-at-first-sight, oh how great it is to be young and carefree, ballad. Never mind honour – there’s a woman to be impressed – Setanta signs up, and we end act 1 with some displays and dancing as Setanta – now Cú Chullain – basically acts as a bouncer. “sorry, you can’t come in dressed like that – no tunic”.

Act 2:

It’s modern Ireland, to provide context the background might feature some unfinished building sites and an eight lane motorway that has a 60km speed limit, it’s up to the set dresser. To the same music as the opening of act 1, we come across our hero playing a game of hurling. Again, it’s one against 5. But now, the player is not setanta, but a modern Camógaí player – Caoimhe. This time she takes out three players, and gives the other two the run around, and of course sings a song about how great it is to be young and carefree. She seems even better than Setanta was, mostly it’s a wire-acrobatics kit that’s letting her jump higher.

Watching from the sidelines is Setanta, now the local hurling captain, and he’s enthralled. Once Caoimhe is done trashing the 5 players, he pleads with her – would she like to go out? He asks her to come see him play in the local final on Sunday. She looks torn, and spotlit – she sings to us about how she’d love to say yes, but just can’t. She let’s him down, and says she’s sorry, she can’t make it. Setanta feels the gentle hand of a put down, and walks off in a bit of a mood, he sings a song about this happening every week, but that he’ll persevere.

Caoimhe, now joined by her Camógaí team mates sings another song about how much she really likes Setanta, but hates the fact that they can’t play together – on the same team. It’s a song that is simultaneously full of sexual innuendo – all about playing together breathlessly – and yet speaks to the importance of being on the same team and that raising a family is the implicit reason for any healthy Irish relationship. She wants to get it on, but would also like to give birth to an entire team of patriotic hurlers.

So Caoimhe reveals her secret – big surprise, she’s been disguising herself as a guy – and playing midfield on the senior mens team, alongside Setanta, for months. It’s a musical, it’s ok for it to make no sense that he never recognised her in all of that time. She laments with her Camógaí team-mates about how unfair it all is, but gets some girl-power reinforcement and validation from the chorus. Sings about how crazy it is that Ireland is so modern in so many ways, but that the spectre of sexism is still there on the field of hurling.

And then, to our climactic scene – the Sunday game. It’s a tight one, it’s the last 5 minutes and it’s an even score. Insert tension here. Setanta and Caoimhe both miss a few chances. But at the last minute, after some epic dance-fighting, Setanta passes the ball to Caoimhe, who scores the winning point. Setanta and Caoimhe embrace in what he thinks is a brotherly hug of fellowship.

But of course, Caoimhe removes her helmet and reveals the curly red locks. The secret is out. At first, Setanta is shocked (think “you finally made a monkey out of me”) but quickly gets over it – oh how great it is to be young and carefree. End with a number that ramps up both the sexual innuendo and happy thoughts of Catholic family.

Fin.

Liberally sprinkle in some jokes about teams going on strike, questions about players getting paid, some post-modern recession references and a dancing at the Crossroads jig in the middle, and I think there’s winning formula potential.

Photo courtesy of Eoin Campbell and is CC licensed.

]]>
http://www.stdlib.net/~colmmacc/2009/07/18/hurling-the-musical/feed/ 1