简体   繁体   English

EJB计时器性能

[英]EJB timer performance

I am trying to decide if use a java-ee timer in my application or not. 我试图确定是否在我的应用程序中使用java-ee计时器。 The server I am using is Weblogic 10.3.2 我正在使用的服务器是Weblogic 10.3.2

The need is: After one hour of a call to an async webservice from an EJB, if the async callback method has not been called it is needed to execute some actions. 需要是:从EJB调用异步Web服务一个小时后,如果尚未调用异步回调方法,则需要执行一些异步操作。 The information regarding if the callback method has been called and the date of the execution of the call is stored in database. 有关是否已调用回调方法以及调用执行日期的信息存储在数据库中。

The two possibilities I see are: 我看到的两种可能性是:

  1. Using a batch process that every half hour looks for all the calls that have been more than one hour without response and execute the needed actions. 使用每半小时进行一次的批处理过程,查找超过一个小时以上的所有呼叫而没有响应,并执行所需的操作。
  2. Create a timer of one hour after every single call to the ws and in the @Timeout method check if the answer has come and if it has not, execute the required actions. 在每次对ws的每次调用之后,创建一个小时的计时器,并在@Timeout方法中检查答案是否到来,如果没有答案,请执行所需的操作。

From a pure programming point of view, it looks easier and cleaner the second one, but I am worry of the performance issues I could have if let's say there are 100.000 Timer created at a single moment. 从纯粹的编程角度来看,第二个看起来更轻松,更干净,但是我担心如果一次创建100.000个Timer会遇到性能问题。

Any thoughts? 有什么想法吗?

All depends of what is used by the container. 一切都取决于容器使用什么。 eg JBoss uses Quartz Scheduler to implement EJB timer functionality. 例如,JBoss使用Quartz Scheduler来实现EJB计时器功能。 Quartz is pretty good when you have around 100 000 timer instances. 当您有大约100 000个计时器实例时,Quartz相当不错。

You would be better off having a more specialized process. 您最好拥有一个更加专业的流程。 The real problem is the 100,000 issue. 真正的问题是100,000期。 It would depend on how long your actions take. 这取决于您的操作需要多长时间。

Because its easy to see that each second, the EJB timer would fire up 30 threads to process all of the current pending jobs, since that's how it works. 因为很容易看到每一秒钟,所以EJB计时器将启动30个线程来处理所有当前的挂起作业,因为这就是它的工作方式。

Also timers are persistent, so your EJB managed timer table will be saving and deleting 30 rows per second (60 total), this is assuming 100K transactions/hour. 此外,计时器是永久性的,因此,您的EJB管理的计时器表将每秒保存和删除30行(总共60行),这是假设每小时处理10万笔事务。

So, that's an lot of work happening very quickly. 因此,很多工作正在迅速进行。 I can easily see the system simply "falling behind" and never catching up. 我可以很容易地看到该系统只是“落后”而从未追赶。

A specialized process would be much lighter weight, could perhaps batch the action calls (call 5 actions per thread instead of one per thread), etc. It would be nice if you didn't have to persist the timer events, but that is what it is. 一个专门的过程将更轻巧,可以分批进行操作调用(每个线程调用5个操作,而不是每个线程调用5个操作),等等。如果您不必持久化计时器事件,那会很好。它是。 You could almost easily simply append the timer events to a file for safety, and keep them in memory. 为了安全起见,您几乎可以简单地将计时器事件附加到文件中,并将其保留在内存中。 On system restart, you can reload that file, and then roll the file (every hour create a new file, delete the older file after it's all been consumed, etc.). 在系统重启时,您可以重新加载该文件,然后滚动该文件(每小时创建一个新文件,用完所有文件后删除旧文件,等等)。 That would save a lot of DB traffic, but you could lose the transactional nature of the DB. 这样可以节省大量数据库流量,但是您可能会失去数据库的事务性。

Anyway, I don't think you want to use the EJB Timer for this, I don't think it's really designed for this amount of traffic. 无论如何,我不认为您要为此使用EJB Timer,我也不认为它真的是为如此大的流量而设计的。 But you can always test it and see. 但是您可以随时对其进行测试并查看。 Make sure you test restarting your container see how well it works with 100K pending timer jobs in its table. 确保测试重新启动容器,然后在表中查看其与100K暂挂计时器作业的配合情况。

@Pau: why u need to create a timer for every call made...instead u can have a single timer thread created at start up of application which runs after every half-hour(configurable) period of time and looks in your Database for all web services calls whose response have not been received and whose requested time is past 1 hour. @Pau:为什么您需要为每个调用创建一个计时器...相反,您可以在应用程序启动时创建一个计时器线程,该线程在每半小时(可配置)时间段后运行,并在数据库中查找所有未收到响应且请求时间超过1小时的Web服务呼叫。 And for selected records, in for loop, it can execute required action. 对于选定的记录,在for循环中,它可以执行所需的操作。

Well above design may not be useful if you have time critical activity to be performed. 如果您要执行时间紧迫的活动,那么超出设计的范围可能没有用。

If you have spring framework in your application, you may also look up its timer services.http://static.springsource.org/spring/docs/1.2.9/reference/scheduling.html 如果您的应用程序中装有spring框架,则还可以查找其计时器服务。http://static.springsource.org/spring/docs/1.2.9/reference/scheduling.html

Maybe you could use some of these ideas: 也许您可以使用以下一些想法:
Where I'm at, we've built a cron-like scheduler which is powered by a single timer. 我在哪里,我们已经建立了一个类似于cron的调度程序,该调度程序由单个计时器提供支持。 When the timer fires the system checks which crons need to run using a Quartz CronTrigger. 当计时器启动时,系统会使用Quartz CronTrigger来检查需要运行的cron。 Generally these crons have a lot of work to do, and the way we handle that is each cron spins its individual tasks off as JMS messages, then MDBs handle the messages. 通常,这些任务有很多工作要做,我们处理每个cron的方式是将其单独的任务分解为JMS消息,然后由MDB处理这些消息。 Currently this runs on a single Glassfish instance and as our task load increases, we should be able to scale this up with a cluster so multiple nodes are processing the jms messages. 当前,此操作在单个Glassfish实例上运行,并且随着任务负载的增加,我们应该能够通过集群进行扩展,以便多个节点正在处理jms消息。 We balance the jms message processing load for each type of task by setting the max-pool-size in glassfish-ejb-jar.xml (also known as sun-ejb-jar.xml). 通过在glassfish-ejb-jar.xml(也称为sun-ejb-jar.xml)中设置max-pool-size,可以平衡每种任务的jms消息处理负载。

Building a system like this and getting all the details right isn't trivial, but it's proving really effective. 构建这样的系统并正确处理所有细节并非易事,但事实证明它确实有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM