Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

rekharaghuram
from rekharaghuram More from this publisher
05.11.2015 Views

CHAPTER 5 ■ ORACLE PROCESSES 165 Notice how the first time I queried, I was using S000 as the shared server. Then in another session, I executed a long-running statement that monopolized the shared server, which just happened to be S000 this time. The first nonbusy shared server is the one that gets assigned the work to do, and in this case no one else was asking to use the S000 shared server, so the DBMS_LOCK command took it. Now, when I queried again in the first SQL*Plus session, I got assigned to another shared server process, since the S000 shared server was busy. It is interesting to note that the parse of a query (returns no rows yet) could be processed by shared server S000, the fetch of the first row by S001, the fetch of the second row by S002, and the closing of the cursor by S003. That is, an individual statement might be processed bit by bit by many shared servers. So, what we have seen in this section is that a connection—a physical pathway from a client to a database instance—may have zero, one, or more sessions established on it. We have seen one use case of that when using SQL*Plus’s AUTOTRACE facility. Many other tools employ this ability as well. For example, Oracle Forms uses multiple sessions on a single connection to implement its debugging facilities. The n-tier proxy authentication feature of Oracle, used to provide end-to-end identification of users from the browser to the database, makes heavy use of the concept of a single connection with multiple sessions, but in each session there would use a potentially different user account. We have seen that sessions can use many processes over time, especially in a shared server environment. Also, if we are using connection pooling with Oracle Net, then our session might not be associated with any process at all; the client would drop the connection after an idle time and reestablish it transparently upon detecting activity. In short, there is a many-to-many relationship between connections and sessions. However, the most common case, the one most of us see day to day, is a one-to-one relationship between a dedicated server and a single session. Dedicated Server vs. Shared Server Before we continue to examine the rest of the processes, let’s discuss why there are two connection modes and when one might be more appropriate than the other. When to Use Dedicated Server As noted previously, in dedicated server mode there is a one-to-one mapping between client connection and server process. This is by far the most common method of connection to the Oracle database for all SQL-based applications. It is the simplest to set up and provides the easiest way to establish connections. It requires little to no configuration. Since there is a one-to-one mapping, you do not have to be concerned that a long-running transaction will block other transactions. Those other transactions will simply proceed via their own dedicated processes. Therefore, it is the only mode you should consider using in a non-OLTP environment where you may have long-running transactions. Dedicated server is the recommended configuration for Oracle, and it scales rather nicely. As long as your server has sufficient hardware (CPU and RAM) to service the number of dedicated server processes your system needs, dedicated server may be used for thousands of concurrent connections. Certain operations must be done in a dedicated server mode, such as database startup and shutdown, so every database will have either both or just a dedicated server setup.

166 CHAPTER 5 ■ ORACLE PROCESSES When to Use Shared Server Shared server setup and configuration, while not difficult, involves an extra step beyond dedicated server setup. The main difference between the two is not, however, in their setup; it is in their mode of operation. With dedicated server, there is a one-to-one mapping between client connections and server processes. With shared server, there is a many-to-one relationship: many clients to a shared server. As its name implies, shared server is a shared resource, whereas a dedicated server is not. When using a shared resource, you must be careful to not monopolize it for long periods of time. As you saw previously, use of a simple DBMS_LOCK.SLEEP(20) in one session would monopolize a shared server process for 20 seconds. Monopolization of these shared server resources can lead to a system that appears to hang. Figure 5-2 depicts two shared servers. If I have three clients, and all of them attempt to run a 45-second process more or less at the same time, two of them will get their response in 45 seconds and the third will get its response in 90 seconds. This is rule number one for shared server: make sure your transactions are short in duration. They can be frequent, but they should be short (as characterized by OLTP systems). If they are not short, you will get what appears to be a total system slowdown due to shared resources being monopolized by a few processes. In extreme cases, if all of the shared servers are busy, the system will appear to hang for all users except the lucky few who are monopolizing the shared servers. Another interesting situation that you may observe when using shared server is that of an artificial deadlock. With shared server, a number of server processes are being “shared” by a potentially large community of users. Consider a situation where you have five shared servers and one hundred user sessions established. Now, at most, five of those user sessions can be active at any point in time. Suppose one of these user sessions updates a row and does not commit. While that user sits there and ponders his or her modification, five other user sessions try to lock that same row. They will, of course, become blocked and will patiently wait for that row to become available. Now, the user session that holds the lock on this row attempts to commit its transaction (hence releasing the lock on the row). That user session will find that all of the shared servers are being monopolized by the five waiting sessions. We have an artificial deadlock situation here: the holder of the lock will never get a shared server to permit the commit, unless one of the waiting sessions gives up its shared server. But, unless the waiting sessions are waiting for the lock with a timeout, they will never give up their shared server (you could, of course, have an administrator “kill” their session via a dedicated server to release this logjam). So, for these reasons, shared server is only appropriate for an OLTP system characterized by short, frequent transactions. In an OLTP system, transactions are executed in milliseconds— nothing ever takes more than a fraction of a second. Shared server is highly inappropriate for a data warehouse. Here, you might execute a query that takes one, two, five, or more minutes. Under shared server, this would be deadly. If you have a system that is 90 percent OLTP and 10 percent “not quite OLTP,” then you can mix and match dedicated servers and shared server on the same instance. In this fashion, you can reduce the number of server processes on the machine dramatically for the OLTP users, and make it so that the “not quite OLTP” users do not monopolize their shared servers. In addition, the DBA can use the built-in Resource Manager to further control resource utilization.

