Musings
muse: to turn something over in the mind meditatively and often inconclusively
Speculative Lock Elision

SLE is easily one of the most cunning ideas I've stumbled across recently. Basically the idea builds on something known as lock-free synchronization. In a nutshell the idea behind lock-free synchronization is data structures that support concurrent access without using locks (or any other explicit synchronization structures). This is achieved with a lot of copying behind the scenes. Operations are handled as atomic "transactions" and when an inconsistency is detected the relevant operations are rolled back (relevent is determined by examining the state of the structure for inconsistencies periodically and checkpointing when all is well).

SLE builds on this by noting that modern multi-processor systems must handle similar problems when maintaining cache coherency between CPUs. Essentially they're implementing the approach proposed above in hardware. The advantages are that most of what's required in hardware is already available today. They've demonstrated gains in software that typically experiences high contention.

What this provides is the possibility of dynamically removing unnecessary lock acquisitions. In many multi-threaded applications there is always the chance that a particular "run" would have been entirely correct without any lock acquisition. Think about a Java HashMap instance with space for 10 elements, and code that (for whatever reason) only ever ends up storing two (unique) Strings in the map. No collisions. No need for the map to grow, ever. This would work equally well as a synchronized or unsynchronized map. But, if the Strings being inserted are dynamic, or the number of Strings varies, then you have to use a synchronized map or run the risk of incorrect behaviour. This technique (and its brethren) would allow the software to transparently remove the lock acquisitions (which are expensive and may not be required) and only force acquisition (or some equivalently costly operation) when required.

Which falls right in line with make the platform smarter, not the programmer.

Posted at 09:55 PM

Tagged!

Sam tagged me to produce this list.

