Speeding Up Gallery 2

I’ve written a couple posts in the past raving about Gallery 2, an open source, web based photo album organizer. An I’ve imported most of my digital photos and media, bringing the total ‘items’ up to over 16,000. But I have been finding Gallery 2 to be incredibly slow. And I don’t remember if it was always like this or if it’s a result of me adding more and more photos. But this afternoon I decided to get to the root of the problem(s).

I did some quick searching around on Google and discovered some other users have found the app slow, but no solid answers as to why. I didn’t bother posting to the forums myself because I run Gallery on top of PostgreSQL and far too often I’ve been given the flame answer of ‘Oh, well it runs fine for me on MySQL so that’s likely your problem’. And perhaps, in this case, it is partially to do with PostgreSQL. I knew it wasn’t an issue with the server because the load is low and there was no real hit on apache until just before the page rendered. Unfortunately, that left the database. And truth be told, this might also be an issue under MySQL in some cases, but since I use PGSQL, I can only talk about it.

If you’re finding Gallery 2 slow, start by disabling the ‘Image Block’ module. It has some SQL in it that can be the problem. It’s not that the SQL is bad, it’s just that the Image Block module runs a couple of queries that if not using an index will take far longer than necessary. That’s both a PostgreSQL and a Gallery problem. If that works, and you can live without the nice random image you get with the Image Block, then you’re done. If not, then you need to have access to your database so you can do some tweaking.

There are two slow queries, both which should be using an index. Load up PostgreSQL’s psql program, or some other DB admin tool that lets you run queries, and try this:

EXPLAIN SELECT COUNT(*) FROM g2_ImageBlockCacheMap WHERE g2_ImageBlockCacheMap.g_userId = 10;

You should see:

QUERY PLAN
———————————————————————–
Aggregate (cost=11042.91..11042.91 rows=1 width=0)
-> Index Scan using g2_imageblockcachemap_1627 on g2_imageblockcachemap (cost=0.00..11007.43 rows=7095 width=0)
Index Cond: (g_userid = 10)
(3 rows)

The important part is that you see Index Scan and NOT Seq Scan. If you see Seq Scan, then the database is going through the entire table. Twice, in fact, since the second query I mentioned is likely going to give you a similar result. At this point you have two options, and you may want to consider doing both.

First, you can tweak the PostgreSQL configuration options that deal with query plans. I suggest reading up on the options first and doing trials on a non-production database. Especially since a PG restart is required for any changes to take effect. Every database config will be different based on processor power and memory and such, so I leave it up to you to figure out how best to change things for your setup. The key thing is though, that you want to tell PostgreSQL’s planner that whenever possible it should use indexes. And sequential scans should be a last resort, except for small tables.

That done, it still may not be enough. And it wasn’t enough to work for me. I’m not entirely sure why the index on the g2_ImageBlockCacheMap table still wasn’t being used but I suspect that it might have to do with the fact that it’s a tuple. Regardless, all that was required was to add an index and vacuum the DB, as such:

CREATE INDEX g2_imageblockcachemap_idx_extra ON g2_imageblockcachemap(g_userid);
VACUUM ANALYZE;

Then re-run that EXPLAIN to see if the index is used instead. It worked for me. And once again I can use the Image Block module.

Published on Tue, 13 Jun 2006 03:03
0 comments

IFR INRAT Exam

I wrote my INRAT exam this morning at the Transport Canada offices, which are located at Calgary’s Airport Corporate Centre. It’s a nice building but with no parking specifically for the building’s visitors (that I could find) I was forced to park in the airport parkade at a cost of $18.00 for the morning. To me, that seems like a deterant to anyone wishing to setup shop in the building, no matter how nice it is. Of course, it’s not like TC cares how much I have to pay to come visit them. Though, CFC is in the process of getting set up so that all TC exams can be written at the club instead; as of this blog entry you can do your private and commercial but not the INRAT (yet).

I considered taking the actual AeroCourse class but decided against it as I could not justify the cost (I’m a frugal kind of guy). And I figured since I was spreading my training out over many months, I’d have sufficient time to do all the required reading and study. Instead, I opted to purchase the AeroCourse workbook, which contains hundreds of sample questions broken out into various categories. I did most of the questions late last year after doing all the reading and then spent the majority of my time studying the areas that I was weak in. Then I redid most of the questions again last week in preparation for writing the INRAT.

