RAC之service——负载均衡与高可用(LB和HA)

负载均衡是指把负载平均分配到集群中的各个节点,从而提高整体性能。Oracle RAC提供两种方式实现负载均衡,第一种是纯技术手段,即在用户连接时,根据系统当前的负载情况决定由哪个节点处理用户请求;第二种是面向业务,人为的把应用切分成很多service,通过某个service过来的连接请求都由某个节点处理。下面来具体看看这两种手段:
    
    纯技术手段 (面向连接的负载均衡)
    
    1. 客户端负载均衡
    
    配置方法是在客户端tnsnames.ora文件中设置LOAD_BALANCE=YES,当客户端发起连接时,会从地址列表中随机选取一个,把连接请求随机分散给各个实例。
    这个技术的最大缺点在于不能根据各个实例的真实负载情况来分散请求,太过粗糙,因此很少使用。
    
    2. 服务器端负载均衡
    
    服务器端 负载均衡依赖于Listener收集的负载信息,在数据库运行过程中,pmon进程会收集系统的负载信息,定期更新至Listener中。如果你配置了 Remote_listener参数,pmon进程不但能把负载信息注册到本地Listener,也可以注册到其它实例的Listener。这样有了 pmon自动注册机制后,集群的每个节点的Listener都掌握了所有节点的负载信息,当收到客户端请求时,会把连接分配给负载最小的实例。
    
    面向业务手段 (利用Service负载均衡)
    
    上面介绍了纯技术手段进行的负载均衡,看起来很美好,但在实际使用中,可能会带来非常大的性能问题。大家都知道,RAC由于其share-disk的架 构,它的性能很大程度上依赖于内存融合(Cache Fusion),纯技术手段无法知道业务的具体情况,因此它可能把同一个业务的连接分散到各个实例中,导致大量的内存融合,性能急剧下降。
    
    如果我们换一种思路,把同一种应用程序的连接分到同一个实例上,比如A应用程序的连接都连在A实例,B应用程序的连接都连在B实例上,这样就能够有效地减少内存融合。
    对应用的划分可以通过service实现,这需要DBA和开放人员合作,在了解业务特点的情况下配置service

 

 

Workload management enables you to manage workload distributions to provide optimal performance for users and applications. Workload management comprises the following:

1>Services—Oracle Database 10g introduces a powerful automatic workload management facility, called services, to enable the enterprise grid vision. Services are entities that you can define in Oracle RAC databases that enable you to group database workloadsand route work to the optimal instances that are assigned to offer the service.

(services可以允许我们将整个数据库负载进行分组,然后将不同的工作负载路由到提供该service的最优的实例。)
2>Connection Load Balancing—A feature of Oracle Net Services that balances incoming connections across all of the instances that provide the requested database service. 

(将connection分布在提供了我们请求的service的实例上。分为客户端连接负载均衡、服务器端负载均衡)

3>Load Balancing Advisory—Provides information to applications about the current service levels that the database and its instances are providing. The load balancing advisory makes recommendations to applications about where to direct application requests to obtain the best service based on the policy that you have defined for that service. 

(负载均衡顾问/咨询 对于负载均衡的实现十分重要,他提供了系统的负载信息。)

4>Fast Application Notification (FAN)—The notification mechanism that Oracle RAC uses to quickly alert applications about configuration and workload service level changes.

5>Runtime Connection Load Balancing—This is the ability of Oracle Clients to provide intelligent allocations of connections in the connection pool based on the current service level provided by the database instances when applications request a connection to complete some work.

6>Fast Connection Failover—This is the ability of Oracle Clients to provide rapid failover of connections by subscribing to FAN events.

7>High Availability Framework—An Oracle RAC component that enables the Oracle Database to maintain components in a running state at all times.

When a user or application connects to a database, Oracle recommends that you specify a service in the connect data portion of the connect string. Oracle Database automatically creates one database service when the database is created. For many installations, this may be all you need. To enable more flexibility in the management of the workload using the database, Oracle Database 10g enables you to create multiple services and specify which instances offer the services.

 

With Runtime Connection Load Balancing, applications can use load balancing advisoryevents to provide better service to users. The Oracle JDBC and ODP.NET clients are automatically integrated to take advantage of load balancing advisory events. (load balanceing advisory 的实现需要 Runtime Connection Load Balancing的支持)