Name ten celebrities that you find attractive (in no particular order), then tag five of your friends.

  1. Natalie Portman
  2. Helena Bonham Carter (One I can't explain)
  3. Julia Ormond
  4. Mary Elizabeth Mastrantonio
  5. Monica Potter (Julia Roberts, but attractive)
  6. Michelle Pfeiffer (ever since Ladyhawke)
  7. Cate Blanchett
  8. Nicole Kidman
  9. Debra Messing
  10. Meg Ryan (stick with the classics)

I considered, briefly, including The Corrs (three for the price of one!), and they've got the Irish thing going for them, but I had to draw the line somewhere.

I don't think I know enough people with blogs to tag who will be receptive to being tagged. The only person I can think of might be Mandy.

Posted at 07:51 PM

Kopseer

Migraines are horrible little bastards. They creep up on you and, just when you're looking the other way, leap out of the shadows and turn you into a slothful, debilitated wreck. Fortunately the drugs have started to kick in.

It's weird to watch my response to these things. I don't want to be touched. Even lightly. Even by myself. Anything that introduces tension into my world must be addressed without delay. When my bladder fills up there is nothing more important than getting to the bathroom. When hunger hits, my stomach has to be filled, even if it means eating something unpleasant. I can't sit still or lie down because then there's nothing to focus on except the pain. So I pace (I do this when I have a hangover too, for the same reason). Distractions (that involve as little motion as possible) are essential until the drugs kick in.

Posted at 09:20 PM

Note to self

Newspaper consistently burns better than old bills and insurance policies.

Posted at 07:11 PM

Photo Albums

pat_drakenberg_small.jpg I struggle to put together photo albums from photos I've taken. And no, the problem's not usually one of finding quality photos. The problem is choosing what not to include. Often I have a handful of shots of essentially the same scene, but each of them captures a little difference. It may be a hand raised to illustrate the telling of a particular joke, or a grin that I know the cause of only because I was there.

I suppose that's the key right there: I was present. Blurred, or slightly off center shots present the same difficulty. They're not terrific photographically speaking, but they're important to me because they capture a fragment of a memory. Often a blurred photo is all you have of that particular instant. How can you throw that away?

The compromise is usually to save everything (being a natural digital squirrel helps) and then produce an album for "general consumption" that captures the best balance I can produce.

Which takes time and frankly I'd rather just toss all of the photos up here and let you sort them out for yourself, but I'm a nice guy, so enjoy.

skywriting_censored_small.jpg I can't claim all the credit for these photographs, since they represent a combined collection of photographs involving three cameras and somewhere between three and five photographers. The bulk of the pictures were taken by either myself or Pat. Pat has a predilection towards taking photos of himself, illustrated in the picture to the left. Pat's one of those incredibly talented creative types, so if you find yourself looking at a picture thinking "wow, that's a really nice shot" or "great composition!" then it's almost certain he took the photo. If you're squinting thinking "I think I need glasses!" then blame me.

Pat's got more of his work (different media) up here. I've linked to it before but if you haven't been there yet I really recommend it.

Pat's also responsible for any (attempts at) vaguely creative photography on my part: each trip away with him teaches me more about my camera than I thought possible. Now I just need a dash of talent. Pat was responsible for the "skywriting" shown on the right. Yes, I could have chosen a different word, but I didn't think I could fit cunnilingus into the 15 second window we were working with.

Posted at 05:07 PM

Segwhere?

I just saw my first South African Segway. This was the little suprise that was going to "change the way cities are designed".

Someone didn't get that memo. The Segway was a huge disappointment. Who wants to fork out a large hunk of dosh to trundle along at a fast trot, looking like a lost extra from the first Star Trek series?

Especially when alternatives include speeding along on a big red monsta.

Posted at 04:27 PM

Where in the world was DB1?

DB1 wrote in to show me where he spent last week.

chicago_1024px.jpg

Posted at 07:15 PM

Where did you spend last week?

berg_house_view_small.jpg

Posted at 09:51 PM

Go away!

system_tray_java.png The Java plugin for web browsers (the coffee cup in my system tray on the left) annoys the hell out of me. The first time you hit a page with an embedded Java applet the plugin is loaded and presents itself gleefully in your system tray (Windows users only of course).

Thereafter, there is no way to unload it without shutting down all browser windows. I routinely have a dozen or so sites open that I'm mulling over or may well come back to shortly.

So why is this an issue? It's quite simple really. I know it's consuming resources and dammit I want them back. Every resource counts. I often find myself relentless sifting through my process list killing anything that I feel isn't justified (or crucial to the operation of the system and even then it's borderline).

Posted at 09:38 PM

Pie in the sky

I had a pie for lunch today.

This may not strike you as earth shattering. What if I were to add that it was 3 to 4 times the size of my head? I thought that might get your attention. Sadly, it just isn't true. However, it was 3 to 4 times the length of my left big toe. Which is probably pretty scary to watch if you're a big toe. Fortunately, neither one of my big toes has eyes so they're probably both living in ignorant bliss.

Since my eyeballs are about the same size, give or take a toenail or two, I'm not sure how they're holding up.

Posted at 07:33 PM

Foot in mouth

Don't you hate switching to a new toothbrush? Especially when the inevitable happens and simply replacing the "model" you had is impossible because technology has "moved on"? And then they insist on randomly selecting the size of the head and you either end up feeling like you're brushing your teeth with a matchstick or, alternatively (and my current predicament), like you're trying to fit a shoe into your mouth.

And what gives with the range? There must be teams of elves (or gnomes?) somewhere diligently working to come up with new and entertaining tooth cleansing mechanisms. Have you actually stopped recently and admired the sheer size of the range of toothbrushes on offer these days?

Posted at 10:51 PM

Pool, the Universe and Everything

With a title like that this should be a much longer entry, but I'm not really up to it. Simon (of Oz notoriety) called earlier to find out if I was up to some pool.

So much for just an hour or two.

But I think this is exactly what I needed. I doubt I'll concur in the morning, but that's what mornings are for: regrets about the previous night.

Posted at 01:17 AM

Tripping

