In the dedicated connection mode, the server establishes a connection with the client for every client request to connect to the database server. This connection is used to process all requests of the client, until the user actively disconnects or the network is interrupted. When the connection is idle, the background process PMON tests the user's connection status at intervals. If the connection is disconnected, PMON cleans up the site and releases related resources. A dedicated connection is equivalent to a one-to-one connection that can quickly respond to user requests. Of course, when connecting, you must first create a PGA (Program global area). The pga_aggregate_target parameter determines the total amount of memory that can be used by all server processes, the workarea_size_policy parameter determines whether to use manual or automatic management. For example:
SQL> show parameter pga_aggregate_target
NAME TYPE VALUE
-------------------------------------------------------
Pga_aggregate_target big integer 10485760
SQL> show parameter workarea_size_policy
NAME TYPE VALUE
-----------------------------------------------------
Workarea_size_policy string AUTO
Pga consists of three parts, including sort_area_size that can be configured, session information, and stack space.
Sort_area_size is the memory space used for sorting: SQL> show parameter sort_area_size
NAME TYPE VALUE
-----------------------------------------------------
Sort_area_size integer 524288
If the sorting data volume is large and the sorting space is insufficient, Oracle uses a dedicated algorithm to segment the data. The data after segmentation is transferred to the temporary tablespace for sorting in the temporary tablespace, after the process is completed, it is combined and returned to the requesting user. This is why temporary tablespace is used for large sorting.
In a dedicated connection, all resources required for the connection are allocated in PGA. This memory zone is a private connection and cannot be accessed by other processes.
Dedicated connections use one-to-one connection to respond to user requests. However, if there are too many connected users, resources must be allocated to each connection, the number of connections is limited by hardware. To overcome this problem, Oracle proposed a connection method for shared connections, that is, using a server process to respond to multiple user connections. Unlike dedicated connections, the PGA is created only when there is a connection, A shared connection is allocated to a specified number of server processes as soon as the instance is started. The user's connections are queued and allocated to the server process by the distributor. Other processes are waiting in queue. As long as the user's request is completed, the connection will be disconnected immediately, and the Allocator will allocate idle server processes to other excluded processes.
The use of shared connections can effectively improve the utilization of server resources, but only one protocol is supported for one distributor. Each distributor has its own queue. After the request task is completed, the operator returns the operation result to the corresponding user process. However, the establishment of a shared connection requires the Oracle listening process, distributor, and sharing server process to complete the creation of a connection. Therefore, the connection allocation also takes some time and resources.
In the shared connection, sort_area_size is allocated in the large_pool of the SGA instance.
The above is the creation and management methods of the two connections. Ideally, using dedicated connections for long transactions or large transactions can effectively improve the system performance, reduces user waits and transaction queues to improve system utilization. For ultra-short transactions, short transactions, and small transactions, you can use the shared connection method to flatten the resource and efficiency. For example, for the OLTP system, use dedicated connections, and for websites, you can use shared connections.
So can we use shared connections in the OLTP system? If it can be used, can it improve performance?
The OLTP system generally has many long transactions and large transactions. For example, a user must perform several operations as a transaction. In this case, let's analyze and see what will happen:
The premise of analysis is that the number of user requests must be greater than the number of processes on the shared server. Otherwise, the performance of the shared connection is lower than that of the dedicated connection.
If the number of user requests is greater than the number of Shared Server Processes, it must be in the queue. If a Shared Server process is currently executing a long transaction, the request queue will always wait, until the current transaction ends. From the perspective of user requests, it is obvious that the response time is longer. From the server perspective, let's take a look at the instances provided by the netizen westlife_xu:
The shared connection is contrary to the long transaction. The shared connection of the long transaction will cause a serious queuing of the shared process, resulting in a serious reduction in performance.
For example, the sharing ratio of 200 requests is 10. Each shared process can process only one request within one time, that is to say, 10 processes can only process 10 requests within the same time. If a request requires a long process, it will cause serious queuing of other requests.
The shared process requires that each request on the client be extremely fast. If one request on the client takes a long time, other requests will have to wait until they are shared.
It can be seen from the above that if there is an OLTP system with large transactions and long transactions, the system will be slower than the original!
In summary, shared connections and dedicated connections have their own advantages. The key is to look at the application. It is a good way to connect your own applications.