| All About Speed - Part 2 (Generation Time) |
| Written by ircmaxell | |
| Tuesday, 24 April 2007 | |
|
In the second installment of this multi part series, I am going to talk about another extremely important topic when it comes to website performance. As you can probably infer from the title, that topic is generation time. Notice I said generation time, and not load time. There is a VERY important difference between them. Load time is the time it takes from when a user makes a request until the page is completely loaded (including all associated graphics and rendering). Generation time (by my definition) is the time from when the server receives the request, until the first useful piece of content is sent.
Why the first piece of useful content?Well, this is simple. If you have ever downloaded a large PDF or streamed content from sites such as Youtube, you notice that you are viewing SOMETHING long before that download is ever completed. That's what you want. You want your users to WANT to wait for the page to finish loading. Personally, if a page takes longer than 5 seconds to load, I more than likely will never come back to that site, yet alone keep clicking. No matter HOW good the content is. If a page lets me start looking within a second or so, I'm MUCH more inclined to stick around. Don't forget that generation time is just a part of the time it takes before a user sees useful content. With that in mind, keep generation time as low as possible, and ALWAYS UNDER one second. So how do I minimize generation time?This is not that simple. Since there are so many factors that affect generation time, trying to optimize it can be daunting. The first thing you can do is reduce your code. If there is anything that you don't need, don't run it! That is true on all sides of generation. In apache, limit what modules you load to what you need. The less modules, the more memory efficient, and less CPU time you need to get the request to PHP. In your PHP files, you'll want to streamline your code. Avoid the use of CPU intensive functions like REGEX functions unless you need them. In a CMS like Joomla, disable any mambots you don't NEED. You'll want to optimize your SQL queries to the best that you can. Also, try to minimize the database queries that you make, especially if your database server does not reside on the same physical machine. Supposed that there is a 20 millisecond network latency between your server and the database server. That adds 2 seconds to the time it takes to make the page with 100 queries! Don't compensate for poor code with hardware...So your site loads slow right now. You think that you need a dedicated server to speed it up. YOU DON'T! It's that simple. Match your hardware to your load, NOT to your generation time. To upgrade to a dual Xeon server because your pages take 4 seconds to load on that Celeron is nothing short of a waste of money. Poor code will run poorly no matter what hardware you put it on! Optimize your code so that it loads fast on that Celeron (or shared host for that matter), and upgrade to the dual Xeon when your demand requires it! You can do a lot with a little bit of processing power. And don't let a host tell you that you need a dedicated server because your site is using too many resources. Unless you are averaging 2,000 visitors a day, all that means is that either you need to refine your code, or they are severely overselling their servers. I've said it a few times already, but I will say it again, DON'T TRY TO COMPENSATE FOR POOR CODE. With that being said, there are a few ways around hiring a consultant to come in and speed up your site. A couple of cost effective methods.Ok, you've dug through your code to the best of your abilities, and optimized it as far as you can. If your site is still slow, there are a few things you can do. The first is install a byte code cacher like eAccelerator or APC. Both of them store the compiled version of a PHP file in memory, which saves the time it would take for the server to compile the code. While this is not a GREAT savings, it can be dramatic. You can save between 5% and 25% off load times depending on your code. The downside to this is two fold. First, you must have root level access to the server to compile in the cacher. The second problem is that they use memory. And lots of it! The average Joomla configuration will consume about 15 megs of ram. PER APACHE CHILD. One Apache child can serve one request at a time. You can see how this will quickly limit the amount of traffic you can receive. The other alternative it install a page cacher, such as my Joomla component. By storing generated pages between requests, these programs can cut down page load times by over 90% or more. Don't forget that you don't want to put a band aid on a broken bone, but if all else fails, these methods do work. Think outside the boxOne thing you can always do is push the generic Apache aside for a leaner, meaner server such as Lighttpd (pronounced Lite-e). This very server runs on a mix of Apache and Lighttpd. I use Lighttpd to mindlessly push out all my static content (such as images and css...) LIGHTNING fast, while leaving Apache to worry about the hard dynamic content. You can read more about Lighttpd in my article "Lighttpd, The Fast Apache...". Just remember, your site will only ever give you back what you put into it. If you take the time to optimize your code and your server, it'll do much better (and cost MUCH less) in the long run. Don't be afraid to try something new. Just remember to make a backup first in case it doesn't work out. Google would not be where it is today if a couple of college students decided that they couldn't make search engine code both fast and accurate. The bottom line? You want your server to spit your files out as fast as possible to give time for the other factors that affect the speed of a website. Stay tuned for next weeks article about optimizing your markup. All About Speed - Part 1 (Bandwidth Demystified) All About Speed - Part 3 (HTML) Trackback(0)
Comments (0)
![]() Write comment
|
|
| Last Updated ( Thursday, 10 May 2007 ) |
| < Prev | Next > |
|---|