tree_silhouette_small.jpg Back in the mother city. We took a week off and joined some friends on a trip up to the Drakensberg and back down again (the long way round in retrospect). We pretty much circled the mountain range starting and ending at Colesberg, and then, almost as an afterthought, threw in Calitzdorp on Route 62 (home to Ronnie's Sex Shop) to break the journey home. I didn't track our mileage but the lower bound must be a few thousand kilometers at least.

We saw some pretty spectacular parts of the country. Sadly, too much of that was at night because we underestimated the travel time between stopovers for the last few days, but there are plenty of places we'll go back to based on this sampling. And I think the upper end of the R62 (relative to Cape Town) is easily the best part, and deserved of a visit on ye olde motorized Penny Farthing relative.

After I've pulled together (and filtered) the collection of photos from the past week I'll put an album up here. The picture on the left was taken on the Curries Post road on the Midlands Meander, at a small restaurant called Mulberry Hill. As a rule of thumb the Midlands Meander was a big let down, but if you do find yourself there, the Curries Post road seems to incorporate the best of the lot (including this restaurant).

We drove up to Boorfontein farm via Colesberg last Saturday to meet the other three. We spent a (very stormy) night there, and then we all headed off to The Berg House just on the Oliviershoek pass (just beyond Little Switzerland). We left (reluctantly) on Thursday morning and drove down to a pit in Mooiriver that advertised itself as The Argyle Arms Country Inn. If you're ever offered a night here, avoid it. The first clue was the owner meeting us at 10am on the morning of our arrival sporting a healthy whiskey tan. We spent the day on the Midlands Meander (disappointing) and the evening at Greenfields Manor House (new owners who appeared to be doing quite well) where we supped on prime, local, hormone free beef.

Back to the "Arms" which, on top of being located in the less than stellar Mooiriver CBD, offered us a night of noise, power failures and a morning with no water. As it turned out the owner had forgotten to buy more electricity for the "Inn". We made a swift exit first thing in the morning. And so began the epic return leg of our journey.

antique_camera_small.jpg From here on out the planned route severely overestimated our average speed. We drove through some spectacularly desolate scenery along the N2 as we wound our way towards Lammergeier on the other side of Barkly pass. This is a part of the world I want to go back to. It's hard to describe and the light was failing so no pictures were possible. Go see it, I promise it's worth it. We were hoping to stay an extra night to enjoy the surroundings (our planning meant we arrived at night and would have to leave first thing the following morning) but alas, there was no room in the inn and no convenient stable nearby. So we headed off to Calitzdorp, a 9 hour drive from Lammergeier (just outside Lady Grey if you're following on a map). Another late arrival and early departure, but we'll probably try to head back to the Calitzdorp Spa at some point too. It's very reasonable and the surroundings are worth a return visit. We left this morning and arrived back at about 2pm.

On a number of occasions I considered whipping out the laptop (yes, it came with) and making a few notes for the blog but (as often happens) never actually got around to it. In retrospect I'm glad about that, at no point did this infernal machine partake in my break from the working world (and reality in general). Come to think about it, the last week has been remarkably detached. I think I spent most of the drive up last Saturday (about 9 hours) thinking about something vaguely related to work, but that was about it. Excluding that, the closest I came to anything work related was probably the dream sometime midweek involving a knife-fight with one of my developers over a flawed Registry backup implementation. In my defence (literally) he pulled his knife first, I was just very prepared. And it wasn't all macho posturing, I spent a good part of that dream going through the intricacies of exception handling in the face of deeply nested recursion, and talking him through the details of why his implementation simply wouldn't work. If I recall correctly, his implementation failed to take into account subkeys. Or something along those lines.

kargs_post_small.jpg The lack of any notes does mean that anything I put down regarding the past week will be sketchy at best, somewhat incoherent, and entirely suspect. Actually, the latter applies to anything you find on this site so scratch that.

These breaks always leave me a little disoriented. I'm sure I'll spend the rest of the week trying to figure out what's changed back home. I know I've only been away for a week, but it always feels like much, much longer. I think the next few weeks will be particularly trying because we're off again in less than a month, for an even longer period of time, and much, much further away from home. So reengaging is probably going to be a challenge, especially since I'm not feeling particularly inspired about work at the moment. The 5 project has gone to the first customer (hmm, I wonder how that's going) and if the past week of silence is anything to go by, my team is more than capable of delivering it without my help. Which is how I want it. As much fun as job security is, it's better for the company, better for my team, better for the individuals, and better for me if the dependency on me is minimal.

The long drives did give me a lot of time to think. I haven't come to any startling conclusions, but I have mulled over a lot. Some of it I'm still digesting and, no doubt bits and pieces will make their way onto this page over the coming weeks. I think the biggest personal "revelation" is quite simply that, come the end of the year, I'll know a good part of what life holds in store for me next.

sunlit_cloud_small.jpg I also think I understand more about why I enjoy these long drives more than many other people. Apart from the time alone to think (almost everyone asleep after a few hours, leaving me to myself), and the forced disconnect from the world, there's a more practical reason I enjoy it so much: birds. Distances like these can cover a good cross-section of the country, and it's amazing what you see on the side of the road alone. Without even venturing off the beaten track we saw Cape Vultures, Pale Chanting Goshawks (by the dozen), the usual plethora of Rock Kestrels, Jackal Buzzards and Blackshouldered Kites, and a host of smaller birds that may not be the rarest of their kind, but are birds I don't see very often. A long road trip includes a goodly amount of birding, if that appeals to you. This can be a great help if your thoughts are taking you down roads you would rather leave be for the time being.

I also spent a fair bit of the past week playing with my camera. Patrick also has a Canon and is particularly good at his photography (anything creative actually), and is a wealth of information on how to get the most out of your camera. We spent one crazy evening playing with a combination of a flash from one camera and another camera with a long exposure to experiment with overlaying a "drawing" at night on the person drawing it. The results were entertaining and will be included in the promised album. Patrick and I also share a sense of humour (such that it is) which made it all the more entertaining.

Sadly, these trips inevitably end, and reality forces its way back into view. Fortunately this is a big country, and if I ever run out of roads here there are more countries waiting.

Posted at 04:08 PM

It's a man's world

Interesting statistic (quoted without anything to back it up). Women attempt suicide 5 times more frequently than men, but men get it right more often than women.

What can we take away from this? If you need something done, give it to a man, even if the task is taking their own life.

*ducks*

Posted at 10:23 PM

Enlightenment

No, not the window manager. Window managers are not something I get particularly excited about. In truth, using most window managers tends to have me checking the underside of my mouse for treacle periodically.

No, I'm talking about enlightenment in the Nirvana sense of the word.

I feel like I made a small step towards that state today. I battle in particular with one person. Fortunately, the Atlantic ocean separates us, so interaction is rare. But when it does happen it frustrates the living banana jam out of me. Today, though, I feel like I reached a point where I managed to let it go. He's one of many, much of his griping is noise and bluster, and frankly, he's not technically equipped for many of the decisions he feels are his to make.

And I really shouldn't let him get to me like I do. Today, for the first time, I think I reached a point where I could put him aside. Maybe not completely, but to a degree where he was just a high pitched chipmonk voice in the back of my mind.

Baby steps.

Posted at 07:34 PM

Time for glasses?

I spent at least 30 seconds just now trying to rub a mark off my laptop screen.

Eventually I looked a little closer, only to discover it was an apostrophe I'd accidentally typed into my text editor.

Sometimes, the only sensible option is to call it a night.

Posted at 11:09 PM

Conservatism

Something which worried me when I joined as a peewee wet-behind-the-ears developer was what I took to be stagnation.

My team is responsible for, among other things, an SDK the rest of our software builds on top of. When I first joined this team the SDK had been through three releases (a period of a few years at least) with almost zero changes. The first release I was involved in saw more changes than the entire collection of releases before that that one.

And I was pretty disheartened with the reaction. People expected code that was written on a later version of our SDK to run unchanged on earlier versions of the SDK. They clearly hadn't stopped and thought about this because it implies that we somehow ensure that code added in a later release of the SDK make its way into versions that had already been released. I thought a lot about that and it didn't take much to see what caused this reaction: our developers had grown used to the fact that the SDK was static.

Thankfully we've dragged them kicking and screaming out of this mindset. I view that as progress: imagine where we'd be if the latest Java release had APIs that were unchanged from the 1.1 release. Or Python. Or any library.

While not on this scale, I've bumped into a related phenomenon over the past few years. It's a kind of conservatism that manifests as an attempt to stifle any change that's viewed as even remotely risky.

I ran into it again this evening and it makes my blood boil. My team introduced a profiler-like mechanism into our SDK that allows us to report on database activity (mostly timing data) in an attempt to tackle a recurring problem on client sites: the app locks up briefly, often because of excessive locking at the database level. One of the first things we need to understand is which database operations where involved. And more importantly, we need to know then and there. This is about diagnosing a problem in the field.

Now the first implementation was flawed and resulted in a few problems under load. We corrected it and that issue is no longer an issue. Recently another performance problem arose and it was tracked back to this code. As it turns out, badly behaving code was (erroneously) generating thousands of unique query strings, resulting in our internal profiling structures gobbling up excessive amounts of RAM. Fair enough, the SDK can be (and has been) updated to cope with badly behaved applications.

One of the guys involved in tracking this down has now demanded that we disable this functionality by default. It's just too risky he feels. What he fails to understand is that this functionality is useless unless it's enabled. That's the whole point of a tool aimed at problem diagnosis.

The knee jerk reaction in this case, "take it out, take it out, it's too risky!", really gets up my nose. Yes, there's risk. Is it unmanageable? No. Do we expect a few teething problems? Yes. Is the potential gain here worth accepting those teething problems? I think so.

Without tools like this we are up the creek when it comes to diagnosing this class of problem. Just mention "610 event" to any one of our developers or support engineers and watch the reaction.

It's really (really) important to me that the environment I work in views change as positive. Progress should be a given, and not something we're occasionally prepared to risk.

Posted at 07:37 PM

Byte me

Feeling quite chuffed with some code I wrote over the weekend.

I've had a hankering for some time to play with one of the byte code manipulation libraries available, but I've never really had an idea that interested me enough to make me sit down and get stuck in.

A posting in a forum requesting some functionality in the JVM from Sun caught my attention last week. It planted an idea in my head and from there it was a hop, click and a jump to that which I spent the weekend crafting.

Before getting started though, I had to decide which of the three byte code manipulation libraries I was going to use. BCEL was one I'd heard of before. SERP was new to me, and ASM I'd seen touted in a blog I read periodically (claiming in particular that ASM was fast and easier to use than BCEL). So I pulled all three down and looked at some sample code. To be honest, SERP looked the most intuitive out of the box, but was the slowest of the lot. ASM was definitely the fastest, by a long way, but initially I wasn't sure I liked the look of the sample code. As it turns out though, ASM has a pretty intuitive programming model (it's based on the SAX callback model, which is where they make their efficiency gains). It seems that the other two were primarily designed for offline byte code inspection, whereas ASM is aimed at runtime byte code instrumentation.

So having decided to give it a go with ASM all that was left was to see if what I intended was feasible. Turns out, it was :-)

The core idea is pretty simple: a custom ClassLoader that tweaks the constructors of each class it loads to register the new instance with a central class. That central registry maintains a mapping between Class instances and a set of the live instances of that class. The set of instances actually contains WeakReference instances wrapping the instances so as to avoid holding up garbage collection (without which, can you say "Memory Leak"?).

Each WeakReference is associated with a single ReferenceQueue, which is watched by a background thread. This ensures we're notified when objects are garbage collected.

A second mapping is maintained that maps each WeakReference to it's associated Class. This is used when the reference is dequeued by the aforementioned worker thread. The reference is mapped back to it's class which tells us which set to remove the reference from.

This leaves us with a mapping of classes to a set of live instances (well, really to a set of WeakReferences to live instances). Often, just knowing the numbers of live instances by class can point you in the direction of that pesky memory leak.

And all this in about 300 lines of code. It really isn't particularly difficult once you've pulled all the threads together. In fact I spent most of the rest of the time spent on this project over the weekend figuring out where to insert the ClassLoader within the product I'm responsible for, which already sports a number of potential ClassLoaders (ours and other people's).