oracle推荐使用service来进行负载均衡的配置,而目前实际情况下的RAC,多数都没有利用好service来进行负载均衡。service对于负载均衡十分重要,对于failover也十分重要。RAC环境下的service是一个十分重要的组件,我们应该很好的掌握它。其他的FAN, Load balancing advisory等等都是为service来服务的。

 

 

 

我们都知道RAC提供的最重要的两个特性就是:负载均衡高可用(load balancing, high available, 简称HALB)。这两个特性是RAC的核心价值所在。负载均衡,提供了scalbility,可扩展性。高可用利用故障转移failover来实现7*24小时的持续对外提供服务。

 

1. HA

HA的是通过故障转移failover来实现的,而failover有三种方式:

1> 客户端基于连接的failover:在RAC环境下,tnsnames.ora中有多个listener的地址串。通过tnsnames.ora中的failover=on来控制,默认是开启的。其提供的功能为:默认使用第一个地址来连接,如果没有连接成功,则使用下一个地址。所以他是基于连接的failover,仅仅在连接时起作用。

2> 客户端的TAF(transparent application failover):通过tnsnames.ora中的failover_mode参数来控制。

3> 服务器端的TAF:通过service的属性来实现。

 

2. LB

负载均衡的实现也有三种方式:

1> 客户端的基于连接的负载均衡:在tnsnames.ora中通过参数load_balance=on来开启。其实现方式是:将多个连接随机均衡的分配到tnsnames.ora中的多个地址串。所以其实质是session数目的均衡,而不是真实负载的均衡。

2> 服务端的负载均衡:如果是通过DBCA来创建的数据库,则默认是开启了服务端的负载均衡。它是通过pmon进程搜集实例的负载信息。反馈给监听器listener,然后监听器根据自己的负载来选择:连接自己的实例,还是转发请求给其他的监听器。所以监听器可以转发连接请求,我们可以从监听器的日志文件中看到转发动作。另外:最好开启load balancing advisory,不然服务端的负载均衡不是很理想。而开启load balancing advisory要通过service.

3> 基于service的负载均衡:这是oracle所推荐的方式,也应该是我们所选择的方式。
Oracle Net Services provides the ability to balance client connections across the instances in an Oracle RAC configuration. There are two types of load balancing that you can implement: client-side and server-side load balancingClient-side load balancing balances the connection requests across the Listeners. With server-side load balancing, the Listener directs a connection request to the best instance currently providing the service by using the load balancing advisory. In an Oracle RAC database, client connections should use both types of connection load balancing. (server-side load balancing需要load balancing advisory提供的负载信息,所以如果没有开启load balancing advisory,server-side load balancing 十分的不理想,如何开启load balancing advisory,需要使用service的goal属性。)

 

通过上面的分析,我们知道HA和LB都可以通过service方式来实现,而且oracle推荐使用service来配置HA和LB。而且使用service来实现HA和LB,有许多的优点。我们应该很好的掌握service。

 

3. RAC下的service概述

Services—Oracle Database 10g introduces a powerful automatic workload management facility, called services, to enable the enterprise grid vision. Services are entities that you can define in Oracle RAC databases that enable you to group database workloadsand route work to the optimal instances that are assigned to offer the service.

(service是一个十分强大的自动负载管理工具,可以使用service将所有的数据库负载分组,将负载工作路由到提供了制定service的最优的实例上)

When a user or application connects to a database, Oracle recommends that you specify a service in the connect data portion of the connect string. Oracle Database automatically creates one database service when the database is created. For many installations, this may be all you need. To enable more flexibility in the management of the workload using the database, Oracle Database 10g enables you to create multiple services and specify which instances offer the services.
(oracle推荐我们使用service来连接数据库,使用service,创建多个service,指定哪个实例提供该service,可以使我们更好的管理负载)


To manage workloads, you can define services that you assign to a particular application or to a subset of an application's operations. You can also group work by type under services. For example, online users can be a service while batch processing can be another and reporting can be yet another service type.

(oracle推荐的方式是:将不同类型的工作分组,创建对应的service,以这种方式来管理数据库工作负载,可以减少cache funsion相关的等待)