A friend of mine who recently finished up his instrument rating bought the Instrument Rating 2005 books authored by Michael Culhane The texts have a Notice to Users which is very specific in what users, flying schools, clubs and instructors can do with the books but I’ve always felt that, other than copying, you should be free to do with a book as you see fit after you’ve bought it. That aside, I realize that this isn’t like a fiction novel in that the texts only really appeal to the people who decide each year to start their instrument rating in Canada. And given that there are an average of 2500 people issued Canadian pilot licences each year and only 14,400 pilots with instrument ratings, I suspect that there are not more than a few hundred people who start their instrument rating each year. That’s a relatively small market. So I can understand where Mr. Culhane is coming from.

There were several errors in the 2005 version of the Ground School Course book and although updates are available online, neither my friend nor I realized that until afterwards. That said, there was only one posted correction for 2005. There was also very little current information on GNSS and GPS approaches and overlays, which is a pity since both my friend and I ended up with six and four questions respectively on the exam dealing with GPS. Most of the sample approach templates were more than a few years old, which would be okay if the CAP style hadn’t changed. But the look of the CAP has changed, and if you are going to pay a premium for a book like this, I think the book should be as current as possible in all respects, and for me, that means that the sample approach plates should look exactly like the actual CAP plates. Since I read the Air Command Weather Manual and the Instrument Procedures manual first, I found the information in the ground course text to be basically an ultra condensed version of those two texts, plus the AIM. So if you are looking for a Cole’s Notes way to study then you can try the Culhane book. But my suggestion is to go out and buy the AeroCourse workbook (and no, I don’t have any relation whatsoever to AeroCourse), especially if you are the learn on your own type, and do the reading from the actual sources (IPM, ACWM and AIM). It’ll take more time, but I think you’ll find that you’ll learn more and get far more detail. Plus your goal should not be to simply pass the test but instead to learn the material such that you can safely act as PIC under IMC, and at the same time, pass the INRAT.

On a semi-related side note, here’s an interesting press release from ATP, whom Culhane tried to sue over some free exam questions that ATP had made available online. And there seem to be a lot of people with strong feelings on Culhane and his books.

This was the first real exam I’ve written since I graduated from University of Calgary in 1997. And like all the exams I had to write there, I was incredibly nervous despite all the studying. But, yes, I passed.

Update: In a message from Mr. Culhane, I’m told that the 2006 version of the Instrument Rating books have been re-written and have more current information. I can’t vouch for that, however, as I haven’t seen them but go and check it out for yourself. My comments above are based on the 2005 version of the texts only, not the latest, now available, 2006 version. And for anyone who might criticize me for using a 2005 book part way through 2006, yes I realize that I was using an older book. But when I started studying, it was 2005. I read the Instrument Rating 2005 books in 2005. And last time I checked, there were GPS (now GNSS) approaches in 2005. In fact, there were GPS approaches in 2004, since I have an older CAP 3 from 2004 with GPS templates in it.

Published on Fri, 09 Jun 2006 19:37
0 comments

KDE 3.5.3

KDE 3.5.3 was released on Wednesday, though the monolithic ebuilds for Gentoo weren’t available until yesterday afternoon. I prefetched all the packages earlier this week and yeserday evening set up my Dell Latitude C840 to crunch all night long, compiling KDE 3.5.3. Once again, the KDE gang has produced a solid release, and thus far KDE 3.5.3 (built from source under Gentoo) appears to run just fine. It also seems to start up slightly faster, though the improvement for me is not as much as some people have been reporting.

Published on Sat, 03 Jun 2006 15:23
0 comments

Hotel Coffee

Thanks to a link in Sam’s blog, Blogging At FL250, I discovered a really great podcast last week titled ’Hotel Coffee.’ The host, Dan O’Leary, is a pilot for Horizon Air and has a very raw podcast. But I say raw in the good sense of the word. As I mentioned in a recent email to Dan, podcasts where there is very little editing as more in tune with what I think podcasting should be: very much like a live radio show. So many podcasts these days try to be these highly polished, commercial quality shows and the end result, while refined, seems contrived and often times, fake. If you listen to Dan’s podcast #35, you’ll hear him mention me and quote those very words.