How cool is that?

Posted at 10:47 PM

Luke, I am your .... *cough*, *hack* ... argh

Ah, Winter. Terrific if your partner is a Star Wars fan. I've picked up a bit of a head cold and as a result woke up this morning doing a serious Darth Vader impersonation.

Posted at 10:30 PM

Sunday spectacular

Funny how people are drawn to a spectacle. And clearly people consider 35+ bikes out for a Sunday run a spectacle.

Andy, Riel and I joined the Pegasus crowd for a Sunday breakfast run to Gordon's Bay. A shorter run than usual, but it was just as well. That many bikes on the road can get a bit out of hand.

The most interesting bit of the ride was just before we joined the R300. I hit a very shallow furrow about the width of a car tire and for a few hundred meters "up" was suddenly in flux as the bike wobbled from one side of the furrow to the other.

After breakfast the three of us decided to continue on along the coast road. It really was just too nice a day to waste. The coast road (round to Kleinmond) is one of the most spectacular roads I've ever ridden and the best thing about it is that it's 20 minutes away from home. Can't ask for more than that. And it's a marvelous winding road with terrific tar to boot. One day I'll actually bring myself to stop and take some photos but it's one of those roads that makes stopping extremely difficult.

Anyway, a picture being worth a thousand words, here's my new baby (actually, that second one is just a picture of some random putz). Hang on. A picture? I can do better. After all, the VFR has to be heard (16Mb) to be fully appreciated.