When you define a service, you define which instances normally support that service. These are known as the PREFERRED instances. You can also define other instances to support a service if the service's preferred instance fails. These are known as AVAILABLE instances.
(preferred instance和available instance是两种角色,通过他们可以实现对service的高可用。当preferred instance没有正常运行时,会将对其上提供的service的请求,failover到avaliable instance. 从而继续提供服务。)

When you specify PREFERRED instances, you are specifying the number of instances on which a service will normally run. The Oracle Clusterware attempts to ensure that the service always runs on the number of nodes for which you have configured the service. Afterwards, due to either instance failure or planned service relocations, a service may be running on an AVAILABLE instance. When a service moves to an available instance, Oracle does not move the service back to the PREFERRED instance when the PREFERREDinstance restarts because:

1> The service is already running on the desired number of instances
2> Maintaining the service on the current instance provides a higher level of service availability
3> Not moving the service back to the initial PREFERRED instance prevents a second outage

You can, however, easily automate fail back by using FAN callouts.

 

As mentioned earlier, DBCA creates a default service for your Oracle RAC database and this service is a special Oracle database service. This default service is always available on all instances in an Oracle RAC environment, unless an instance is in restricted mode. You cannot alter this service or its properties. The database also supports the following two internal services:
1> SYS$BACKGROUND is used by the background processes only
2> SYS$USERS is the default service for user sessions that are not associated with any application service

DBCA在RAC环境下创建的默认的service应该是和 sid 名字相同的service,即为RAC数据库对应的每一个实例创建一个默认的同名service


4. service相关之connection load balancing

service可以实现HA和LB,并且是推荐的方式。但是service需要借助一些其他的功能,比如connection lad balancing, load balancing advisory等。service提供了对应的属性来设置。

FAN, FCF, and the load balancing advisory depend on an accurate connection load balancing configuration that includes setting the connection load balancing goal for the service. You can use a goal of either long or short for connection load balancing. (connection load balancing对应在service中的参数为clb_goal)

  • Long—Use the LONG connection load balancing method for applications that have long-lived connections. This is typical for connection pools and SQL*Forms sessions. Long is the default connection load balancing goal. 
    EXECUTE DBMS_SERVICE.MODIFY_SERVICE (service_name => 'POSTMAN' , clb_goal => DBMS_SERVICE.CLB_GOAL_LONG);

  • Short—Use the SHORT connection load balancing method for applications that have short-lived connections.
     EXECUTE DBMS_SERVICE.MODIFY_SERVICE (service_name => 'ORDER' , CLB_GOAL => DBMS_SERVICE.CLB_GOAL_SHORT);


When you create an Oracle RAC database with the Database Configuration Assistant (DBCA), DBCA configures and enables server-side load balancing by default. The DBCA also creates a sample client-side load balancing connection definition in the tnsnames.ora file on the server. Any services created through DBCA have the default setting of CLB_GOAL=CLB_GOAL_LONG. (虽然DBCA提供了clb_goal的默认值,但是默认没有开启load balancing advisory, 也就是说这个server-side load balancing 很不理想。)

 

 

5. service相关之load balancing advisory

Load balancing distributes work across all of the available Oracle RAC database instances. The load balancing advisory provides advice about how to direct incoming work to the instances that provide the optimal quality of service for that work. 

By using the THROUGHPUT or SERVICE_TIME goals, feedback is built in to the system. Work is routed to provide the best service times globally, and routing responds gracefully to changing system conditions. In a steady state, the system approaches equilibrium(接近平衡,从而提高了吞吐量)  with improved throughput across all of the Oracle RAC instances.

The load balancing advisory is deployed with key Oracle clients, such as a Listener, the JDBC Implicit Connection Cache 10g, and the ODP.NET Connection Pool. The load balancing advisory is also open for third party subscription by way of ONS.

You can configure your environment to use the load balancing advisory by defining service-level goals for each service for which you want to enable load balancing. This enables the load balancing advisory for that service and FAN load balancing events are published. There are two types of service-level goals for runtime:

 

  • SERVICE TIME—Attempts to direct work requests to instances according to response time. Load balancing advisory data is based on elapsed time for work done in the service plus available bandwidth to the service.

    EXECUTE DBMS_SERVICE.MODIFY_SERVICE (service_name => 'OE', goal => DBMS_SERVICE.GOAL_SERVICE_TIME);
    
  • THROUGHPUT—Attempts to direct work requests according to throughput. The load balancing advisory is based on the rate that work is completed in the service plus available bandwidth to the service. 

    EXECUTE DBMS_SERVICE.MODIFY_SERVICE (service_name => 'sjob', goal => DBMS_SERVICE.GOAL_THROUGHPUT);
    

 

