Category Archives: Software

WordPress Performance

In the last month or two, I’ve begun writing some simple plugins for WordPress and I’ve been a little frustrated by one of the application/database design decisions which have been made.

Most web sites consist predominantly of read activity and infrequent write activity. As such, it is in the interest of performance that, where applicable, you store an aggregate value instead of calculating it. This design decision was made correctly by storing the number of comments per post in the wp_posts table. Unfortunately, this technique has not been used for storing the URL for a post. For whatever reason, to get the URL for a particular post you need to call get_permalink() – which through the use of a few other queries derives the URL for the page.

I can understand to some extent why this was done, it makes sure that the URL presented for a post is always the current one. I think the other reason might involve creating a convenient templating language for the public to use with WordPress. As a simple example, consider the lists of posts you see on this site. Instead of requiring a single query to generate these lists, it requires n+1 queries to generate the lists where n is the number of posts you want displayed.

What I don’t understand is why the guid field in the wp_posts table isn’t updated and kept in sync with the post and a users desired permalink structure. Employing a simple mechanism like this would mean generating a list of URL’s would only issue a single query. If this was the case, you’d end up with a scenario where:

  • drafting a post would create a permalink
  • publishing a post would update the permalink
  • changing the publishing date of a post would regenerate the permalink
  • changing the permalink structure would regenerate all permalinks

One other thing which is a little frustrating is that after asking in #wordpress on irc.freenode.net, no one at the time could clarify what the guid field was used for and why it isn’t kept in sync as pointed out above (maybe its a bug?). The other thing which I couldn’t find on the codex, was a good definition of all fields in all tables and what they logically represent. If I happen to run into Matt or Ryan, I’ll be sure to ask them to confirm one way or the other.

IIS Dropping Sessions

You might have noticed that at times, it appears that IIS6 is losing or dropping your ASP.net session information. After looking around under the hood of IIS, there are a couple settings in IIS6 which can affect the consistency of session data.

In case you’re not already aware, IIS has two different mechanisms to handle ASP.net session information:

  • In ProcessWhen using the in process method for session storage, IIS places your session data in the same memory area as the ASP.net worker process which is servicing your site. Since the session information is being stored in the worker process, if your ASP.net application is reset for any reason – the session data is lost at the same time.
  • Out Of ProcessConfigured using out of process means that the session information is stored in a different worker process, either on the same server or on a different server to that running the ASP.net application. As you’d expect, if the ASP.net application is restarted for whatever reason – the session data is not lost. Within this type of session management, there are two physical methods you can choose:
    • IIS State ServiceIIS6 comes with a Windows service which can be used for session storage. You can configure it to run on the same server as your application to support a web gardens (even when you only use a single worker process) or on a different server to support a web farm (though, you could do that with a single server as well if you wanted I believe).
    • SQL Server
    • As with the IIS State service above, utilising SQL Server to store session data can be done locally or on a remote server.

    One point of interest about using out of process storage, is that if you’re storing rich objects and not simple primitives (int/string/float/..) then you’re objects must be serializable.

If your ASP.net site utilises out of process session management, then you really don’t have a lot to worry about. If on the other hand your site utilises the default configuration, which is in process management, then you have some important points to be aware of.

Application Pools

One of the new options within IIS6 is a feature called an application pool. An application pool is a way to isolate a web site or collection of, from other web sites. This isolation is created by each application pool having its own worker processes. Of course, if you’re using in process session management then each application pools session data is also isolated from another.

For convenience, a virtual host in IIS6 can contain as more than one application within it. If you are not aware of the impact of creating applications, then it is very simple for your ASP.net site to be serviced by more than one worker process. Of course, when that happens and a clients request is bounced between multiple worker processes; their session data is ‘lost’ for the first request in each process. From that point onwards, it exists however updating a session object in one process does not update it in the other, leading to inconsistent application execution.

Web Garden

A web garden is a small scale web farm (har har!) which allows multiple worker processes to service a single application pool on the same server. Since each worker process has its own memory for storing session information, you’ll run into issues using a web garden and in process session management at the same time.

Recycling Processes

IIS also provides a convenient way of recycling worker processes systematically. A lot of web hosts will use this feature to cycle processes daily in the early hours of the morning to keep the memory use of each worker process to a minimum. Of course, if you’re application is using in process management – this feature would destroy any active session data being stored. This might seem trivial, however it would be extremely frustrating to have a worker process automatically cycle while you were half way through filling up your online shopping cart.

Simple Solutions

If you happen to have multiple applications running within a single site, you can force each application to use the same application pool. By doing so, each application will be served by the same worker process (assuming you are not using a web garden) and thus all of your applications can share session information seamlessly.

If you’re using a web garden at the moment and you’re application doesn’t receive enough load to require the other worker processes, reducing it back to a single process will stop you ‘losing’ session information. If you require the other worker processes, then you don’t have a choice but to use an out of process storage mechanism. If you don’t want to use the state server or SQL Server, you could alternatively roll your own as well.

Unfortunately, if you’re using in process session storage you don’t have a leg to stand on when a worker process is recycled. If you are using any out of process mechanism, either the two listed above or your own custom version – you should find that your session information is perfectly safe whilst cycling processes.

Happy session management!

WordPress Plugin: Hicksdesign Style Archives

The Hicksdesign Style Archives plugin now has a permanent URL.

Looking for a better way of displaying your blog archive list than a list of links to your monthly archive pages? There are many ways to display an archive list of posts, most common is a series of links to your ‘monthly archive’ pages. While perfectly functional, it just wasn’t working for me.

After looking around, I really liked the way that Jon Hicks displays his blog archive list. Using Jon’s method gives a little more substance to an otherwise fairly sparse page and the post titles break up the page nicely with their varying length.

Usage

  1. Download arl_hicksdesign_archives.zip
  2. Unzip the file locally
  3. Upload arl_hicksdesign_archives.php into your plugins folder (normally: /wp-content/plugins/)
  4. Enable the plugin via your administration console
  5. Edit your appropriate WordPress template file and add a call to arl_hicksdesign_archives()

Download

Zip: arl_hicksdesign_archives.zip
Source: arl_hicksdesign_archives.phps

ChangeSet

  • 2006-05-01:
    • Implemented get_permalink() to fix bug
    • Implemented get_month_link() to fix potential bug
  • 2006-04-29: Fixed spelling mistake in plugin name, arl_hicksdesign_archives().
  • 2006-04-26: Initial release.

Upcoming WordPress Plugin Releases

Quite regularly I attempt to do something in WordPress, which I can’t find a simple way to achieve through the use of the Templating Tags. When this happens, I usually whip up a very simple plugin – which in most cases is just a simple function I can then reuse somewhere else.

In the coming days, I’ll be releasing some of the plugins I’ve written. A few of them had previously been written, however I reinvented the wheel so I could gain an understanding of how the WordPress works on the inside.

Currently slated for release:

The plugins should be considered in beta, as I spent as little time on them as required to get the job done. That being said, they are enabed and have been running here error free for quite some time.