Q8.1: Sybase SQL Server Performance and Tuning


All Components Affect Response Time & Throughput

We often think that high performance is defined as a fast data server, but the picture is not that simple. Performance is determined by all these factors: Unlike some products which aim at performance on paper, Sybase aims at solving the multi-dimensional problem of delivering high performance for real applications.

OBJECTIVES

To gain an overview of important considerations and alternatives for the design, development, and implementation of high performance systems in the Sybase client/server environment. The issues we will address are:

Client Application and Physical Database Design design decisions will account for over 80% of your system's "tuneable" performance so ... plan your project resources accordingly !

It is highly recommended that every project include individuals who have taken Sybase Education's Performance and Tuning course. This 5-day course provides the hands-on experience essential for success.

Client Application Issues

Tuning Transact-SQL Queries

Locking and Concurrency

ANSI Changes Affecting Concurrency

Application Deadlocking

Prior to SQL Server 10 cursors, many developers simulated cursors by using two or more connections (dbproc's) and divided the processing between them. Often, this meant one connection had a SELECT open while "positioned" UPDATEs and DELETEs were issued on the other connection. The approach inevitably leads to the following problem:
  1. Connection A holds a share lock on page X (remember "Rows Pending" on SQL Server leave a share lock on the "current" page).
  2. Connection B requests an exclusive lock on the same page X and waits...
  3. The APPLICATION waits for connection B to succeed before invoking whatever logic will remove the share lock (perhaps dbnextrow). Of course, that never happens ...
Since Connection A never requests a lock which Connection B holds, this is NOT a true server-side deadlock. It's really an "application" deadlock !

Design Alternatives

  1. Buffer additional rows in the client that are "nonupdateable". This forces the shared lock onto a page on which the application will not request an exclusive lock.
  2. Re-code these modules with CT-Library cursors (aka. server-side cursors). These cursors avoid this problem by disassociating command structures from connection structures.
  3. Re-code these modules with DB-Library cursors (aka. client-side cursors). These cursors avoid this problem through buffering techniques and re-issuing of SELECTs. Because of the re-issuing of SELECTs, these cursors are not recommended for high transaction sites !

Optimizing Cursors with v10.0

Special Issues for Batch Applications

SQL Server was not designed as a batch subsystem! It was designed as an RBDMS for large multi-user applications. Designers of batch-oriented applications should consider the following design alternatives to maximize performance :

Design Alternatives :

Asynchronous Queries

Many, if not most, applications and 3rd Party tools are coded to send queries with the DB-Library call dbsqlexec( ) which is a synchronous call ! It sends a query and then waits for a response from SQL Server that the query has completed !

Designing your applications for asynchronous queries provides many benefits:

  1. A "Cooperative" multi-tasking application design under Windows will allow users to run other Windows applications while your long queries are processed !
  2. Provides design opportunities to parallize work across multiple SQL Server connections.

Implementation Choices:

Generating Sequential Numbers

Many applications use unique sequentially increasing numbers, often as primary keys. While there are good benefits to this approach, generating these keys can be a serious contention point if not careful. For a complete discussion of the alternatives, download Malcolm Colton's White Paper on Sequential Keys from the SQL Server Library of our OpenLine forum on Compuserve.

The two best alternatives are outlined below.

  1. "Primary Key" Table Storing Last Key Assigned
  2. IDENTITY Columns (v10.0 only)

    Other Application Issues

    Physical Database Design Issues

    Normalized -vs- Denormalized

  3. There Are Some Good Reasons to Denormalize
    1. All queries require access to the "full" set of joined data.
    2. Majority of applications scan entire tables doing joins.
    3. Computational complexity of derived columns require storage for SELECTs
    4. Others ...

    Index Selection

    Promote "Update-in-Place" Design

    Promote Parallel I/O Opportunities

    Networking Issues

    Choice of Transport Stacks for PCs

    Variable-sized TDS Packets

    Pre-v4.6 TDS Does Not Optimize Network Performance Current SQL Server TDS packet size limited to 512 bytes while network frame sizes are significantly larger (1508 bytes on Ethernet and 4120 bytes on Token Ring).
    The specific protocol may have other limitations!
    For example:

    TCP/IP Packet Batching

    Operating System Issues

    Hardware Configuration Issues

    General SQL Server Tuning

    Audit Performance Tuning for v10.0