Chinaunix首页 | 论坛 | 博客
  • 博客访问: 38634
  • 博文数量: 28
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 0
  • 用 户 组: 普通用户
  • 注册时间: 2013-11-23 14:14
文章分类

全部博文(28)

文章存档

2014年(1)

2013年(27)

我的朋友

分类: Oracle

2013-11-26 16:57:09

我们都知道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 balancing. Client-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 workloads and 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 PREFERRED instance 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 10g Release 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的相关配置。



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