Wednesday, May 17, 2023

Monitoring and Viewing DRCP Settings:

Monitoring and Viewing DRCP Settings:

To ensure optimal performance and troubleshoot any potential issues related to DRCP, it's essential to monitor and view the DRCP settings in your Oracle database. The following scripts can be used to gather valuable information about the DRCP configuration and monitor its performance:

  1. Viewing DRCP Configuration: To view the current DRCP configuration settings, you can execute the following SQL query:
sql
Select * from DBA_CPOOL_INFO;

This query provides details such as the maximum number of pooled servers, session pooling mode, minimum and maximum number of sessions per pooled server, and other relevant DRCP settings.

  1. Monitoring DRCP Statistics: Oracle provides dynamic performance views to monitor the DRCP statistics. The following query can be used to retrieve information about the current DRCP pool and server statistics:
sql
SELECT * FROM GV$CPOOL_CC_STATS

These views offer insights into metrics such as the number of connections created, connections in use, connections released, and other statistics related to DRCP pool and server utilization.

  1. Monitoring DRCP Performance: To monitor the performance of the DRCP connections and identify potential bottlenecks, you can execute the following SQL query:
sql
SELECT * FROM GV$CPOOL_CC_STATS

This query provides valuable information about the performance metrics of the DRCP connections, including the number of requests, average response time, and connection queue length.

  1. Checking DRCP Status: To check the overall status of the DRCP feature in your Oracle database, you can use the following query:
sql
select a.connection_status,a.*  from gv$cpool_conn_info a; 

The returned status can be "ENABLED" if DRCP is active or "DISABLED" if it's currently disabled.

  1. Monitoring DRCP Session Activity: To monitor the activity of individual DRCP sessions and connections, you can query the v$drcp_sessions view:
sql
select sess.inst_id Inst, sess.username, sess.sid, sess.server, sess.seq#, round(sess.wait_time_micro/1000000,1) time_waited, sess.event, sess.state, sess.status, sess.program, sess.machine, sess.module, sess.action from gv$session sess where sess.server = 'POOLED' order by sess.sid;

This view provides details about the active DRCP sessions, including the session ID, username, client identifier, and other relevant information.

By regularly running these monitoring scripts, database administrators can gain insights into the current DRCP settings, track performance metrics, identify potential issues, and take necessary actions to optimize the performance of DRCP in their Oracle database.

Conclusion:

Monitoring and viewing the DRCP settings in Oracle is crucial for ensuring optimal performance and troubleshooting any potential issues. By utilizing the provided scripts to gather information about the DRCP configuration, monitoring statistics, and tracking performance metrics, database administrators can effectively manage and optimize the DRCP feature to enhance the performance of their Oracle database-driven applications.

Connecting to Autonomous Database with Database Resident Connection Pooling (DRCP)

Connecting to Autonomous Database (ADB ) with Database Resident Connection Pooling (DRCP)

Introduction:

Oracle Autonomous Database (ADB) offers powerful features to simplify database management and optimize performance. One such feature is Database Resident Connection Pooling (DRCP), which provides efficient management of open connections. By leveraging DRCP, you can reduce database resource requirements and scale for simultaneous connections. In this blog post, we will guide you through the process of connecting to Autonomous Database using DRCP and highlight important considerations for working with DRCP.

Connecting with a Pooled DRCP Server Process:

To connect to Autonomous Database using a pooled DRCP server process, follow these steps:

Step 1: Locate the tnsnames.ora File: Locate or obtain the tnsnames.ora file that you are using to connect to your Autonomous Database. This file contains the necessary configuration details for establishing a connection.

Step 2: Modify the tnsnames.ora File: Edit the tnsnames.ora file and add the server type as SERVER=POOLED to enable DRCP for your connection. The modified entry should resemble the following example:

plaintext
example_high = (description= (address=(protocol=tcps)(port=1522)(host=adb.example.oraclecloud.com)) (connect_data=(service_name=example_high.oraclecloud.com)(SERVER=POOLED)) (security=(ssl_server_dn_match=yes)))

Ensure that you replace "example_high" with the appropriate service name for your Autonomous Database instance.

Step 3: Download Client Credentials (Wallets): To securely connect to Autonomous Database, you need to download the client credentials (wallets). Refer to Oracle's documentation for instructions on how to obtain the client credentials (wallets) required for authentication.

Step 4: Connect to Autonomous Database: With the modified tnsnames.ora file and the downloaded client credentials (wallets), you can now establish a connection to Autonomous Database using DRCP. Depending on your programming language or framework, use the appropriate connection method and provide the necessary connection details.

Important Considerations for DRCP in Autonomous Database:

  1. DRCP Enabled by Default: DRCP is enabled by default in Autonomous Database. However, using DRCP is optional. To connect using a pooled connection, specify SERVER=POOLED in the tnsnames.ora file. If you do not specify SERVER=POOLED, you will connect with a dedicated connection.

  2. Connection Pooling Benefits: DRCP enables efficient sharing of server processes among multiple user processes, reducing resource requirements and enabling scalability for simultaneous connections. Leveraging connection pooling can significantly enhance the performance of your applications.

  3. DRCP is recommended when there are applications the connects and disconnects after every transaction or you need to startup a application with a huge number of INACTIVE sessions.