Setting the goal to NONE disables load balancing for the service. To enable the load balancing advisory, set the GOAL parameter on the service. (service的GOAL参数是load balancing advisory的开关。)

You can see the goal settings for a service in the data dictionary and in the DBA_SERVICES, V$SERVICES, and V$ACTIVE_SERVICES views.

 

6. service相关之FAN(fast application notification)

 

FAN is a notification mechanism that Oracle RAC uses to notify other processes about configuration and service level information such as includes service status changes, such as UP or DOWN events. Applications can respond to FAN events and take immediate action. FAN UP and DOWN events can apply to instances, services, and nodes.(FAN本质就是一个快速的通告机制,通告各种消息,比如HA相关的信息,LB相关的信息等。)

For cluster configuration changes, the Oracle RAC high availability framework publishes a FAN event immediately when a state change occurs in the cluster. Instead of waiting for the application to poll the database and detect a problem, applications can receive FAN events and react immediately.

FAN also publishes load balancing advisory events. Applications can take advantage of the load balancing advisory FAN events to direct work requests to the instance in the cluster that is currently providing the best service quality. You can take advantage of FAN events in the following three ways:

  1. Your application can use FAN without programmatic changes if you use an integrated Oracle client. The integrated clients for FAN events include Oracle Database 10g JDBC(Oracle Database 10g Release 2 is required for load balancing), Oracle Database 10gRelease 2 ODP.NET, and Oracle Database 10g Release 2 OCI. This includes applications that use TAF.

  2. Applications can use FAN programmatically by using the ONS Application Programming Interface (API) to subscribe to FAN events and to execute event handling actions upon the receipt of an event.

  3. You can implement FAN with server-side callouts on your database tier.

For DOWN events, the disruption to the application can be minimized because sessions to the failed instance or node can be terminated. Incomplete transactions can be terminated and the application user is immediately notified. Application users who request connections are directed to available instances only. For UP events, when services and instances are started, new connections can be created so that the application can immediately take advantage of the extra resources. 

 

 

FAN events are published using ONS and an Oracle Streams Advanced Queuing. The publication mechanisms are automatically configured as part of your Oracle RAC installation. (FAN依赖于ONS或者aq来提供服务。)

The Connection Manager (CMAN) and Oracle Net Services Listeners are integrated with FAN events. This enables the Listener and CMAN to immediately de-register services provided by the failed instance and to avoid erroneously sending connection requests to failed instances.

If you use the service goal CLB_GOAL_SHORT, then the Listener uses the load balancing advisory when the Listener balances the connection loads. When load balancing advisory is enabled, the metrics used for the Listener are finer grained.

 

小结:

service以及相关的组件,对于RAC实现HA和LB都十分重要,而且是oracle推荐的方法。service针对LB有两个参数来配置:goal来配置load balancing advisory; clb_goal来配置connection load balancing. 而FAN是为RAC的HA和LB以及其他功能来提供快速的消息通告这一基础服务的。

下一篇博文主要来具体剖析service,以及service对于HA的相关配置。

 

 

在前一篇博文中http://blog.chinaunix.net/uid-25909722-id-3489695.html,我们初略的描述了RAC的两大关键特性HA和LB,以及他们的各种配置方法。而且对service进行了总体的概述,并对service相关的connection load balancing, load balancing advisory, FAN等LB属性进行了学习。oracle推荐使用service来进行负载管理,使用service来配置HA和LB。本文主要来剖析service,学习service具有的所有属性。包括HA相关的属性,以及分布式事务相关属性。

1. service属性具体剖析

When you create and administer services, you are dividing the work that your database performs into manageable units

