Chinaunix首页 | 论坛 | 博客
  • 博客访问: 104574250
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类: Oracle

2008-04-30 16:46:25

使用oracle data provider的连接池功能,实现比较高效的服务器,文档来源:
Oracle data provider for DotNet developer guide


Connection Pooling
ODP.NET connection pooling is enabled and disabled using the Pooling connection
string attribute. By default, connection pooling is enabled. The following are
ConnectionString attributes that control the behavior of the connection pooling
service:
■ Connection Lifetime
■ Connection Timeout
■ Decr Pool Size
■ HA Events
■ Incr Pool Size
■ Load Balancing
■ Max Pool Size
■ Min Pool Size
■ Pooling
■ Validate Connection
Connection Pooling Example
The following example opens a connection using ConnectionString attributes
related to connection pooling.
// C#
using System;
using Oracle.DataAccess.Client;
class ConnectionPoolingSample
{
static void Main()
{
OracleConnection con = new OracleConnection();
//Open a connection using ConnectionString attributes
//related to connection pooling.
con.ConnectionString =
"User Id=scott;Password=tiger;Data Source=oracle;" +
"Min Pool Size=10;Connection Lifetime=120;Connection Timeout=60;" +
"Incr Pool Size=5; Decr Pool Size=2";
con.Open();
Console.WriteLine("Connection pool successfully created");
// Close and Dispose OracleConnection object
con.Close();
con.Dispose();
Console.WriteLine("Connection is placed back into the pool.");
}
}
Using Connection Pooling
When connection pooling is enabled (the default), the Open and Close methods of the
OracleConnection object implicitly use the connection pooling service, which is
responsible for pooling and returning connections to the application.
The connection pooling service creates connection pools by using the
ConnectionString property as a signature, to uniquely identify a pool.
If there is no existing pool with the exact attribute values as the ConnectionString
property, the connection pooling service creates a new connection pool. If a pool
already exists with the requested signature, a connection is returned to the application
from that pool.
When a connection pool is created, the connection pooling service initially creates the
number of connections defined by the Min Pool Size attribute of theConnectionString property. This number of connections is always maintained by
the connection pooling service for the connection pool.
At any given time, these connections are in use by the application or are available in
the pool.
The Incr Pool Size attribute of the ConnectionString property defines the
number of new connections to be created by the connection pooling service when
more connections are needed in the connection pool.
When the application closes a connection, the connection pooling service determines
whether or not the connection lifetime has exceeded the value of the Connection
Lifetime attribute. If so, the connection pooling service closes the connection;
otherwise, the connection goes back to the connection pool. The connection pooling
service enforces the Connection Lifetime only when a connection is going back to
the connection pool.
The Max Pool Size attribute of the ConnectionString property sets the maximum
number of connections for a connection pool. If a new connection is requested, but no
connections are available and the limit for Max Pool Size has been reached, then the
connection pooling service waits for the time defined by the Connection Timeout
attribute. If the Connection Timeout time has been reached, and there are still no
connections available in the pool, the connection pooling service raises an exception
indicating that the connection pool request has timed-out.
The Validate Connection attribute validates connections coming out of the pool.
This attribute should be used only when absolutely necessary, because it causes a
round-trip to the database to validate each connection immediately before it is
provided to the application. If invalid connections are uncommon, developers can
create their own event handler to retrieve and validate a new connection, rather than
using the Validate Connection attribute. This generally provides better
performance.
The connection pooling service closes connections when they are not used;
connections are closed every 3 minutes. The Decr Pool Size attribute of the
ConnectionString property provides connection pooling service for the maximum
number of connections that can be closed every 3 minutes.
Connection Pool Management Not Supported in a .NET Stored Procedure
ODP.NET connection pool management provides explicit connection pool control to
ODP.NET applications. Applications can explicitly clear connections in a connection
pool.
Using connection pool management, applications can do the following:
■ Clear connections from connection pools using the ClearPool method.
■ Clear connections in all the connection pools in an application domain, using the
ClearAllPools method.
Connection Pooling for a Real Application Clusters (RAC) Database
This section discusses optimization and other aspects of connection pooling for a Real
Application Clusters (RAC) database. RAC is the technology that makes grids possible for Oracle database by providing the ability to access the database from multiple
instances, each running on nodes in a cluster.
Connection Pool Optimizations for RAC
Oracle Data Provider for .NET optimizes connection pooling for RAC database by
balancing work requests across RAC instances, based on the load balancing advisory
and service goal. Furthermore, the ODP.NET connection pool can be enabled to
proactively free resources associated with connections that have been severed due to a
down RAC service, service member, or node.
Oracle Data Provider for .NET uses the following features to optimize connection
pooling for RAC:
■ Runtime Connection Load Balancing
When Runtime Connection Load Balancing is enabled:
– The ODP.NET connection pool dispenses connections based on the load
balancing advisory and service goal.
– The ODP.NET connection pool also balances the number of connections to
each service member providing the service, based on the load balancing
advisory and service goal.
By default, this feature is disabled. To enable runtime connection load balancing,
include "Load Balancing=true" in the connection string. This feature can only
be used against a RAC database and only if "pooling=true".
In order to use Runtime Connection Load Balancing, specific RAC configurations
must be set. For further information, see Oracle Database Oracle Clusterware and
Oracle Real Application Clusters Administration and Deployment Guide. Oracle Net
Services should also be configured for load balancing. See Oracle Net Services
Administrator's Guide for further details.
The following connection string example enables Runtime Connection Load
Balancing:
"user id=scott;password=tiger;data source=erp;load balancing=true;"
■ HA events
When HA events is enabled:
■ ODP.NET connection pool proactively removes connections from the pool
when a RAC service, service member, or node goes down.
■ ODP.NET establishes connections to existing RAC instances if the removal of
severed connections bring the total number of connections below the "min
pool size".
By default this feature is disabled. To enable HA events, include "HA
Events=true" in the connection string. This feature can only be used against a
RAC database and only if "pooling=true".
The following connection string example enables HA Events:
"user id=scott;password=tiger;data source=erp;HA events=true;"
Pool Size Attributes in a RAC Database
When connection pools are created for a non-RAC database, pool size attributes are
applied to the single service. Similarly, when connection pools are created for a RAC
database, the pool size attributes are applied to a service and not to service members.
For example, if "Min Pool Size" is set to N, ODP.NET does not create N connections
for each service member. Instead, it creates, at minimum, N connections for the entire
service, where N connections are distributed among the service members.
The following pool size connection string attributes are applied to a service.
■ Min Pool Size
■ Max Pool Size
■ Incr Pool Size
■ Decr Pool Size

 

原文:http://thinkdollar.blog.ccidnet.com/blog-htm-itemid-155086-do-showone-type-blog-uid-52739.html

阅读(504) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~