7. Services
Traditional Workload Dispatching
传统模式下,每个应用被永久性地分配到一部分相对独立的资源,这些分配到的资源必须分别满足每个应用的峰值需求。由于应用的峰值时段一般只持续几小时,因此在绝大多数时间中,大量资源处于浪费状态。
Grid Workload Dispatching
在网格计算环境下,由一个全局的资源池同时对多个应用提供使用,在不同的应用间计算单元可被动态地分配和调整。
What Is a Service?
• Is a means of grouping sessions that are doing the same kind of work
可将完成同一种工作的会话分组
• Provides a single-system image instead of a multipleinstances image
提供一种单一系统的映像(可以跨多个实例)
• Is a part of the regular administration tasks that provide dynamic service-to-instance allocation
可动态增加或减少支持该service的instance
• Is the base for High Availability of connections
高可用性连接的基础元素
• Provides a new performance-tuning dimension
提供一种新的性能调优角度
High Availability of Services in RAC
• Preferred instances:
– Set the initial cardinality for the service – 设置支持service的instance的初始基数
– Are the first to start the service – 在启动service时即启动
• Available instances are used in response to preferredinstance failures.
相关的HA配置信息存储在OCR中
Possible Service Configuration with RAC
• Active/spare – N+M,M个空闲实例为多个service提供failover功能
• Active/symmetric – 各service在所有节点上均匀分布
• Active/asymmetric – 根据负载将各service在所有节点上作不对等的分布
Service Attributes
• Global unique name
• Network name
• Load Balancing Advisory goal*
• Distributed transactions flag*
• Advance queuing notification characteristics for OCI and ODP.NET clients*
• Failover characteristics*
• Connection load-balancing algorithm*
• Threshold
• Priority
• High-availability configuration*
clb_goal: 确认使用connection数或者使用LBA来进行负载均衡(short or long)
LBA goal: LBA使用的负载均衡策略
Service Types
• Application services – 上限为100,服务名长度不能超过64个字符
• Internal services:
– SYS$BACKGROUND
– SYS$USERS
– Cannot be deleted or changed
Service Goodness – 评价service运行情况的性能指标,由MMNL进行根据service metrics进行计算。使用的metrics由不同的service goal决定。
Create Services with the DBCA
使用DBCA,可添加、删除服务,配置prefer和available实例以及TAF。DBCA配置CRS resource,也配置net service服务名。
实验:在动态注册的情况下,启动一个服务,会在实例的service_names变量中添加这个服务名,在关闭实例的时候再去掉这个实例名。
Create Services with Enterprise Manager
使用EM添加、删除服务及配置服务属性。但不再tnsnames.ora文件中添加网络服务名。
Create Services with SRVCTL
使用srvctl add/remove service命令添加/删除服务。可配置prefer和available instance及TAF。(经实验,一定要使用oracle用户来创建服务,否则服务可能无法正常启动)
Modify Services with the DBMS_SERVICE Package
使用dbms_service包修改service的一些属性(dbca或EM无法修改),但由于未和clusterware进行整合,因此无法设置prefer或available的instance。可用于非rac环境创建和删除实例。还可将连接到某个实例及某个服务的所有会话断开。
Everything Switches to Services
• Data dictionary maintains services. – service相关的统计信息
• The AWR measures the performance of services.
• The Database Resource Manager uses services in place of users for priorities.
• Job scheduler, Parallel Query (PQ), and Streams queues run under services.
• RAC keeps services available within a site.
• Data Guard Broker with RAC keeps primary services available across sites.
Use Services with Client Applications
通过在tns设置中将connect_data配置为service,即可连接到特定的service。
Use Services with the Resource Manager
使用service来进行consumer group的映射。当连接建立时,根据会话连接的service自动分配consumer group。可用于管理service间的优先级和资源使用限制。
Use Services with the Scheduler
当创建一个job class时,为其指定service。则该class中的所有作业都运行在该service下。这样设置便于进行一些工作负载管理以及性能调优。同时,把一个job class与service关联起来而不是与一个特定的instance关联起来,有助于提升高可用性以及更好地进行负载均衡。
instance_stickiness – job的属性。设置为true倾向于采用负载均衡的策略选择job运行的实例。
Use Services with Parallel Operations
在并行查询或并行DML中,slave可在一个不支持coordinator所属service的实例上运行,当并行操作执行完成后,该slave自动恢复为默认service。
Use Services with Metric Thresholds
Two service-level thresholds
– ELAPSED_TIME_PER_CALL
– CPU_TIME_PER_CALL
React on generated alerts
– Change priority.
– Relocate services.
– Add instances for services.
如使用dbms_server_alert来设置metric thresholds,则每个intance都需要设置thresholds。
Service Aggregation and Tracing
• Statistics can be aggregated at finer levels: - service一级的统计信息默认收集
– MODULE
– ACTION
– Combination of SERVICE_NAME, MODULE, ACTION
• Tracing can be done at various levels:
– SERVICE_NAMES
– MODULE
– ACTION
– Combination of SERVICE_NAME, MODULE, ACTION
在shared server模式下,service/module/action一级的信息收集对问题分析有较大用处。
Service_name - 登陆时设置;MODULE&ACTION – 使用dbms_application_info包或OCI调用在应用中设置。可使用DBMS_MONITOR包配置统计信息收集和trace。统计信息收集为数据库一级的操作,实例重启后设置仍然生效。Trace收集默认收集所有instance,但也可指定特定的instance。
Trcsess Utility – 可通过session ID、client ID、service name、action name、module name等对trace文件进行筛选,可将多个文件合并成单个trace文件,使用tkprof工具阅读。
Manage Services
• Use EM or SRVCTL to manage services:
Start/stop/enable/disable/relocate/modify/get status info/add/remove
• Use the DBCA :
Add/remove/modify(prefer/available/TAF)
服务必须enable后才能启动。Disable服务可避免不必要的自动重启。
Relocate – 临时将服务从一个节点移到另一个节点。这个操作会强制中断原节点所有与该服务相连的会话。
Using Distributed Transactions with RAC
在RAC环境下支持分布式事务时,如同一事务的两部分被分配到不同实例执行,可能会产生数据不一致、死锁等问题。解决方法为将service的 DTP属性置为true。支持分布式事务的service只能有一个prefer的节点。
Restricted Session and Services
当一个节点起到restricted session模式时,(1) 有restricted session权限的用户也只能从本地连接实例;(2) 如为动态注册,listener把该节点排除在负载均衡策略之外。如为静态注册,无法将其排除在负载均衡之外,可能会造成该实例成为cluster中最为空闲的实例,大量连接被发送到该实例后又被拒绝,造成应用堵塞。
8. High Availability of Connections
Types of Workload Distribution
Connection balancing is rendered possible by configuring multiple listeners on multiple nodes:
– Client-side connect-time load balancing
– Client-side connect-time failover
– Server-side connect-time load balancing
Run-time connection load balancing is rendered possible by using connection pools
Client-Side Connect-Time Load Balancing
客户端发起连接时随机选择一个地址
ERP =
(DESCRIPTION =
(ADDRESS_LIST =
(LOAD_BALANCE=ON)
(ADDRESS=(PROTOCOL=TCP)(HOST=node1vip)(PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=node2vip)(PORT=1521))
)
(CONNECT_DATA=(SERVICE_NAME=ERP)))
Client-Side Connect-Time Failover
客户端连接一个地址失败后尝试其他地址。配置vip后,可避免等待TCP/IP超时。
ERP =
(DESCRIPTION =
(ADDRESS_LIST =
(LOAD_BALANCE=ON)
(FAILOVER=ON)
(ADDRESS=(PROTOCOL=TCP)(HOST=node1vip)(PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=node2vip)(PORT=1521))
)
(CONNECT_DATA=(SERVICE_NAME=ERP)))
静态注册global dbname(在listener.ora文件中设置GLOBLE_DBNAME)会使connect_time failover disable掉。
Server-Side Connect-Time Load Balancing
Spfile:
*.REMOTE_LISTENER=RACDB_LISTENERS
Server-Side tnsnames.ora:
RACDB_LISTENERS=
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=node1vip)(PORT=1521))
(ADDRESS=(PROTOCOL=tcp)(HOST=node2vip)(PORT=1521)))
使用动态服务注册允许PMON进程将service的运行情况提供给listener,以便进行负载均衡。
remote_listener – 列出了配置中所有的listener
local_listener – 设置后使得动态注册可以注册到非1521端口的监听
Fast Application Notification: Overview
使用FAN event在failure发生时对应用进行快速提醒。已被整合到多种客户端中。
Fast Application Notification: Benefits
• No need for connections to rely on connection timeouts
• Used by Load Balancing Advisory to propagate load information
• Designed for enterprise application and management console integration
• Reliable distributed system that:
– Detects high-availability event occurrences in a timely manner
– Pushes notification directly to your applications
• Tightly integrated with:
– Oracle JDBC applications using connection pools
– Enterprise Manager
– Data Guard Broker
FAN-Supported Event Types
SERVICE
SRV_PRECONNECT
SERVICEMEMBER
DATABASE
INSTANCE
ASM
NODE
SERVICE_METRICS
FAN Event Status
Up/down/preconn_up/preconn_down/nodedown/not_restarting/restart_failed/Unknown
FAN Event Reasons
User/failure/dependency/unknown/autostart/Boot
FAN Event Format
VERSION=
[service=]
[database=] [instance=]
[host=]
status=
reason=
[card=]
timestamp=
Load Balancing Advisory: FAN Event
Event type为SERVICE_METRICS,计算应该分配给每个instance的request百分比。
Server-Side Callouts Implementation
/racg/usrco目录下,每次接受到FAN event时该目录下有执行权限的脚本或程序均会执行,执行顺序不确定。出于安全考虑,该目录下所有文件写权限只能授予cluster owner。
• Writing callouts involves:
1. Parsing callout arguments: The event payload
2. Filtering incoming FAN events
3. Executing event-handling programs
Configuring the Server-Side ONS
ONS配置文件路径:/opmn/conf/ons.config
三个参数:localport/remoteport/nodes
如使用ocr的配置,则在文件中设置useocr=on。通过racgons命令配置。
Optionally Configure the Client-Side ONS
在client端,10.1版本需要安装ons并起daemon。10.2版本只需调用API即可。
JDBC Fast Connection Failover: Overview
FCF与JDBC ICC共同使用,用于对中断的连接进行快速自动恢复。当某个节点的服务down时,event handler自动清理无用当的连接。当新的节点启动服务时,event handler回收部分未使用的连接并重新创建连接。由于listener的负载均衡机制达到连接在多个节点上的均匀分布。
使用本地或远程ONS接收FAN event可支持JDBC thin以及OCI drivers
使用AQ发布FAN event可支持ODP.NET或OCI
Using Oracle Streams Advanced Queuing for FAN
使用dbms_service.modify_service打开设置
exec DBMS_SERVICE.MODIFY_SERVICE (
service_name => 'SELF-SERVICE', aq_ha_notification => TRUE);
通过DBA_OUTSTANDING_ALERTS视图查看FAN events。
JDBC/ODP.NET FCF Benefits
自动负载均衡connections和requests(使用哪个连接进行工作)、连接预先建立、失败的连接可被立刻检测和清除。
Load Balancing Advisory
LBA – 一个advisory,可用于各种传递连接请求的客户端。对如何在各节点间均衡分配工作任务给出建议。
The Load Balancing Advisory is deployed with Oracle’s key clients, such as Connection Load Balancing, JDBC Implicit Connection Cache, OCI Session Pool, Oracle Data Provider (ODP) Connection Pool for .NET, and is open for third-party subscription via ONS.
JDBC/ODP.NET Runtime Connection Load Balancing: Overview
通过使用LBA,可根据各节点间服务运行情况来分配工作(在连接池中将工作分配给已建立的连接),实时进行负载均衡。
Connection Load Balancing in RAC
根据不同的clb_goal,使用不同的metrics作为connection load balancing的依据。
• Session count by instance - clb_goal=LONG
• Run queue length of the node - clb_goal=SHORT & goal= DBMS_SERVICE.GOAL_NONE
• Goodness by service – clb_goal=SHORT
Load Balancing Advisory: Summary
• Uses DBMS_SERVICE.GOAL
– Service time: weighted moving average of elapsed time
– Throughput: weighted moving average of throughput
• AWR
– Calculates goodness locally (MMNL), forwards to master MMON
– Master MMON builds advisory for distribution of work across RAC, and posts load balancing advice to AQ
– IMON retrieves advice and send it to ONS
– EMON retrieves advice and send it to OCI
– Local MMNL post goodness to PMON
• Listeners use DBMS_SERVICE.CLB_GOAL=SHORT
– Use goodness from PMON to distribute connections.
• Load Balancing Advisory users (inside the pools)
– Use percentages and flags to send work.
Monitor LBA FAN Events
SQL> SELECT TO_CHAR(enq_time, 'HH:MI:SS') Enq_time, user_data
2 FROM sys.sys$service_metrics_tab
3 ORDER BY 1 ;
Transparent Application Failover: Overview
TAF提供一种功能,使得应用在初始连接中断后自动重连。活动事务被回滚,但查询可以继续执行(可选)。
TAF提供两种failover的方式:
Basic: 在failover时创建连接
Preconnect: 为初始连接维护一个shadow connection,在failover时使用这个提前创建的连接。
TAF Basic Configuration Without FAN: Example
$ srvctl add service -d RACDB -s AP -r I1,I2 -P BASIC
$ srvctl start service -d RACDB -s AP
AP =
(DESCRIPTION =(FAILOVER=ON)(LOAD_BALANCE=ON)
(ADDRESS=(PROTOCOL=TCP)(HOST=N1VIP)(PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=N2VIP)(PORT=1521))
(CONNECT_DATA =
(SERVICE_NAME = AP)
(FAILOVER_MODE =
(TYPE=SESSION)
(METHOD=BASIC)
(RETRIES=180)
(DELAY=5))))
TYPE - SESSION/SELECT
TAF Basic Configuration with FAN: Example
10.2版本中提供,可使用dbms_service包在server端配置TAF,客户端连接串无须配置failover_mode。
TAF Preconnect Configuration: Example
$ srvctl add service -d RACDB -s ERP -r I1 –a I2 -P PRECONNECT
$ srvctl start service -d RACDB -s ERP
ERP =
(DESCRIPTION =(FAILOVER=ON)(LOAD_BALANCE=ON)
(ADDRESS=(PROTOCOL=TCP)(HOST=N1VIP)(PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=N2VIP)(PORT=1521))
(CONNECT_DATA = (SERVICE_NAME = ERP)
(FAILOVER_MODE = (BACKUP=ERP_PRECONNECT)
(TYPE=SESSION)(METHOD=PRECONNECT))))
ERP_PRECONNECT =
(DESCRIPTION =(FAILOVER=ON)(LOAD_BALANCE=ON)
(ADDRESS=(PROTOCOL=TCP)(HOST=N1VIP)(PORT=1521))
(ADDRESS=(PROTOCOL=TCP)(HOST=N2VIP)(PORT=1521))
(CONNECT_DATA = (SERVICE_NAME = ERP_PRECONNECT)))
Shadow service自动命名为_PRECONNECT。
TAF Verification
SELECT machine, failover_method, failover_type, failed_over, service_name, COUNT(*)
FROM v$session
GROUP BY machine, failover_method, failover_type, failed_over, service_name;
FAN Connection Pools and TAF Considerations
• Both techniques are integrated with services and provide service connection load balancing.
• Do not use FCF when working with TAF, and vice versa. - 两者无法同时使用
• Connection pools that use FAN are always preconnected.
• TAF may rely on operating system (OS) timeouts to detect failures.
• FAN never relies on OS timeouts to detect failures.
[@more@]来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8558093/viewspace-1016290/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/8558093/viewspace-1016290/