Oracle RAC 和序列

发布于 2024-10-15 19:29:53 字数 157 浏览 4 评论 0原文

我有各种使用序列的数据库应用程序,我正在将这些应用程序从不带 RAC 的 10g 迁移到带 RAC 的 11g。我需要有序的序列并且可以容忍间隙。

我正在考虑按顺序进行缓存序列,我不知道对性能有何影响。您认为这是一个好的选择吗?您对序列和 RAC 有什么经验?

谢谢,

I have various database applications that use sequences, I´m migrating these applications to Oracle RAC from 10g without RAC to 11g with RAC. I need ordered sequences and gaps are tolerated.

I'm thinking in cache sequences with order, I don´t know what are the effect in performance. Do you think this is a good option? What are your experience with sequences and RAC?

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

掐死时间 2024-10-22 19:29:53

在这种情况下,“有序”到底是什么意思?

默认情况下,集群中的每个节点都有一个单独的序列号缓存。因此,节点 1 可能正在分发值 1-100,而节点 2 可能正在分发值 101-200。从单个节点返回的值是连续的,但节点 1 上的会话 A 可能会得到值 15,而节点 2 上的会话 B 会得到值 107,因此跨会话返回的值看起来是无序的。

如果您指定必须对序列进行排序,那么您基本上就违背了序列缓存的目的,因为 Oracle 现在必须在每次请求新序列值时在节点之间进行通信。这有可能产生相当大的性能开销。如果您使用该序列作为一种时间戳,则该开销可能是必要的,但通常并不可取。

实际上,开销差异将高度依赖于应用程序——对于某些应用程序来说,开销差异将小得无法测量,而对于其他应用程序来说,开销差异将是一个重大问题。 RAC 节点的数量、互连的速度以及互连流量的多少也会有所贡献。由于这主要是一个可扩展性问题,因此实际效果将限制应用程序的扩展程度,这本质上是非线性的。将应用程序处理的交易量加倍将导致开销增加一倍以上。

如果指定NOCACHE,则选择ORDER或NOORDER基本上是无关紧要的。如果指定ORDER,则选择CACHE或NOCACHE基本上是无关紧要的。所以CACHE NOORDER是目前为止效率最高的,其他三个相对来说是可以互换的。每次您请求序列值时,它们都会涉及节点间协调和网络流量,这显然是潜在的瓶颈。

通常最好在表中添加 TIMESTAMP 列来存储实际时间戳,而不是依赖序列来提供时间戳顺序。

Exactly what do you mean by "ordered" in this context?

By default, each node in the cluster has a separate cache of sequence numbers. So node 1 may be handing out values 1-100 while node 2 is handing out values 101-200. The values returned from a single node are sequential, but session A on node 1 may get a value of 15 while session B on node 2 gets a value of 107 so the values returned across sessions appear out of order.

If you specify that the sequence has to be ordered, you're basically defeating the purpose of the sequence cache because Oracle now has to communicate among nodes every time you request a new sequence value. That has the potential to create a decent amount of performance overhead. If you're using the sequence as a sort of timestamp, that overhead may be necessary but it's not generally desirable.

The overhead difference in practical terms is going to be highly application dependent-- it will be unmeasurably small for some applications and a significant problem for others. The number of RAC nodes, the speed of the interconnect, and how much interconnect traffic there is will also contribute. And since this is primarily a scalability issue, the practical effect is going to limit how well your application scales up which is inherently non-linear. Doubling the transaction volume your application handles is going to far more than double the overhead.

If you specify NOCACHE, the choice of ORDER or NOORDER is basically irrelevent. If you specify ORDER, the choice of CACHE or NOCACHE is basically irrelevent. So CACHE NOORDER is by far the most efficient, the other three are relatively interchangable. They are all going to involve inter-node coordination and network traffic every time you request a sequence value which is, obviously, a potential bottleneck.

It would generally be preferrable to add a TIMESTAMP column to the table to store the actual timestamp rather than relying on the sequence to provide a timestamp order.

臻嫒无言 2024-10-22 19:29:53

摘要

CACHE 可以显着提高使用 ORDER 的序列的性能,即使在 RAC 上也是如此。

它仍然不如 NOORDER 快,但已经非常接近了。特别是如果该序列一次仅在一个节点上使用。

测试用例

SQL> create sequence cache_order cache 20 order;

Sequence created.

SQL> create sequence cache_noorder cache 20 noorder;

Sequence created.

SQL> create sequence nocache_order nocache order;

Sequence created.

SQL> create sequence nocache_noorder nocache noorder;

Sequence created.

SQL> set timing on
SQL> declare
  2     v_temp number;
  3  begin
  4     for i in 1 .. 100000 loop
  5             v_temp := cache_order.nextval;
  6     end loop;
  7  end;
  8  /

