Read Oracle Essentials Oracle Database 11g Online
Authors: Rick Greenwald
The remainder of this chapter examines many of these features in more depth.
Architectures for OLTP
Although all OLTP systems are oriented toward the same goals, there are several different underlying system architectures that you can use for the deployment of OLTP, including the traditional two-tier model, a three-tier model, and a centralized model that encompasses the use of the Web and the grid.
Traditional Two-Tier Client/Server
The late 1980s saw the rise of two-tier client/server applications. In this configuration, PCs acted as clients accessing a separate database server over a network. The client ran both the GUI and the application logic, giving rise to the term
fat clients
.
The database server processed SQL statements and returned the requested results back to the clients. While database servers were relatively simple to develop using visual tools, client/server systems were difficult to deploy and maintain—they required fairly high-bandwidth networks and the installation and regular upgrading of specific client software on every user’s PC.
Figure 9-1 illustrates the two-tier architecture.
206
|
Chapter 9: Oracle and Transaction Processing
SQL
Oracle
Oracle
Instance
Database
Data
Client
Database
-GUI
-Data
-Application logic
-SQL
Figure 9-1. Two-tier client/server architecture
Stored Procedures
Oracle7 introduced stored procedures written in PL/SQL, Oracle’s proprietary language for writing application logic. These procedures are stored in the database and executed by clients issuing remote procedure calls (RPCs) as opposed to executing SQL statements. Instead of issuing multiple SQL calls, occasionally with intermediate logic to accomplish a task, the client issues one procedure call, passing in the required parameters. The database executes all the required SQL and logic using the parameters it receives.
Stored procedures can also shield the client logic from internal changes to the data structures or program logic. As long as the parameters the client passed in and received back don’t change, no changes are required in the client software. Stored procedures move a portion of the application logic from the client to the database server. By doing so, stored procedures can reduce the network traffic considerably.
This capability increases the scalability of two-tier systems.
Figure 9-2
illustrates a two-tier system with stored procedures.
Procedure Calls
Oracle
Oracle
Instance
Database
Return Parameters
Client
Database
-GUI
-Data
-Application logic
-SQL
-Program logic
Figure 9-2. Two-tier system with stored procedures
Architectures for OLTP
|
207
Three-Tier Systems
The OLTP systems with the largest user populations and transaction throughput are typically deployed using a three-tier architecture. In the past, the three-tier architecture involved a transaction processing monitor, but now more frequently uses an application server. Clients access a transaction processing (TP) monitor or application server in the middle tier that, in turn, accesses a database server on the backend.
The notion of a TP monitor dates back to the original mainframe OLTP systems. Of course, in the mainframe environment all logic ran on one machine. In an open system environment, application servers typically run on a separate machine (or machines), adding a middle tier between clients and the database server.
There are various classes of application servers:
• Older, proprietary servers such as Tuxedo from BEA Systems on Unix and Windows, or CICS from IBM on mainframes
• Industry-standard application servers based on Java 2 Enterprise Edition (J2EE)
• The Microsoft .NET application server environment as part of the Windows operating systems for servers, for example, Windows 2000 or Windows 2003
Application servers provide an environment for running services that clients call. The clients don’t interact directly with the database server. Some examples of calling services provided by a TP monitor on a remote machine seem similar in many ways to the stored procedure architecture described in the previous section, which is why stored procedure-based systems are sometimes referred to as “TP-Lite.” Application servers provide additional valuable services, such as:
Funneling
Like Oracle’s shared servers, application servers leverage a pool of shared services across a larger user population. Instead of each user connecting directly to the database, the client calls a service running under the TP monitor or application server’s control. The application servers invoke one of its services; the service interacts with the database.
Connection pooling
The application server maintains a pool of shared, persistent database connections used to interact with the database on behalf of clients in handling their requests. This technique avoids the overhead of individual sessions for each client.
Load-balancing
Client requests are balanced across the multiple shared servers executing on one or more physical machines. The application servers can direct client service calls to the least-loaded server and can spawn additional shared servers as needed.
208
|
Chapter 9: Oracle and Transaction Processing
Fault-tolerance
The application server acts as a transaction manager; the monitor performs the commit or rollback of the transaction.* The underlying database becomes a resource manager, but doesn’t control the transaction. If the database server fails while executing some transaction, the application server can resubmit the transaction to a surviving database server, as control of the transaction lies with the application server.
This type of transaction resiliency is a hallmark of the older TP monitors such as Tuxedo, and the newer application servers and standards offer similar features.
Transaction routing
The logic in the middle tier can direct transactions to specific database servers, increasing scalability.
Heterogeneous transactions
Application servers can manage transactions across multiple heterogeneous database servers—for example, a transaction that updates data in Oracle and DB2.
While developing three-tier OLTP systems is complex and requires specialized skills, the benefits are substantial. Systems that use application servers provide higher scalability, availability, and flexibility than the simpler two-tier systems. Determining which architecture is appropriate for an OLTP system requires (among other things) careful evaluation and consideration of costs, available skills, workload profiles, scalability requirements, and availability requirements.
Figure 9-3 illustrates a three-tier system using an application server.
Application Servers and Web Servers
The middle tier of web-based systems is usually an application server and/or a web server. These servers provide similar services to the application server previously described, but are more web-centric, dealing with HTTP, HTML, CGI, and Java.
J2EE and .NET application servers have evolved a great deal in the last decade and are the clear inheritors of the TP monitor legacy for today’s
N
-tier systems. Different companies have different standards and preferences—the proprietary nature of .NET
leads some firms to J2EE, while others prefer the tight integration of Microsoft’s offerings. A detailed discussion of the relative merits of J2EE and .NET, and application server technology in general, is beyond the scope of this book. Suffice to say that application servers play an extremely important role in today’s systems environment, and database management personnel need to understand
N
-tier systems architecture.
* TP monitors usually control transactions using the X/Open Distributed Transaction Processing standard published by the X/Open standards body. A database that supports the XA interface can function as a resource manager under control of a TP monitor, which acts as a transaction manager.
Architectures for OLTP
|
209
Service Calls
Service
Service
Application
Service
Oracle
Oracle
Server
Instance
Database
Service
Service
Client
Application Server
Database
-GUI
-Services logic
-Data
-Funneling
-SQL
-Load-balancing
-Transaction control
Figure 9-3. Three-tier architecture
Figure 9-4
depicts an
N
-tier system with a client, web server, application server, and DBMS server.
HTTP(s)
HTTP(s)
JDBC
Web Server
Application
Oracle Database
Server
Server
J2EE Application
J2EE Application
Browser
Server Proxy
Server
Figure 9-4. An N-tier system
The Grid
Oracle Database 10
g
introduced focus on another architecture variation, grid computing. The actual topology of the grid is not relevant to the discussion in this chapter, because the point of the grid is to provide an extremely simple user interface that transparently connects to a highly flexible source of computing power.
210
|
Chapter 9: Oracle and Transaction Processing
In this way, the grid gives IT departments the ability to achieve the benefits of more complex architectures while not imposing undue complexity on users, and OLTP
applications are deployed using grid computing resources.
Oracle Features for OLTP
Oracle has many features that contribute to OLTP performance, reliability, scalability, and availability. This section presents the basic attributes of many of these features. This section is by no means exhaustive; it’s only intended to be an introduction. Please see the relevant Oracle documentation and third-party books for more information.
General Concurrency and Performance
As discussed in
Chapter 8,
Oracle has excellent support for concurrency and performance in OLTP systems. Some of the key features relevant to OLTP are as follows:
Nonescalating row-level locking
Oracle locks only the rows a transaction works on and never escalates these locks to page-level or table-level locks. In some databases, which escalate row locks to page locks when enough rows have been locked on a page, contention can result from false lock contention when users want to work on unlocked rows but contend for locks that have escalated to higher granularity levels.
Multiversion read consistency
Oracle provides statement-level and transaction-level data consistency without requiring read locks. A query is guaranteed to see only the data that was committed at the time the query started. The changes made by transactions that were in-flight but uncommitted at the time the query started won’t be visible.
Transactions that began after the query started and were committed before the query finishes also won’t be seen by the query. Oracle uses rollback segments to reproduce data as it existed at the time the query started. This capability avoids the unpleasant choice between allowing queries to see uncommitted data (known as dirty reads) or having readers block writers (and vice versa). It also provides a consistent snapshot view of data at a single point in time.
Shared SQL
The parsing of a SQL statement is fairly CPU-intensive. Oracle caches parsed and optimized SQL statements in the shared SQL area within the shared pool. If another user executes a SQL statement that is cached, the parse and optimize overhead is avoided. The statements must be identical to be reused; no extra spaces, line feeds, or differences in capitalization are allowed. OLTP systems involve a large number of users executing the same application code. These systems provide an ideal opportunity for reusing shared SQL statements.
Oracle Features for OLTP
|
211
Stored outlines
Oracle8
i
added support of execution-plan stability, sometimes referred to as
bound plans
, with stored outlines. The route a SQL statement takes during execution is critical for high performance. Once application developers and DBAs have tuned a SQL statement for maximum efficiency, they can force the Oracle optimizer to use the same execution plan regardless of environmental changes.
This provides critical stability and predictability in the face of software upgrades, schema changes, data-volume changes, and so on. Oracle9
i
added the capability for administrators to edit stored outlines.
Since Oracle Database 10
g
, youcan select better execu tion plans for the
optimizer to use in conjunction with poorly written SQL to improve OLTP performance without having to rewrite the SQL. The SQL Tuning Advisor performs these advanced optimizations on SQL statements, and can then create an improved SQL Profile for the statement. This profile is used instead of the original optimization plan at runtime.
Scalability
Both the shared server and the Database Resource Manager help Oracle support larger or mixed user populations.