CHAPTER 5 ■ ORACLE PROCESSES 165<br />

Notice how the first time I queried, I was using S000 as the shared server. Then in another<br />

session, I executed a long-running statement that monopolized the shared server, which just<br />

happened to be S000 this time. The first nonbusy shared server is the one that gets assigned<br />

the work to do, <strong>and</strong> in this case no one else was asking to use the S000 shared server, so the<br />

DBMS_LOCK comm<strong>and</strong> took it. Now, when I queried again in the first SQL*Plus session, I got<br />

assigned to another shared server process, since the S000 shared server was busy.<br />

It is interesting to note that the parse of a query (returns no rows yet) could be processed<br />

by shared server S000, the fetch of the first row by S001, the fetch of the second row by S002,<br />

<strong>and</strong> the closing of the cursor by S003. That is, an individual statement might be processed bit<br />

by bit by many shared servers.<br />

So, what we have seen in this section is that a connection—a physical pathway from a<br />

client to a database instance—may have zero, one, or more sessions established on it. We<br />

have seen one use case of that when using SQL*Plus’s AUTOTRACE facility. Many other tools<br />

employ this ability as well. For example, <strong>Oracle</strong> Forms uses multiple sessions on a single connection<br />

to implement its debugging facilities. The n-tier proxy authentication feature of<br />

<strong>Oracle</strong>, used to provide end-to-end identification of users from the browser to the database,<br />

makes heavy use of the concept of a single connection with multiple sessions, but in each session<br />

there would use a potentially different user account. We have seen that sessions can use<br />

many processes over time, especially in a shared server environment. Also, if we are using<br />

connection pooling with <strong>Oracle</strong> Net, then our session might not be associated with any<br />

process at all; the client would drop the connection after an idle time <strong>and</strong> reestablish it<br />

transparently upon detecting activity.<br />

In short, there is a many-to-many relationship between connections <strong>and</strong> sessions. However,<br />

the most common case, the one most of us see day to day, is a one-to-one relationship<br />

between a dedicated server <strong>and</strong> a single session.<br />

Dedicated Server vs. Shared Server<br />

Before we continue to examine the rest of the processes, let’s discuss why there are two connection<br />

modes <strong>and</strong> when one might be more appropriate than the other.<br />

When to Use Dedicated Server<br />

As noted previously, in dedicated server mode there is a one-to-one mapping between client<br />

connection <strong>and</strong> server process. This is by far the most common method of connection to the<br />

<strong>Oracle</strong> database for all SQL-based applications. It is the simplest to set up <strong>and</strong> provides the<br />

easiest way to establish connections. It requires little to no configuration.<br />

Since there is a one-to-one mapping, you do not have to be concerned that a long-running<br />

transaction will block other transactions. Those other transactions will simply proceed via<br />

their own dedicated processes. Therefore, it is the only mode you should consider using in a<br />

non-OLTP environment where you may have long-running transactions. Dedicated server is<br />

the recommended configuration for <strong>Oracle</strong>, <strong>and</strong> it scales rather nicely. As long as your server<br />

has sufficient hardware (CPU <strong>and</strong> RAM) to service the number of dedicated server processes<br />

your system needs, dedicated server may be used for thous<strong>and</strong>s of concurrent connections.<br />

Certain operations must be done in a dedicated server mode, such as database startup<br />

<strong>and</strong> shutdown, so every database will have either both or just a dedicated server setup.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!