轮询数据库与从数据库触发程序?

ggk*_*ath 8 database oracle

我有一个过程,其中只要该表中至少存在一行,在应用程序服务器中运行的程序必须访问Oracle数据库服务器中的表.每行数据涉及请求由程序执行某些数字运算的客户端.该程序只能串行执行此数字运算(即,一次对一个客户端而不是并行运行多个客户端).

因此,需要告知程序何时数据库中有数据可供处理.我也可以

  1. 让程序轮询数据库,或
  2. 让数据库触发程序.

问题1:有没有传统观点为什么一种方法可能比另一种方法更好?

问题2:我想知道程序是否有任何问题"一次运行"几个月(服务器中的任何进程是否会停止或破坏程序运行? - 如果是这样我不知道如何学习有一个问题,除非愤怒的客户).任何人都有在服务器上运行程序很长时间没有问题的经验?或者,如果服务器崩溃,有没有办法在服务器重新启动后自动启动它(即C语言可执行文件)程序,因此不需要人专门启动它?

任何建议表示赞赏

更新1:客户端正在等待结果,但是几秒钟的额外延迟(来自轮询)不是交易破坏者.

Ale*_*Vaz 5

我想给出一个更通用的答案......

\n\n

没有每次都适用的正确答案。有时您需要触发器,有时最好进行轮询。

\n\n

但是\xe2\x80\xa6 十分之九,轮询比触发高效、安全、快速得多。

\n\n

It's really simple. A trigger needs to instantiate a single program, of whatever nature, for every shot. That is just not efficient most of the time. Some people will argue that that is required when response time is a factor, but even then, half of the times polling is better because:

\n\n

1) Resources: With triggers, and say 100 messages, you will need resources for 100 threads, with 1 thread processing a packet of 100 messages you need resources for 1 program.

\n\n

2) Monitoring: A thread processing packets can report time consumed constantly on a defined packet size, clearly indicating how it is performing and when and how is performance being affected. Try that with a billion triggers jumping around\xe2\x80\xa6

\n\n

3) Speed: Instantiating threads and allocating their resources is very expensive. And don\xe2\x80\x99t get me started if you are opening a transaction for each trigger. A simple program processing a say 100 meessage packet will always be much faster that initiating 100 triggers\xe2\x80\xa6

\n\n

3) Reaction time: With polling you can not react to things on line. So, the only exception allowed to use polling is when a user is waiting for the message to be processed. But then you need to be very careful, because if you have lots of clients doing the same thing at the same time, triggering might respond LATER, than if you where doing fast polling.

\n\n

My 2cts. This has been learned the hard way ..

\n


HAL*_*000 2

1)让程序轮询数据库,因为您不希望数据库能够启动主机程序(因为您必须确保只有“您的”程序可以通过这种方式启动)。

在 Oracle 中执行此操作的经典(也是最方便的 IMO)方法是通过DBMS_ALERT 包

第一个程序将发出具有特定名称的警报,并传递可选消息。注册警报的第二个程序将在第一个程序提交后立即等待并接收警报。回滚第一个程序将取消警报。

当然,您可能有许多会话发出信号并等待警报。但是,警报是一种序列化设备,因此如果一个程序发出警报,则发出相同警报名称的其他程序将被阻止,直到第一个程序提交或回滚。

表 DBMS_ALERT_INFO包含已注册警报的所有会话。您可以使用它来检查警报处理是否处于活动状态。

2) 自动启动或后台执行取决于您的主机平台和操作系统。在 Windows 中,您可以使用 SRVANY.EXE 将任何可执行文件作为服务运行。