When you create new services for your database, you should define each service's workload management characteristics. The characteristics of a service include:

  • A unique global name to identify the service. (全局唯一的服务名)

  • A Net Service name that a client uses to connect to the service.(网络服务名,在tnsnames.ora中用于客户端发起连接)

  • The preferred instances where you want the service to be enabled in a normal running environment.(提供service的首选实例)

  • The available instances where the service can be enabled if one of the preferred instances fails.(提供service的备用实例)

  • A service goal that determines whether connections are made to the service based on best service quality (how efficiently a single transaction completes) or best throughput (how efficiently a complete job or long-running query completes), as determined by the load balancing advisory.(load balancing advisory的使用的来进行负载均衡度量)

  • An indicator that determines whether the service is used for distributed transactions.(一个service是否可以进行分布式事物的标记)

  • An indicator that determines whether Oracle RAC high availability events are sent to OCI and ODP.NET clients that have registered to receive them through Advanced Queuing.(FAN是否可以使用AQ的标记)

  • The characteristics of session failovers such as whether failovers occur, whether sessions can use pre-existing connections on the failover instance, and whether failed over sessions can continue to process interrupted queries. The service definition can also define the number of times that a failed session attempts to reconnect to the service and how long it should wait between reconnection attempts. The service definition can also include a connection load balancing goal that informs the Listener how to balance connection requests across the instances that provide the service. (service中的failover相关的属性)

  • The method for load balancing connections for each service. This method is used by the Listener when Oracle creates connections. Connections are classified as LONG (such as connection pools and SQL*FORMS) which tells the Listener to use session based, or SHORT which tells the Listener to use CPU based. If load balancing advisory is enabled, its information will be use to balance connections otherwise CPU utilization is used.(service中的connection load balancing相关的属性)

service的具体属性如下:
The CREATE_SERVICE procedure adds a new service to the Oracle RAC database. 
In the CREATE_SERVICE syntax:
service_name is the unique, global service name, 
network_name is the TNS name for connections to the service, 
goal sets the workload management goal directive to service quality or throughput, 
dtp is the distributed transaction flag, 
aq_ha_notification is the flag to send Oracle RAC high availability events to registered OCI clients, failover_method is the TAF failover method for the service, 
failover_type is the TAF failover method for the service, 
failover_retries is the TAF connection retry count, 
failover_delay is the wait time between TAF connection retries, and 
clb_goal sets the connection load balancing goal. 
When using services with Oracle RAC, add the high availability properties, such as the PREFERRED and AVAILABLE placement, using Enterprise Manager, DBCA or SRVCTL.

service的这些属性可以分为几类:

1> service的两个名字,service_name和net_service_name;

2> service的LB相关的两个goal:connection load balancing和load balancing advisory

3> service的HA相关的4个failover属性;

4> service的HA相关的提供服务的实例:prefered instance和available instance;

5> dtp分布式属性;
You can create and administer services with Enterprise Manager, DBCA, and the DBMS_SERVICE PL/SQL package, and you can perform most service administration tasks with the SRVCTL utility. 

2. service之DTP(distributed transaction processing)

 

All tightly coupled branches of a distributed transaction running on an Oracle RAC database must run on the same instance. 

In addition, connection pools at the application server tier that load balance across multiple connections to an Oracle RAC database must ensure that all tightly-coupled branches of a global distributed transaction run on only one Oracle RAC instance. This is also true in distributed transaction environments using protocols such as X/Open Distributed Transaction Processing (DTP) or the Microsoft Distributed Transaction Coordinator (DTC).

To simplify the deployment of distributed transactions, you can use services to manage DTP environments. By defining the DTP property of a service, the service is guaranteed to run on one instance at a time in an Oracle RAC database. All global distributed transactions performed through the DTP service are ensured to have their tightly-coupled branches running on a single Oracle RAC instance. This preserves the integrity for distributed transactions.

To leverage all of the instances in a cluster, create one or more DTP services for each Oracle RAC instance that hosts distributed transactions. Choose one DTP service for one distributed transaction. Choose different DTP services for different distributed transactions to balance the workload among the Oracle RAC database instances. 

For services that you are going to use for distributed transaction processing, create the service using Enterprise Manager, DBCA, or SRVCTL and define only one instance as the preferred instance. You can have as many AVAILABLE instances as you want.

 

 

http://blog.chinaunix.net/uid-25909722-id-3489826.html

posted @ 2018-03-16 14:28  dion至君  阅读(776)  评论(0编辑  收藏  举报