uniqid() is slow

So there I was, profiling one of our systems with XHProf and what jumped out as taking up lots of wall-clock execution time? uniqid(). This function, which provides a convenient way to generate unique identifiers, can hold up your PHP execution far more than it should if you’re not careful.

Two things about uniqid() make it a potential performance minefield:

  1. If not called with a second argument of TRUE (the “more entropy” argument), uniqid() sleeps for at least a microsecond.
  2. uniqid() relies on the system function gettimeofday() — and the Linux kernel essentially serializes access to gettimeofday() across all cores.

Continue reading “uniqid() is slow”

Experiment with Literate Programming Didn’t Work Out

About a year and a half ago, I tried doing some “literate programming” for one of our internal scripts. Well, I have just converted those scripts back to the normal, un-literate (illiterate?) style. It just wasn’t working out.

Continue reading “Experiment with Literate Programming Didn’t Work Out”

xnperfstat: wrapping NetApp’s PerfStat Tool

Perfstat is a diagnostic data collection tool for NetApp filers. If and when they experience performance issues, NetApp Support will likely ask for perfstat to be run against the ailing filers. This is (hopefully) not something that is done often, and therefore, the details of how to run it may get rusty, which is problematic in the middle of an availability storm.

Continue reading “xnperfstat: wrapping NetApp’s PerfStat Tool”

The Nagios Shell (ngsh)

Another tool we’ve got a fair amount of mileage on is what we internally refer to as the Nagios Shell (ngsh). We have used Nagios since our early days (circa 2005), and it has served us very well to keep an eye on our infrastructure. Over time, we started writing tools to poke and probe Nagios in one way or another. The end result of this process was a hodgepodge of tools that parsed status.dat and did other things they really shouldn’t. We lacked consistence across the toolset, some of them took forever to run (we have a decently large environment), and others failed in mysterious ways.

Continue reading “The Nagios Shell (ngsh)”

Zettabee and Theia

It’s hard to believe it has almost a year since we started the process of open sourcing tools, but it has indeed been that long, and it picked up steam a few weeks ago, when pushed out nddtune, which is admittedly a very simple tool. Today we’re continuing that effort with a couple of more significant tools: Zettabee and Theia.

Continue reading “Zettabee and Theia”

Operations Toolkit

A few months ago (has it been that long already?!) we started the process of pushing some of our internal Operations toolkit out in the open (and you can rightly argue that we barely dipped our toes in the water).

We are picking up where we left off, and are working towards releasing several other tools over the next few weeks, some of them trivial (let’s call them utilities), others far more significant (true tools).

Continue reading “Operations Toolkit”

3 Steps to Understanding Ungrokkable Legacy Code

On Friday I was faced with making some changes to some old code that nobody really understood. Nobody liked to go into this code, so nobody was familiar with it. I too dreaded to make changes to it, and only dipped my toes in it as little as possible to understand what I needed to know.

Well now I needed to understand it better in order to make a bug fix. It turned out to be a good opportunity to learn what this code was doing and make it easier to understand.

Continue reading “3 Steps to Understanding Ungrokkable Legacy Code”

PHP Tip: The identity function I()

Here’s a tip I picked up from another PHP programmer. It’s called the identity function, and it simply returns its argument:

function I($subject) {
    return $subject;
} 

Now what so great about that, you ask? One cool thing is that it allows you to instantiate an object and call a method on it, in a single statement:

I(new Foo())->bar();

Continue reading “PHP Tip: The identity function I()”