常驻连接池(Database Resident Connection Pool)

联系:手机/微信(+86 17813235971) QQ(107644445)QQ咨询惜分飞

标题:常驻连接池(Database Resident Connection Pool)

作者:惜分飞©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]

一.介绍常驻连接池(Database Resident Connection Pool,Oracle DRCP)
数据库驻留连接池是Oracle Database 11g的一个新特性,专门为了解决在需要支持大量连接的环境对可扩性的迫切需求而设计的。数据库驻留连接池把数据库服务器进程和对话汇合起来(这样的组合称之为池服务器),通过从单主机或不同主机发出的多个应用软件进程的连接进行共享。由一个连接代理(Connection Broker)进程控制着数据库后台进程中的池服务器。连接代理会持续的连接客户并对客户进行验证。当需要进行某种数据库活动时,客户将请求连接代理提供池服务器,使用完毕后再将它们释放以供其他客户重新使用。当池服务器处在使用当中时,相当于一台专用服务器。对于来自常驻通道中的客户端连接请求,连接代理会为其选择一个合适的池服务器,并把客户端请求交给该池服务器处理,不再干涉。此后客户通过和该池服务器的直接对话来完成所有的数据库活动。当客户完成请求任务释放池服务器后,连接代理将重新接管该池服务器。

二.什么时间使用DRCP
1 使用较小内存的、大量的客户端连接
2 客户端应用是相似的,可以共享或重用会话
3 客户端占用数据库连接的周期相当短
4 会话不需要跨客户请求
5 客户端有众多的主机与进程

三.Dedicated Servers,Shared Servers与DRCP的内存需求和区别对比
一般情况下,由于每个会话需要消耗400k的内存,每个进程需要消耗4m的内存,现在我们以DRCP的pool size是100,shared server的shared server进程是100为例,假如有5000个客户端连接到这些环境,则这些主机的内存分配如下:

A Dedicated Server
Memory used = 5000 X (400 KB + 4 MB) = 22 GB

B Shared Server
Memory used = 5000 X 400 KB + 100 X 4 MB = 2.5 GB
Out of the 2.5 GB, 2 GB is allocated from the SGA
.
C Database Resident Connection Pooling
Memory used = 100 X (400 KB + 4 MB) + (5000 X 35KB)= 615 MB


四.使用DRCP时,当实例有活动pooled server,有以下限制:
1 不能shutdown database;
2 不能停掉DRCP;
3 不能用database link连接到不同实例的DRCP;
4 不能使用Advanced Security Option (ASO),比如encryption等

五.客户端如何连接到DRCP
如果是专用服务器连接,则SERVER=DEDICATED,如果是DRCP连接,则SEVER=POOLED。如果要指定客户端请求到DRCP,则客户端的tnsnames.ora中的连接字符串必须指定连接类型是POOLED,配置方式如下所示:

ORA11G_P =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.10)(PORT = 1521))
    )
    (CONNECT_DATA =
     (SERVER=POOLED)  --注意
      (SERVICE_NAME = ora11g)
    )
  )

说明:
1)如果在tnsnames.ora中指定了SERVER=POOLED,但并没有在实例中启动DRCP,则当客户请求连接时,DB会报ORA-12520错误。
2)11g的客户端才可以使用DRCP,如果10g的客户端在tnsnames.ora中指定了SERVER=POOLED,则连接时报ORA-56606。

六.DRCP配置/查询
1.DRCP启动/关闭

--查看当前DRCP状态
SQL> select CONNECTION_POOL,status from dba_cpool_info;

CONNECTION_POOL                STATUS
------------------------------ --------------------------------
SYS_DEFAULT_CONNECTION_POOL    INACTIVE

--启动DRCP
SQL> execute dbms_connection_pool.start_pool;

PL/SQL procedure successfully completed.

SQL> select CONNECTION_POOL,status from dba_cpool_info;

CONNECTION_POOL                STATUS
------------------------------ --------------------------------
SYS_DEFAULT_CONNECTION_POOL    ACTIVE

--关闭DRCP
SQL> exec dbms_connection_pool.stop_pool

PL/SQL procedure successfully completed.

SQL> select CONNECTION_POOL,status from dba_cpool_info;

CONNECTION_POOL                STATUS
------------------------------ --------------------------------
SYS_DEFAULT_CONNECTION_POOL    INACTIVE

2.修改DRCP参数

--dbms_connection_pool.configure_pool
exec dbms_connection_pool.configure_pool(
	POOL_NAME=>'SYS_DEFAULT_CONNECTION_POOL',
	minsize=>10,
	maxsize=>100,
	INCRSIZE=>10,
	SESSION_CACHED_CURSORS=>50,
	inactivity_timeout=>3000,
	max_think_time=>100,
	MAX_USE_SESSION=>10000,
	MAX_LIFETIME_SESSION=>36000
   );

