< Day Day Up > |
Stored ProceduresAs part of your previous optimization work, described in Chapter 19, you suggested that High-Hat move toward centralizing its business logic in server-based, stored procedures. You felt that this would produce higher-quality applications, especially given the frenetic turnover and related lack of development discipline in the airline's IT department. High-Hat took your advice and began converting significant portions of client-side application code into server-side, stored procedures. Almost immediately, the inconsistencies that had plagued their applications and data became much rarer. However, first developers and then users began noticing performance degradation for several of the applications that employ these new stored procedures, as well as some other applications that do not. DiagnosisDeciphering an apparent stored procedure performance problem is often far simpler than tackling a server configuration problem. All that is necessary is to look at the stored procedure code, along with any SQL invoked from the procedure; the EXPLAIN command helps with that task as well. Stored procedures are discussed in Chapter 9, "Developing High-Speed Applications." ObservationsMany of the stored procedures that you evaluate appear normal. However, several other procedures seem to follow the same design pattern. They typically
SolutionSeveral performance and concurrency problems exist with this stored procedure design pattern. You present your recommendations in the following two categories. TransactionsThe preceding example, as well as the other procedures, appears to be not particularly sensitive to minor data alterations. Despite this indifference, the transaction isolation level is set to a superstrict value of SERIALIZABLE. Recall from Chapter 9 that this isolation level effectively blocks other processes from altering any rows that have been evaluated during the course of this transaction, regardless of whether these rows have even been changed. Given the large number of rows spread across multiple tables, there is a good chance that this procedure is negatively impacting users throughout the system. In addition, this procedure's demanding isolation level means that it will likely run into obstacles and be forced to wait for other operations to finish. For this kind of transaction, the default isolation level of REPEATABLE READ would suffice. In fact, an even less restrictive isolation level would probably be fine. It can also be argued that the transaction should not even start until immediately before the INSERT statement. In this case, any less-restrictive isolation level change will likely yield a better-performing procedure that treads more lightly on other users and processes. Processing OptionsBy failing to use basic joins and built-in functions, the authors of these procedures have been forced to reinvent the wheel. Aside from the waste of valuable development time, it's likely that their implementations will not be as speedy as the MySQL query engine and library of functions. You recommend that this group of stored procedures be rewritten to leverage the power of SQL and functions such as AVG(), freeing the developers to focus on application logic. |
< Day Day Up > |
No comments:
Post a Comment