Building an Optimized Platform


Designing a well-structured, normalized database schema is just half of the optimization puzzle (albeit an important half). The other half is building and fine-tuning the server that will house your database. Think about the four main components of a server: CPU, memory, hard drive, and operating system. Each of these need to be up to speed or no amount of design or programming will make your database faster!

  • CPU The faster the CPU, the faster MySQL will be able to process your data. There's no real secret to this, but a 3.0GHz processor is significantly faster than a 1.0GHz processor. With processor speeds consistently increasing, and with reasonable prices all around, it's not difficult to get a good bang for your buck.

  • Memory Put as much RAM in your machine as you can. You can never have enough, and RAM is cheap these days. Having available RAM can help balance out sluggish CPUs.

  • Hard drive The proper hard drive will be both large enough and fast enough to accommodate your database server and its traffic. An important measurement of hard-drive speed is its seek time, or the amount of time it takes for the drive to spin around and find a specific piece of information. Seek time is measured in milliseconds, and an average disk-seek time is around 8 or 9 milliseconds. When buying a hard drive, make sure it's big enough to accommodate all the data you'll eventually store in your database and fast enough to find it quickly.

  • Operating system If you use an operating system that's a resource hog (for example, Windows), you have two choices: buy enough resources so that it doesn't matter, or use an operating system that doesn't suck away all your resources.

If you put the proper pieces together at the system level, you'll have taken several steps toward overall server optimization.

Using the benchmark() Function

You can perform a quick test of your server speed using the benchmark() MySQL function to see how long it takes to process a given expression. You can make the expression something simple, such as 10+10, or something more extravagant, such as extracting pieces of dates.

No matter the result of the expression, the result of benchmark() will always be 0. The purpose of benchmark() is not to retrieve the result of an expression, but to see how long it takes to repeat the expression for a specific number of times. For example, the following command executes the expression 10+10 one million times:

mysql> select benchmark(1000000,10+10); +--------------------------+ | benchmark(1000000,10+10) | +--------------------------+ |                        0 | +--------------------------+ 1 row in set (0.03 sec)


This command executes the date extraction expression also one million times:

mysql> select benchmark(1000000, extract(year from now())); +----------------------------------------------+ | benchmark(1000000, extract(year from now())) | +----------------------------------------------+ |                                            0 | +----------------------------------------------+ 1 row in set (0.08 sec)


The important number is the time in seconds, which is the elapsed time for the execution of the function; the first test took 0.03 seconds, and the second took 0.08 seconds. You might want to run the same uses of benchmark() multiple times during different parts of day (when your server is under different loads) to get a better idea of how your server is performing.




Sams Teach Yourself PHP, MySQL And Apache All in One
Sams Teach Yourself PHP, MySQL and Apache All in One (3rd Edition)
ISBN: 0672328739
EAN: 2147483647
Year: 2004
Pages: 327

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net