11 tips on reducing CPU usage on your Windows serverposted on 8 January 2008 | posted in Hosting General
This is far from an exhaustive list, but it should act as a good "to do" list when checking over your websites / server.
Websites1. Cache everything that can be cached. This was discussed in detail in the Database-driven websites and caching article - don't render your pages via database calls if you don't need to. Caching is probably the best tip out of the lot and will greatly reduce CPU usage.
2. When you use SQL, use LIMIT when possible. If you just need 5 records from a query, say so : SELECT ProductName FROM Products WHERE CatID=1 LIMIT 5;
3. Avoid using * in your SQL queries. Be explicit. For example, don't use : SELECT * FROM Products;. DO use: SELECT Product ID, ProductName FROM Products;
4. Try to avoid ORDER BY if you can - not always possible, but it's a bad habit to use it for non-display purposes (when you're looking up to see if records exist for example)
5. For ASP, try to put your code in blocks, rather than completely mix it up with HTML. Not always possible but bear this in mind when creating pages.
6. Avoid large loops / nested loops - this really ties up the CPU and you can normally find alternative ways to achieving the same goals.
7. Always use INSERT when adding records. Sounds obvious, but some developers still use recordset.Update command which truly impacts on the CPU when your table has even just hundreds of thousands of records.
IIS8. Switch off logging. Logging switched on means constant appending of text files on your server that details everything about the visitors accessing your sites. Necessary if you're monitoring bandwidth though. My tip is to monitor bandwidth periodically - so switch on logging for a week out of 3 months, just to keep an eye on sites and the bandwidth they use, then switch off logging at all other times. There's no need to keep it on permanently, unless you do want to monitor bandwidth 365 days a year.
Anti-virus10. Use Nod32 - end of story. It's light, it's effective, it's up-to-date. Everything else I've tried is heavy and CPU intensive.
SSL11. SSL is absolutely necessary for sensitive areas of your websites, but don't go overboard with SSL. Encryption uses up a lot of CPU. I've seen entire websites secured with SSL when it's entirely unnecessary - secure what needs securing and put the rest outside of https://.