litheon

Discussion on all things college and technology.

October 2007 - Posts

Increasing web server performance

So over the past week or so the site has been dealing with quite a few problems regarding performance, especially around that of average CPU utilization. Throughout the process I found quite a bit of documentation regarding increasing performance in IIS. So in no particular order here are a few of the changes that had major corresponding increases in performance and decrease in CPU utilization. With the steps listed below we've been able to hammer out some of the most frustrating performance problems, and optimize the site's performance enough that we no longer need to babysit the server during high load and especially when we reach the front page of digg.

1. Code optimization

  • Code optimization is probably the most important aspect of insuring top-notch performance, and also the hardest to give guidance about fixing as the code for every application varies and the way it executes on each individual server can vary just as much. The most important aspects of code optimization is reducing memory usage whenever possible, reducing the number of CPU intensive processes, and caching the results of frequently-run database queries.

2. Caching

  • Cache anything and everything that can be cached. When there are many parts of a page that are generated dynamically it can be very difficult to effectively cache data while still showing website visitors fresh content. This can be very difficult to accomplish, especially with certain application-specific caching frameworks such as WP-Cache. In ASP.NET the use of the Cache and Application objects makes it immensely simple to cache data, and not even need to worry about checking the freshness of the content because you can easily specify how the object should expire in the cache which will cause your code to re-create that entry using fresh data. PHP can also incorporate the same functionality through the use of Memcache.

3. HTTP headers

  • Another way to extend the reach of caching it ensuring your web server sends headers that tell the browser it doesn't need to update the same static files consistently. For IIS this does prove to be slightly difficult as you can not actually specify which specific types of files have the expires header set, which will cause the client browser to request the file if it was modified which doesn't necessarily add as much load as requesting the file out right. In order to circumvent this in IIS you can set the expiration on these files by setting the header status on the folder containing them (as the majority of static files you're probably going to be loading are in some sort of theme file). With Apache it is far more customizable using mod_expires, which allows you to specify a default and then specify the expiration based on the MIME type.

4. Multi-Threading

  • Quite a few modern web servers also have the capability of creating multiple execution threads and worker processes dynamically based on the load. Apache accomplishes this via the Multi-Processing Modules which gives you control over the number of threads created per worker process and the number of worker processes, while IIS allows you to specify the maximum number of worker processes that can be created. One thing to note about the IIS worker processes is that each specific worker process has its memory isolated from the others, so items added to the Cache on that worker process will only be accessible from pages that worker process handles.

5. Dynamic load management

  • Another good idea to ensure performance is disabling certain functionality during times of high load. Probably the easiest way to accomplish this would be to use some form of "Who is online" functionality if the software powering your website supports it. Some of the functionality that should be disabled includes anything that is heavy in database queries, and functionality that requires significantly more markup and as such requires more processing on the server-side. Disabling functionality like this also gives you the opportunity to disable caching of anything required to use whatever functionality you have disabled, effectively giving you additional memory to cache other, more important, elements of the page.

6. HTTP Keep-alives

  • Using HTTP Keep-alives is another way of maintaining adequate performance by using a single connection to the server for all of the elements on the page, and subsequent pages a client may navigate to. This reduces performance overhead by only necessitating that one connection as opposed to a single connection to the server for every element that needs to be requested from the server.

7. Gzip compression

  • Gzip compression can reduce the amount of time a client is actively communicating with the server, and as such reduces the performance overhead caused by the underlying TCP/IP protocol. The less time a client is communicating with the server the more time is available for other clients to communicate without having to be placed into a hold queue. It should however be noted that compressing anything does have a certain amount of CPU overhead in itself so it would be worth your time to try and balance CPU utilization versus the time required for the communication to complete. Unfortunately compression can only be configured at the server on Apache and IIS, and virtual host level on Apache. So if you're not using a VPS or a dedicated server it would be worth contacting your host to inquire about enabling that functionality if it is not already. Apache uses mod_deflate to facilitate gzip compression, while IIS allows you to edit the properties of "Web Sites" and enable HTTP compression on the "Service" tab.

8. Database optimization

  • Optimizing your databases is another huge step in ensuring good performance. Although most of the popular content management software out there already does a great deal of optimizing database schema, if you are developing your own application or adding additional functionality that requires your own database interface you should make sure you always create an index or primary key on a table that has a large quantity of data; especially if it is accessed relatively frequently. If you're using MySQL the storage engine chosen also plays a large part in the performance of the database server software, and as a result can positively or negatively affect the speed of your website.

Overall the issue of performance really doesn't have a single solution and can be the single most frustrating aspect of developing and running a website. Even with the most optimized code and databases, and with the most optimally tweaked settings it can be an insurmountable task to find the right combination of configuration options, hacks, plugins, and frameworks to achieve the best performance possible. However, with the steps listed here (and the steps on some of the websites listed below) obtaining at least adequate performance out of your website is a goal that can easily be within reach.

Links:

 

Do you like free stuff?

Thanks to Tony Hynes, John Porcaro, Tom Eberspecher, and all of the other folks over at the GamerScoreBlog I have quite a few codes for Xbox Live Arcade games that have built up in my Inbox. I would use them, but really the only arcade game I play is Geometry Wars. So instead I figured I would give them out to the folks on Xbox Live.

So here's how it works, if you're a registered user (here or at MajorNelson.com) login and post a comment here. If you would only like to win certain arcade games post them in your comment. If you're not registered make sure you set your name to your gamertag AND include your gamertag in your post, and if you only want to with certain arcade games include that in your comment.

Also, I've got two Xbox Live one year subscription codes that I will enter everbody who enters (even if you win an arcade game).

Some general guidelines:

  • Do not attempt to enter more than once, if you do enter more than once you will be disqualified for this and any other giveaways I might do
  • Register if at all possible, if I have any question as to whether or not you've tried to enter more than once this will make it very easy for me to determine you are innocent
  • You can only win one game

The arcade games:

  • Roboblitz
  • New Rally X
  • Castlevania
  • Jetpac
  • Luxor 2
  • Catan
  • Double Dragon
  • Xevious
  • Rush'n Attack
  • Super Contra
  • Spyglass Boardgames
  • Hexic 2
  • Cyberball
  • Fatal Fury
  • Tetris Splash
  • E4

Good luck!

Posted: Oct 25 2007, 06:17 PM by litheon | with 70 comment(s) |
Filed under: ,
What's up with the site today?

As I'm sure you've noticed the uptime for the site today was more or less on and off, rather than steadily up. The main reason behind the uptime and the frequent display of the "Under maintenance" error is due to some unforseen performance issues with the back-end code to facilitate interfacing with Xbox Live's gamercard and presence information via the XCDP feed. As a result of this, I've been doing tweaks to code and caching configurations all day and running performance counters among some other tracing tools to try and isolate the source of the problem.

It turns out the underlying cause of the problem was due to the way Visual Studio sets up the code when dealing with tables containing relationships within a DataSet designed with the DataSet designer. Even if I'm not using the methods Visual Studio creates for me to get the data in a related row the code still gets the row. Normally this wouldn't be a problem; however, the data retreived in this way is not ever cached meaning that upon every request for a particular gamertag's presence or their played games caused the intended request I wrote within the code and then the code that is part of the DataSet to request the same rows. Normally I only request five rows since that is the number present within a gamercard, but this dataset would request every single row.

Anyway the problem is fixed now, and games will soon be back in gamercards. Thanks for being patient even during the slowness.

What do you look for in a blog theme?

I've been working on a new blog theme for MajorNelson.com for the past few months now and upon reviewing comments regarding it I'm fairly convinced that it needs a bit of work. Despite the attempts at a simple, yet pleasing presentation, it seems the theme has some issues. Namely it doesn't support some standards for user-accessibility, and well-formed markup. So there will be some changes in the conventions used for design; although it will be staying with tables, because, even though semantically tables shouldn't be used for anything but data, it still makes sense to use them since not all browsers easily support some of the CSS that would be required to using div tags as floating elements. In addition the the convention changes the theme itself will be compliant with CSS standards and markup standards, among some other tweaks to the rounding of corners and the reflection employed by certain parts of the theme.

So I'm looking for some criticism regarding the theme, specifically about the following:

  • What do you think of the navigation area at the top of the page? Does trading the sleakness of the current design to that of a more easily navigable one make sense?
  • What do you think of the link colors? Should the ones in content areas be changed based on what the link is in regard to?
  • Do the rounded corners look good or does it just look like there's just too much of an attempt at creating a Web 2.0 look?
  • Even if you use the sidebar collapse link on the top of the right side does it seem like there isn't enough space horizontally? (Especially when viewing a post's comments)
  • Do the posts seem to run together? Should there be more differentiation between them?
  • How do you think anonymous comments should be dealt with? Should they be hidden by default?
  • Is there anything else you don't like about the theme? Colors too bright or repeated too much?