It’s the same thing with official company blogs: the companies are simply using the hype of blogs to turn press release type articles into ‘blog entries’. But I don’t fall for that, and I suspect that after a while neither will anyone else. People want their blogs raw; they want to hear people’s thoughts and feelings, not a ‘story’ written and rewritten by some media relations intern.

So check out Dan’s podcast for a true podcast, in the original spirit of what a podcast should be. It took me the better part of a week to catch up and listen to all his podcasts, but it was time well spent; truly enjoyable, full of cool stories about life as a first officer for a regional airline and, most importantly, raw.

Published on Sun, 21 May 2006 04:22
0 comments

The Importance Of Error Messages

I had a good laugh on Friday as I ready the Pop-up Potpourri: Mayday Edition article over on The Daily WTF. As one person commented: ”These make TheDailyWTF worth existing.” So funny. More so since these pop-ups come from actual applications. I have always believed that if you are going to display some sort of error message, the message should really only display a brief explaination of what happened (ie. ran out of disk space), what didn’t happen (ie. file wasn’t saved) and what the solution is, all from the user’s perspective. The user doesn’t care about internal error numbers or stack traces or anything else that relates to debugging of any kind. All the user wants to know is how can I fix the problem and move on with what I’m trying to do. Everything else is stuff that should be in the application’s log file.

That brings me to log files. I ran into a small error this weekend that caused me to sit down and say “what was I thinking?”. And before you start into me about not using a logger, such as log4j, forget it; this application predates log4j. And not only that, there are some instances I can think of where you may want your logging to go to stdout. I have slowly been migrating the logging over to log4j but there are still a fair number of calls to System.out.prinlnt(). Anyway, once again, I digress. I had been tinkering in the code of an application, adding some new features. But recently I had also been cleaning up old code, mostly instances where methods had been deprecated. I was testing something out, when I saw a string of these in my console logger:

UTF-8
UTF-8
UTF-8
UTF-8

The offending code it turned out was a result of a change I made due to a deprecated method within URLEncoder. The new method requires an encoding scheme, which The World Wide Web Consortium Recommendation states should be “UTF-8”. But what I had instead was “UTF-8 ” (notice the extra space) within code similar to this:

try {
  userList.append(URLEncoder.encode(lastUserStr, "UTF-8 "));
}
catch (UnsupportedEncodingException uee) {
  System.out.println(uee.getMessage());
}

The end result was that an UnsupportedEncodingException was being thrown and the error message associated with that exception was my invalid encoding scheme. Unfortunately, in a console logging window, that extra space doesn’t show up, so from a developer’s perspective it looks like UTF-8 isn’t supported. And that simply wasn’t the case. Since I haven’t got this particular class set up with log4j and not wishing to introduce any major changes at this point, I replaced the offending code with something like this:

try {
  userList.append(URLEncoder.encode(lastUserStr, "UTF-8"));
}
catch (UnsupportedEncodingException uee) {
  System.out.println("Unsupported encoding: " + "[" uee.getMessage() + "]");
}

So next time you are writing a error message, think aobut who the reader of the message will be and ensure the message is written from that person’s perspective. And don’t try and write a message that will satisfy multiple types of people.

Published on Mon, 15 May 2006 22:21
0 comments

30,000 Junk Emails

Today is a big day. In late December 2002, I started collecting junk emails. I’m not quite sure of the actual date nor am I quite sure why I started keeping these junk emails, but for whatever reason I did. And I only kept junk emails that were sent to me, via any of my email accounts (I have several addresses). I never asked for anyone else’s junk nor did I go out of my way to get junk mail. I simply collected the stuff that was sent. And now, three and a half years later, my junk mailbox is full of 30,000 emails which were a waste of my bandwidth and time. Not to mention service providers around the world.