Posted at 06:30 PM

Biker's guilt

Eish. Ain't life just a barrel of laughs. A little while back a close family member was diagnosed with cervical cancer.

It came to light today in a conversation that they've had to borrow a largish chunk of cash to pay for treatment.

And here I am on a "new" hunk of metal that cost me an amount that would settle all of their bills and then some. And it's my second one.

Makes you want to hang your head in shame and go sit quietly in a nearby corner.

Posted at 02:20 PM

Red wine - The Devil's work

Bit of a tender morning. I overindulged on a good bottle of red wine last night. I knew it would happen but everything is easier from the other side of a few glasses of wine, including screwing yourself over.

So that meant a headache-filled morning and, given my tendency to skip breakfast, come lunch time I was in a pretty sorry state. I always forget how much of a difference food can make in that state.

I spent a little time just watching the team today. I'm really starting to feel more dispensable as the days pass, which kind of sucks (bye bye job security) but suggests I'm doing a good job of making my team a little more self-reliant. I'm literally seeing improvement on a daily basis. Some of the guys still have a way to go yet, but the team as a whole is doing pretty well, especially given the lack of experience (on average) across the group.

I think a lot of it boils down to stretching people. I really feel the best way to learn, and by implication the best way to teach, is to just dive in and start trying to swim. If you have good people around who are willing and able to give you assistance when you really need it then your learning curve is significantly steeper than if you're spoonfed and are never forced to apply what you're learning.

This can be a painful process, and demands tolerance from other people who depend on the person or people learning, but I really think it's worth it in the long run. Unfortunately I don't think everyone we work with understands this, or is prepared to tolerate it. Frankly, that's their problem. If they're not prepared to take a longer term view of things then I'm not prepared to burn in the short term just to service their selfishness. In everything a balance you must find (to put words in Yoda's mouth).

But we're coming through the most difficult part of the learning curve and I'm starting to see the results. Most of the guys I've heaped responsibility onto have just about broken through the pile of dirt they're buried in and are about to take their first breaths of fresh air.

Of course, if I do too good a job, then I may well be out of a job ;-)

Posted at 07:36 PM