The theme is a work in progress, and it's something that will be in-use for quite a while until the next itteration of a theme so any feedback you provide to improve the theme will better serve you when viewing the site. Also, any feature requests you may have would be appreciated as well. Once this theme is finished there is a high probability that in the future you will be able to reorganize items on the left and, assuming you choose to display it, the right columns using some of the amazing code available from brothercake.

Welcome to the new blog!

I would like to personally welcome you to litheon.com. I've made numerous attempts at blogging in the past using Windows Live spaces but I've finally rested here thanks to the coincidental checking of the availability of this domain and folks at CentraComm making this happen as smooth as it did. I'm still new to blogging, so please excuse me while I get used to the controls.

About me: I'm James, although go by the pseudonym litheon and have used that for just about every online handle I can think of since the new Xbox.com Forums launched. I've been a Microsoft Xbox MVP since October of 2004, and have worked on a wide variety of web-related projects over the past few years. Currently I do most of the "behind-the-scenes" work on MajorNelson.com, and of course here as well. Presently, I am a freshman at the University of Colorado at Boulder.

What I'll be blogging about: I'll be blogging about just about anything that interests, and is relevant to who I am and what I do. So you will likely see a wide variety of posts related to video games (although most prominently the Xbox 360), information technology in general (especially the work I do on MajorNelson.com), music, photography, and probably the occasional post that is related to absolutely nothing of that sort.

Also you might (or might not) have noticed (or at least will if you take a look at the comments) that this site is integrated just as MajorNelson.com is integrated with some features of Xbox Live. You might also notice that you can login here with the same credentials that you use on MajorNelson.com and post using the same Gamertag. In the next few days you won't even need to worry about logging in at both sites.
That's really about it, enjoy the site and if you have any questions feel free to private message me or shoot me an email at jp@mvps.org.

Posted: Oct 19 2007, 07:13 PM by litheon | with 8 comment(s) |
Filed under: , ,