Luckily, however, I’ve been using Mozilla Thunderbird since its inception. And one of Thunderbird’s best features is it’s adaptive junk mail detection. Thunderbird uses Bayesian filtering, which was made popular in part thanks to Paul Graham’s ”A Plan For Spam”. Unlike traditional junk mail filters at the time, which were mostly based on the sender’s email or perhaps on specific words, Bayesian was more mathematical in it’s filtering approach and with proper training could reduce false positives to a miniscule amount. If you’re interested in more information, you should read Paul’s essay but in short, filtering based on the senders email address doesn’t work because the spammers simply make up random names and email addresses. And judging spam based on single words like viagra, for example, doesn’t work because while an advertisement for purchasing the drug is spam, a joke email from a friend about taking viagra is not. Read the original essay though as it’s quite enlightening. And there’s a follow up article also.

Since training Thunderbird as to what I consider junk email, I have yet to have any false positives. Though, to be perfectly honest, I’m so convinced of Thunderbird’s adaptive filter that I no longer check for false positives. So the chance exists that there may be a couple. But I doubt it. I have seen a slight increase in junk emails that don’t get caught recently but I don’t mind because marking them as junk is a single click task. And just like life for me, where my learning never stops, Thunderbird continues to learn too. Even after 30,000 junk emails.

Published on Mon, 08 May 2006 21:14
0 comments

ndiswrapper 1.15

This afternoon I emerged the latest version (or at least the latest version available in Gentoo) of ndiswrapper (version 1.15). I figured that since people still seem to find this blog as a result of my trials with the D-Link DWL-G122 Wireless USB Adapter I may as well keep going. Once again there were no issues and ndiswrapper 1.15 worked just fine with the DWL-G122. The process still hasn’t changed since I last wrote about using ndiswrapper.

I’m now using the Linux 2.6.16.x kernel but I didn’t have time to try pulling out the device (without unloading the module) to see if doing so hung the machine like some of the old versions. If I get a chance, I’ll give it a go and update this entry.

Published on Mon, 08 May 2006 01:29
0 comments

Thirty-three Gusting Thirty-nine

I flew up north this morning. Not as far north as Aviatrix is, but well north-west of Calgary. Some people might call it Rocky Mountain House but pilots would likely refer to it as CYRM. It was a long slog up there. A really long slog. The winds aloft were forecast to be 330 at 43 knots and based on our groundspeed of 73 knots, I don’t think that forecast was far off. And I was too busy battling the light to moderate chop to muck around with the GPS to calculate the actual winds.

But the best thing about a consistent headwind is that it becomes a tailwind on the return flight. The same route that was a 1.3 hour flight going there, was a mere 45 minutes on the return. The bad news though is that the winds at Calgary/Springbank (CYBW) had increased from ”20 gusting 30” to ”33 gusting 39”. At 30 degrees off the runway, with some fluxuation, that put me dangerously close to exceeding the aircraft’s maximum crosswind component of 17 knots. And, in fact, the maximum would be exceeded during the gusts.

For students, or even licenced pilots, who are are unaware, don’t understand or simply don’t use the correct crosswind landing technique, the notion of a maximum crosswind component may be lost on them. When a pilot improperly employs the use of crabbing on short final in order to return the aircraft to solid ground, kicking the rudder at the last second to bring the aircraft in line with the runway, a maximum crosswind component doesn’t really exist. Or there’s no need for it to exist. If they kick within the last couple feet the aircraft will drift, but on a reasonably wide runway they can get away with that simply by ensuring that they start the kick with the aircraft on the wind side of the centre line. That way the drift simply brings them inline with the centre of the runway and at the very least they have some room to play with. So in a sense, the maximum crosswind component for a ‘kick’ method landing is really related to the width of the runway because for pilots employing this method, the higher the crosswind, the more they’ll drift.

Ultimately though, as Sam points out in his Slipping and Sliding, Kicking and Screaming post, the crabbing method can be dangerous, not only to the airplane structure but to the crew’s health should a runway excursion occur. But with the proper side slip technique, you bank in the direction of the wind and keep the aircraft aligned with the runway using opposite rudder. Here’s where the maximum crosswind component comes in; you can counter any crosswind using this technique but the higher the crosswind, the more bank required. And at some point, your angle of bank will be such that should you continue this all the way to the ground, your wingtip will contact the ground first. And to overstate the obvious, having your wingtip contact anything but air at anytime is a bad thing, but when that wingtip is the first thing to contact the ground on a landing, well, it’s not likely that things will end very well. It’s impossible to tell from the report as to when during landing this Delta aircraft wing strike happened, but I’d say they were lucky. In any case, the maximum crosswind component should make sense now.