PL/SQL procedure successfully completed.

Elapsed: 00:00:08.44
SQL> declare
  2     v_temp number;
  3  begin
  4     for i in 1 .. 100000 loop
  5             v_temp := cache_noorder.nextval;
  6     end loop;
  7  end;
  8  /

PL/SQL procedure successfully completed.

Elapsed: 00:00:07.46
SQL> declare
  2     v_temp number;
  3  begin
  4     for i in 1 .. 100000 loop
  5             v_temp := nocache_order.nextval;
  6     end loop;
  7  end;
  8  /

PL/SQL procedure successfully completed.

Elapsed: 00:00:35.15
SQL> declare
  2     v_temp number;
  3  begin
  4     for i in 1 .. 100000 loop
  5             v_temp := nocache_noorder.nextval;
  6     end loop;
  7  end;
  8  /

PL/SQL procedure successfully completed.

Elapsed: 00:00:35.10

测试用例说明

我的结果是在 2 节点 RAC 上获得的。仅显示一个结果集,但我在不同的数据库上多次运行测试用例,并获得几乎相同的结果。

我还在不同的节点上同时运行了测试。尽管 CACHE NOORDER 的速度是 CACHE ORDER 的两倍多,但 CACHE 仍然显着改进了 ORDER

我过去也注意到其他环境中的类似行为,尽管我没有得到任何结果。

为什么?

我不明白为什么使用 ORDERCACHE 会产生如此大的差异。与通过网络发送数据的时间相比,生成数字的时间应该是无关紧要的。这让我认为要么 Oracle 使用了糟糕的算法,要么我的测试用例是错误的。 (如果有人发现我的测试用例存在问题,请告诉我。)

此外,这个答案仅讨论生成序列的时间。使用 NOORDER 可能还有其他好处。例如,减少索引争用,如此处所述。

Summary

CACHE can significantly improve the performance of a sequence that uses ORDER, even on RAC.

It's still not as fast as NOORDER, but it can be surprisingly close. Especially if the sequence is only used on one of the nodes at a time.

Test Case

SQL> create sequence cache_order cache 20 order;

Sequence created.

SQL> create sequence cache_noorder cache 20 noorder;

Sequence created.

SQL> create sequence nocache_order nocache order;

Sequence created.

SQL> create sequence nocache_noorder nocache noorder;

Sequence created.

SQL> set timing on
SQL> declare
  2     v_temp number;
  3  begin
  4     for i in 1 .. 100000 loop
  5             v_temp := cache_order.nextval;
  6     end loop;
  7  end;
  8  /

PL/SQL procedure successfully completed.

Elapsed: 00:00:08.44
SQL> declare
  2     v_temp number;
  3  begin
  4     for i in 1 .. 100000 loop
  5             v_temp := cache_noorder.nextval;
  6     end loop;
  7  end;
  8  /

PL/SQL procedure successfully completed.

Elapsed: 00:00:07.46
SQL> declare
  2     v_temp number;
  3  begin
  4     for i in 1 .. 100000 loop
  5             v_temp := nocache_order.nextval;
  6     end loop;
  7  end;
  8  /

PL/SQL procedure successfully completed.

Elapsed: 00:00:35.15
SQL> declare
  2     v_temp number;
  3  begin
  4     for i in 1 .. 100000 loop
  5             v_temp := nocache_noorder.nextval;
  6     end loop;
  7  end;
  8  /

PL/SQL procedure successfully completed.

Elapsed: 00:00:35.10

Test Case Notes

My results were obtained on a 2-node RAC. Only one result set is shown, but I ran the test case multiple times, on different databases, and obtained almost identical results.

I also ran the tests concurrently, on different nodes. The CACHE still significantly improves ORDER, although the CACHE NOORDER is more than twice as fast as CACHE ORDER.

I've also noticed similar behavior in other environments in the past, although I do not have any results for them.

Why?

I don't understand why CACHE would make so much of a difference when ORDER is used. The amount of time to generate a number should be irrelevant compared to the time to send data over a network. This makes me think that either Oracle is using a poor algorithm, or my test case is wrong. (If anyone can find a problem with my test case, please let me know.)

Also, this answer only discusses the time to generate the sequence. There may be other benefits of using NOORDER. For example, reduced index contention, as described here.

手心的温暖 2024-10-22 19:29:53

序列的设计目的并不是为了有意义地排序。看看这个链接到 Tom Kyte 的回复以及他在同一线程中的一些后续回复。

Sequences are not designed to be ordered with meaning. Check out this link to a response by Tom Kyte and some of his followup responses in the same thread.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文