MemberDB speed improvements

So I finally installed the xdebug PHP extension and started doing some performance analysis of MemberDB using xdebug and kcachegrind. The upshot of which is a number of commits to the bzr tree that dramatically improve performance in several key areas. The answer? Caching.

I’m not even talking using memcached or caching things in database tables or anything like that – just about everything is still the same dynamically produced content as before, but I’m now caching some simple things avoiding many round-trips to the database while executing a script.

There were a few things that were taking a fair bit of execution time:

  1. The generation of the menu. In MemberDB, there’s a menu on the left. There’s also a powerful (read: non-trivial) permissions system allowing relatively fine grained granting of permissions. So, we need to check that the user has permission to go to the page before showing the page in the menu.
    Previously, for each item in the menu, we’d do a lookup to the database – checking if they have the permission or they are an admin. This ended up taking a bit of time – up to 30% of the time for the front page was taken up just generating the menu!
    So, now I cache the set of permissions for the user. One function to fetch it from the DB into a structure, another function to check the permissions of the user in that struct.
    While testing this, I actually used memcached to cache the menu to see how much of an improvement I could get… I’m about 69/70ths of the speed of using memcached with a purely PHP implementation caching the permissions info.
  2. Getting the information about a member is done in a variety of places. On some pages, you want information on the current logged in user (or just need to find their member ID). These are now cached for the duration of the script. Saved quite a few DB round trips
  3. When viewing an election (not the results, just the normal “view election” page that lists candidates), we need to get the membership information on a number of users (okay… so technically I should rewrite some of the queries to use joins in the DB… but this was easier). I now have a (limited) cache of membership info. So now, when a member has nominated multiple people, we only pull the member info out of the database once.
  4. Rewrite the “current_members” view. The old one was not as efficient as it could be. While the new one has slightly different semantics (can have duplicate rows, it turns out the use of DISTINCT was adding a bit of execution time, which for a bunch of queries is not needed) it’s significantly quicker.

I used the faithful Apache Bench (ab) to do benchmarks against the modified PHP code. I think the biggest improvement was the view election page which went from about 6seconds/page to 0.2seconds/page.

Enabling bluetooth on a hp laptop (6710b IIRC)

A friend of mine has a HP 6710b (if i remember the model name correctly). Bluetooth wasn’t working. Nada… not even a USB device showing up in lsusb for the inbuilt bluetooth.

It turns out, if you disable the bluetooth radio from the Windows thingy, it does something you cannot undo from Linux (at least with Ubuntu Gutsy) .

Except… after hours of fucking around, we reset the BIOS to default settings and this made it work.

Yep, no option in the BIOS setup to do this (there’s an Enable/Disable switch… but that doesn’t fix this problem). But a reset does it.

I really hope this saves somebody else the hours of “fun” we had.

Baking Bread

Sometime in what we laughingly call the past (okay… the last week) I used a (slight) modification to this Basic white bread recipe and baked bread. Today, I’m doing it again. Why on earth I’m baking in hot weather is another question…. but anyway. The only real change to the recipe was using vegetable oil (just normal cheap cooking oil) instead of butter (i.e. to make it Vegan).

Last time I made the bread it was quite good – the crust was totally awesome. Hopefully will be this time too. Maybe I’ll even take pictures :)

Vegan Choc Chip Cookies

I was inspired by this recipe: Best Vegan Choc Chip Cookies! and slightly modified it. Namely, I didn’t seem to have any maple syrup, so I used Golden syrup and i wasn’t sure it was chocolately enough, so added 1/3rd cup cocoa powder.

I quite like the outcome, and so at least does Michael – so it so far gets one friend approval.

The complete recipe (what I did, not exactly what’s at the link):

  • 1 1/4 cups plain flour
  • 1 1/4 cup oat flour (to make, grind approximately 2 cups rolled oats in food processor until a fine, flour consistency)
  • 1 1/8 cups rolled oats
  • 1 teaspoon salt
  • 1 1/8 teaspoons baking soda
  • 1 1/2 cups semi-sweet chocolate chips (I used some I found that were about 63% cocoa and supplemented with some crush soy chocolate – if making this vegan, check the choc chips – even dark chocolate chips may contain milk)
  • 1 cup golden syrup
  • 1 cup canola oil (i just used normal vegetable cooking oil… likely canola..)
  • 1 tablespoon vanilla extract
  • 2 tablespoons water
  • 1/3 cup cocoa powder

and then:

  1. Mix everything together in a bowl. It will be a moist dough, and yummy
  2. Put it on biscuit trays
  3. 180 degrees C for 18-20 minutes (or a bit longer if your oven is crap like mine)