天天看点

RAC的GES/GCS原理(2)

资源的概念:

资源是内存结构,这些结构代表了数据库中的组件,对这些组件的访问必须为限制模式或者串行化模式。换一句话说,这个资源只能被一个进程或者一直实例并行访问。如果这个资源当前是处于使用状态,其他想访问这个资源的进程必须在队列中等待,直到资源变得可用。

队列是内存结构,它负责并行化对特殊资源的访问。如果这些资源只被本地实例需求,那么这个队列可以本地来获得,而且不需要协同。但是如果这个资源被远程实例所请求,那么本地队列必须变成全球化。

优化全局队列

全局锁将明显的影响性能,这将造成增加的等待次数,甚至是死锁。然而,一些简单的方法能够极大地减小全局锁的影响。

很多全局锁与分析活动有关,因此,你应该随处避免不必要的解析。有很多种方式可以达到这个目的。在OLTP 环境中,文字应该被绑定变量所替代。这个置换方式实现的最好方式是修改源代码。但是,如果你没有访问源代码的权限,也许你可以考虑使能游标共享,这可以达到一样的目的,但会增加轻微的额外开销,因为在数据库中每个被执行的语句必须被做为文字的扫描,然后再做语句的解析。

PL/SQL 将包含一系列的优化策略,目的是提升性能。比如,当一个语句执行完毕之后,pl/sql 不会关闭游标。替代的是,它将高效的把游标放在一个池里,以备他们被再次需要,这种情况下,如果近期这个语句被再次执行可以避免再次做重复的软解析。如果你用C或者JAVA来开发应用,你可以把上面的信息保留下来并因此减少被解析的量。

另一种减少解析的方式是优化library cache的大小,减少发生这种情况游标的个数,这些游标从cache中age out之后很快又被reloaded。你可以把常用的包以及游标 pin到内存中,这样来提高数据库的效率。

你也应该尝试从你的应用移除不必要的DDL语句。最常见的原因是,在复杂的步骤中,有中间步骤需要建立临时表,这些步骤包括报告或者批量子进程。这些表可以经常被全局临时表所代替。

最终,减少全局enqueue 的一个方式是执行更少的SQL语句,要达到这个效果,我们可以通过减少不必要的语句来实现。它也可以通过合并存在的SQL语句来实现。

比如说,使用UNION ALL.而且,我们也值得花时间检查下你的应用逻辑,确认是否正在被周期的执行的sql语句能够被作为一个集合操作执行。比如说,你可能能够修改一个sql语句,这个语句能够使用一条语句一次更新所有的行,代替老的单命令语句100次更新语句。

英文/翻译

Resources and Enqueues

A resource is a memory structure that represents some component of the database to which access must be restricted

or serialized.In other words,the resource can only be accessed by one process or one instance concurrently.If the

resource is currently in use,other processes or instances needing to access the resource must wait in a queue until

the resource becomes available.

资源是内存结构,这些结构代表了数据库中的组件,对这些组件的访问必须为限制模式或者串行化模式。换一句话说,这个资源只能被一个进程或者一直实例并行访问。如果这个资源当前是出于使用状态,其他想访问这个资源的进程必须在队列中等待,直到资源变得可用。

An enqueue is a memory structure that serializes access to particular resource.If the resource is only required

by the local instance,then the inqueue can be acquired locally,and no coordination is necessary.However,if the

resource is required by a remote instance,then the local enqueue must become global.

队列是内存结构,它负责并行化对特殊资源的访问。如果这些资源只被本地实例需求,那么这个队列可以本地来获得,而且不需要协同。但是如果这个资源被远程实例所请求,那么本地队列必须变成全球化。

优化全局队列:

Optimizing Global Enqueues

Global locking can significantly impact performance causing increased wait times and possibly even dead locks.

However,a few simple measures can greatly reduce the impact of global locking.

全局锁将明显的影响性能,这将造成增加的等待次数,甚至是死锁。然而,一些简单的方法能够极大地减小全局锁的影响。

Much global locking is related to parsing activity.Therefore ,you should avoid unnecessory parsing wherever possible.

There are many ways to archive this.

很多全局锁与分析活动有关,因此,你应该随处避免不必要的解析。有很多种方式可以达到这个目的。

In OLTP environments,literals should be replaced by bind variables.This replacement is best archived by modifying

the source code.

在OLTP 环境中,文字应该被绑定变量所替代。这个置换方式实现的最好方式是修改源代码。

Howerver,if you do not have access to the source code,you might consider enabling cursor sharing,which archives the

same goal but incurs a slight overhead,as the text of every statement executed in the database must be scanned for

literals  before the statement is parsed.

但是,如果你没有访问源代码的权限,也许你可以考虑使能游标共享,这可以达到一样的目的,但会增加轻微的额外开销,因为在数据库中每个被执行的语句必须被做为文字的扫描,然后再做语句的解析。

PL/SQL contains a number of optimazions aimed at improving performance.For example,it does not close cursors when a

statement completes.Instead,it effectively retains cursors in a pool in case they are needed again,which avoids the

need to perform a soft parse if the cursor is executed again in the near future.If you develop your own applications in

C or Java,you can copy this behavior and thereby reduce the amount of parsing required.

PL/SQL 将包含一系列的优化策略,目的是提升性能。比如,当一个语句执行完毕之后,pl/sql 不会关闭游标。替代的是,它将高效的把游标放在一个池里,以备他们被再次需要,这种情况下,如果近期这个语句被再次执行可以避免再次做重复的软解析。如果你用C或者JAVA来开发应用,你可以把上面的信息保留下来并因此减少被解析的量。

Another way to reduce parsing is simply to optimize the size of the library cache to reduce the number of cursors

that are aged out of the cache and subsequently reloaded.You may also benifit from pinning commonly used packages

and cursors in memory.

另一种减少解析的方式是优化library cache的大小,减少发生这种情况游标的个数,这些游标从cache中age out之后很快又被reloaded。你可以把常用的包以及游标 pin到内存中,这样来提高数据库的效率。

You shoud also attempt to remove unnecessary DDL statements from your application.The most common cause of these

is the creation of temporary tables for intermediate steps in complex tasks,such as reports and batch processes.

These tables can often be replaced by global temporary tables.

你也应该尝试从你的应用移除不必要的DDL语句。最常见的原因是,在复杂的步骤中,有中间步骤需要建立临时表,这些步骤包括报告或者批量子进程。这些表可以经常被全局临时表所代替。

Finally,the impact of global enqueue can be reduced by simply executing fewer SQL statements,which can often be

archived by eliminating unnecessary statements.It can also be archived by combining existing SQL statements.

最终,减少全局enqueue 的一个方式是执行更少的SQL语句,要达到这个效果,我们可以通过减少不必要的语句来实现。它也可以通过合并存在的SQL语句来实现。

for example,using a UNION ALL .It is also worth examining your application logic to establish whether statements

that are being executed procedurally(ie,row by row)could be executed as a set operation.For example,you might be

able to replace 100 single-row update statements with a single statement that updates all rows at the same time.

比如说,使用UNION ALL.而且,我们也值得花时间检查下你的应用逻辑,确认是否正在被周期的执行的sql语句能够被作为一个集合操作执行。比如说,你可能能够修改一个sql语句,这个语句能够使用一条语句一次更新所有的行,代替老的单命令语句100次更新语句。