--dbms_connection_pool.alter_param
exec dbms_connection_pool.alter_param(
	POOL_NAME=>'SYS_DEFAULT_CONNECTION_POOL',
	PARAM_NAME=>'MINSIZE',
	PARAM_VALUE=>'2');

3.DRCP视图

DBA_CPOOL_INFO 
displays configuration information about all Database Resident Connection Pools in the database.

V$CPOOL_STATS 
displays information about the Database Resident Connection Pool statistics for an instance


V$CPOOL_CC_STATS 
displays information about the connection class level statistics for 
the Database Resident Connection Pool per instance.

V$CPOOL_CONN_INFO 
displays connection information about each connection to the connection broker.

V$CPOOL_CC_INFO 
displays information about the pool-to-connection class mapping for 
the Database Resident Connection Pool per instance.

七.DRCP相关进程

oracle   11715     1  0 21:38 ?        00:00:00 ora_n000_ora11g
oracle   11719     1  0 21:38 ?        00:00:00 ora_l000_ora11g
oracle   11723     1  0 21:38 ?        00:00:00 ora_l001_ora11g
oracle   11727     1  0 21:38 ?        00:00:00 ora_l002_ora11g
oracle   11731     1  0 21:38 ?        00:00:02 ora_l003_ora11g
oracle   12490     1  0 21:57 ?        00:00:00 ora_l004_ora11g
oracle   12494     1  0 21:57 ?        00:00:00 ora_l005_ora11g
oracle   12498     1  0 21:57 ?        00:00:00 ora_l006_ora11g
oracle   12502     1  0 21:57 ?        00:00:00 ora_l007_ora11g
oracle   12506     1  0 21:57 ?        00:00:00 ora_l008_ora11g
oracle   12510     1  0 21:57 ?        00:00:00 ora_l009_ora11g
oracle   12514     1  0 21:57 ?        00:00:01 ora_l010_ora11g
oracle   12518     1  0 21:57 ?        00:00:00 ora_l011_ora11g
oracle   12522     1  0 21:57 ?        00:00:00 ora_l012_ora11g
oracle   12526     1  0 21:57 ?        00:00:00 ora_l013_ora11g
oracle   12530     1  0 21:57 ?        00:00:00 ora_l014_ora11g
oracle   12534     1  0 21:57 ?        00:00:00 ora_l015_ora11g
oracle   12538     1  0 21:57 ?        00:00:00 ora_l016_ora11g
oracle   12542     1  0 21:57 ?        00:00:00 ora_l017_ora11g
oracle   12546     1  0 21:57 ?        00:00:00 ora_l018_ora11g
oracle   12550     1  0 21:57 ?        00:00:00 ora_l019_ora11g

ora_n000_ora11g 
Connection Broker Process

ora_l000_ora11g 
Pooled Server Process(Handles client requests in Database Resident Connection Pooling)
此条目发表在 Oracle 分类目录。将固定链接加入收藏夹。

常驻连接池(Database Resident Connection Pool)》有 2 条评论

  1. 惜分飞 说:

    Database Resident Connection Pool参数介绍

  2. 惜分飞 说:

    dbms_connection_pool包使用

    SQL> desc dbms_connection_pool
    PROCEDURE ALTER_PARAM
     Argument Name                  Type                    In/Out Default?
     ------------------------------ ----------------------- ------ --------
     POOL_NAME                      VARCHAR2                IN     DEFAULT
     PARAM_NAME                     VARCHAR2                IN
     PARAM_VALUE                    VARCHAR2                IN
    PROCEDURE CONFIGURE_POOL
     Argument Name                  Type                    In/Out Default?
     ------------------------------ ----------------------- ------ --------
     POOL_NAME                      VARCHAR2                IN     DEFAULT
     MINSIZE                        BINARY_INTEGER          IN     DEFAULT
     MAXSIZE                        BINARY_INTEGER          IN     DEFAULT
     INCRSIZE                       BINARY_INTEGER          IN     DEFAULT
     SESSION_CACHED_CURSORS         BINARY_INTEGER          IN     DEFAULT
     INACTIVITY_TIMEOUT             BINARY_INTEGER          IN     DEFAULT
     MAX_THINK_TIME                 BINARY_INTEGER          IN     DEFAULT
     MAX_USE_SESSION                BINARY_INTEGER          IN     DEFAULT
     MAX_LIFETIME_SESSION           BINARY_INTEGER          IN     DEFAULT
    PROCEDURE RESTORE_DEFAULTS
     Argument Name                  Type                    In/Out Default?
     ------------------------------ ----------------------- ------ --------
     POOL_NAME                      VARCHAR2                IN     DEFAULT
    PROCEDURE START_POOL
     Argument Name                  Type                    In/Out Default?
     ------------------------------ ----------------------- ------ --------
     POOL_NAME                      VARCHAR2                IN     DEFAULT
    PROCEDURE STOP_POOL
     Argument Name                  Type                    In/Out Default?
     ------------------------------ ----------------------- ------ --------
     POOL_NAME                      VARCHAR2                IN     DEFAULT