Conclusion:

Connecting to Autonomous Database with Database Resident Connection Pooling (DRCP) provides efficient connection management and scalability for simultaneous connections. By modifying the tnsnames.ora file to include SERVER=POOLED and utilizing the client credentials (wallets), you can establish a connection to Autonomous Database using DRCP. With DRCP enabled by default in Autonomous Database, you can leverage connection pooling benefits to optimize the performance of your applications while reducing resource requirements.

 

Performing a Concurrency Test with Python and Oracle Autonomous Database

Conducting a concurrency test is a crucial step in evaluating the performance and scalability of an application. In this blog post, we'll explore how to execute a concurrency test using a Python script to connect to an Oracle Autonomous Database. Oracle Autonomous Database is a fully managed cloud database service that offers high availability, scalability, and automated maintenance. By leveraging Python and Oracle Autonomous Database, we can easily simulate multiple concurrent sessions and measure the response times of each query.

Prerequisites

Before getting started, ensure you have the following prerequisites in place:

  1. Python installed on your machine
  2. cx_Oracle library installed (python -m pip install cx_Oracle --upgrade )
  3. Access to an Oracle Autonomous Database instance

Setting Up the Python Script

Let's begin by creating a Python script that connects to Oracle Autonomous Database, executes queries concurrently, and measures the response times. Here's the script:

import cx_Oracle
#import concurrent.futures
import time
import threading


#dsn = cx_Oracle.makedsn('<hostname>', '<port>', '<service_name>')
username = 'ADMIN'
password = 'Carbon##lalal4'
dsn="krpocadw_low"

# List of queries to be executed
queries = [
    "SELECT  /*+ NO_RESULT_CACHE */ * FROM ssb.customer where rownum < 1000" ,
    "SELECT  /*+ NO_RESULT_CACHE */ * FROM ssb.customer where rownum < 10000",
    "SELECT  /*+ NO_RESULT_CACHE */ * FROM ssb.customer where rownum < 100000",
    "select  /*+ NO_RESULT_CACHE */sum(lo_extendedprice*lo_discount) as revenue from ssb.lineorder, ssb.dwdate where lo_orderdate = d_datekey and d_yearmonthnum = 199401 and lo_discount between 4 and 6 and lo_quantity between 26 and 35",
    """ select  /*+ NO_RESULT_CACHE */sum(lo_extendedprice*lo_discount) as revenue from ssb.lineorder, ssb.dwdate
     where lo_orderdate = d_datekey and d_weeknuminyear = 6 and d_year = 1994 and lo_discount
     between 5 and 7 and lo_quantity between 26 and 35 """
]


# Function to execute queries and measure their response times

# Function to execute queries and measure their response times
def execute_query(queries):
    
    # Establish connection to the Oracle database
    connection = cx_Oracle.connect(username, password, dsn)

    # Create a cursor
    cursor = connection.cursor()

    response_times = []

    for query in queries:
        # Append current date and time to the query
        query_with_time = query + " /* " + time.strftime("%Y-%m-%d %H:%M:%S") + " */"
        
        start_time = time.time()

        # Execute the query
        cursor.execute(query_with_time)

        # Fetch all the rows
        rows = cursor.fetchall()

        end_time = time.time()

        # Calculate the response time
        response_time = end_time - start_time
        response_times.append(response_time)

    # Close cursor and connection
    cursor.close()
    connection.close()

    return response_times


# Function to run queries concurrently and measure average response time per query
# Function to run queries concurrently and measure average response time per query
def run_queries_concurrently(concurrency_level):
    response_times = []

    # Create a list to hold the threads
    threads = []

    # Create and start the threads
    for _ in range(concurrency_level):
        thread = threading.Thread(target=lambda: response_times.extend(execute_query(queries)))
        threads.append(thread)
        thread.start()

    # Wait for all threads to complete
    for thread in threads:
        thread.join()

    return response_times


# Main function
def main():
    # Define the levels of concurrency
    concurrency_levels = [1, 2, 14, 28]

    for level in concurrency_levels:
        print(f"Running queries with concurrency level: {level}")

        # Measure the average response time per query
        response_times = run_queries_concurrently(level)

        for i, query in enumerate(queries):
            average_time = sum(response_times[i::len(queries)]) / len(response_times[i::len(queries)])
            print(f"Query: {query}")
            print(f"Average response time: {average_time:.4f} seconds\n")

# Execute the main function
if __name__ == "__main__":
    main()

Make sure to replace <hostname>, <port>, <service_name>, <username>, and <password> with your actual Oracle Autonomous Database connection details. Update the queries list with your desired