So what did I do for my landing in this extreme crosswind? Although this was my first landing with a crosswinds anywhere close to the maximum crosswind component, I planned to do what I always do: side slip on final to correct for the crosswind. I did, however, request an extended downwind. That way I could ensure I would have a little extra time to stabilize my final approach. Although anticipated the tailwind I’d have on the left base for runway 34, my turn to base and turn to final were still one fluid movement. I then myself up in a side slip for the two mile final, during which I time I was able to monitor frequency of the gusting and how much more slip was required. I maintained the slip all the way to the threshold, at which point, unable to ensure I wouldn’t strike the wingtip, I transitioned to a bit of a combination; a partial crab of no more than perhaps two or three degrees with a slip to offset the rest of the crosswind.

I have so much time on the Warrior (though likely not as much as David so perhaps he can comment) that I am never surprised by the touchdown; it’s like having a built in radar altimeter. That said, I’m not entirely sure that it was the best method and I’m not sure that I would recommend it to anyone else unless they too were intimate with their aircraft. But the plane is home safe and without any undo stresses placed on the aircraft or it’s pilot. What I would recommend, however, to any pilot put into any situation on landing that they aren’t used to, is to setup for a long, stabilized final approach. Forget that rule about turning base when the threshold is 45 degrees off your wing in the circuit (or pattern) and instead ask for an extended downwind and thus an extended final. If it’s good enough for the big boys, I don’t see why us bug smashers shouldn’t use it also.

Published on Tue, 02 May 2006 22:42
1 comment

Blog Moving

I’ve decided to move my blog over to my own personal server. A server that I maintain and control completely. So if you’re reading this then that means you’ve either arrived here directly (ie. via Google) or the Zymeta blog server redirected you over here. That’s a good start. And I’ve changed the RSS feed so it also redirects over to my new blog server; hopefully that works also (and feel free to let me know if it doesn’t).

Thanks to the beauty of Postgresql’s import/export dump features, I’ve also pulled all my old entries and comments over as well. So, for the most part, it’s like I was always right here.

Anyway, the nice thing about being on my own server is that no one can mistake my entries as representing my employer (which certain losers have done). The other great thing about being separated is that I can be more openly critical about whatever I want without the potential ramifications of affecting future clients of my employer. So, for example, I can talk about certain airlines executives as being out of touch with their customers without worrying about said airline not wanting to advertise on our network because of my comments. You get where I’m going with this.

So welcome to the new, old blog site. And please let me know if you encounter issues.

Published on Thu, 27 Apr 2006 14:36
0 comments

Gallery 2.1

I updated to Gallery 2.1 on one of my Gentoo servers last week. And once again the process was amazingly slick. The Gallery developers have gone out of their way to make the process as seemless as possible. It’s not at the stage where my Mum could install it but given that this is a server-based application, it’s about as close as you can get.

I took the lazy route this time and didn’t bother cleaning up the old files and instead simply copied the new set of files overtop of the old ones. I hate doing this because if there’s any kind of problem with permissions, some new files may not get installed. But not to worry with Gallery 2 because the app not only checks the validity of the files when upgrading, it also checks for old files. At that stage of the install, I was presented with a long list of old files and groaned at the thought of having to delete them all. At least until I read this message on the same page:

These files are no longer part of Gallery. They probably won’t cause any problems but it is a good idea to remove them to keep your install clean. Gallery can’t remove these files for you, but you can download and run this script in your gallery2 directory to delete them for you.

And the word “script” was a link to download a nice shell script which removed all the old files for me. Brilliant. And just when I thought the application couldn’t get any better. So if the Gallery development team are doing this, why can’t more app developers? In most cases it comes down to laziness and the cool factor; it’s just not cool or fun to do that kind of stuff.

Published on Mon, 17 Apr 2006 14:46
0 comments

RSS