对你的应用程序和数据库进行基准测试,以找出瓶颈所在。在修复一个瓶颈(或将其替换为“虚拟”模块)后,你可以继续识别下一个瓶颈。即使你的应用程序目前整体性能可以接受,你也至少应该为每个瓶颈制定计划,并决定如果将来确实需要额外性能时如何解决它。Benchmark your application and database to find out where the bottlenecks are. After fixing one bottleneck (or by replacing it with a “dummy” module), you can proceed to identify the next bottleneck. Even if the overall performance for your application currently is acceptable, you should at least make a plan for each bottleneck and decide how to solve it if someday you really need the extra performance.
一个免费的基准测试套件是开源数据库基准测试,可在 http://osdb.sourceforge.net/ 获取。A free benchmark suite is the Open Source Database Benchmark, available at http://osdb.sourceforge.net/.
问题通常只在系统负载非常高时才会出现,这是很常见的。我们有许多客户在生产中使用经过测试的系统时遇到负载问题后联系我们。在大多数情况下,性能问题最终被发现是由于基本数据库设计的问题(例如,在高负载下表扫描表现不佳)或者操作系统或库的问题。大多数时候,如果系统尚未投入生产,这些问题会更容易解决。It is very common for a problem to occur only when the system is very heavily loaded. We have had many customers who contact us when they have a (tested) system in production and have encountered load problems. In most cases, performance problems turn out to be due to issues of basic database design (for example, table scans are not good under high load) or problems with the operating system or libraries. Most of the time, these problems would be much easier to fix if the systems were not already in production.
为了避免此类问题,请在最坏的负载情况下对整个应用程序进行基准测试:To avoid problems like this, benchmark your whole application under the worst possible load:
mysqlslap 程序对于模拟由多个客户端同时发出查询产生的高负载可能非常有用。请参阅 第 6.5.7 节,“mysqlslap — 负载模拟客户端”。The mysqlslap program can be helpful for simulating a high load produced by multiple clients issuing queries simultaneously. See Section 6.5.7, “mysqlslap — A Load Emulation Client”.
你也可以尝试使用基准测试软件包,例如 SysBench 和 DBT2,可在 https://launchpad.net/sysbench 和 http://osdldbt.sourceforge.net/#dbt2 获取。You can also try benchmarking packages such as SysBench and DBT2, available at https://launchpad.net/sysbench, and http://osdldbt.sourceforge.net/#dbt2.
这些程序或软件包可能会使系统不堪重负,因此务必仅在开发系统上使用它们。These programs or packages can bring a system to its knees, so be sure to use them only on your development systems.