如何扩展具有守护进程任务的应用程序服务器?

发布于 2024-11-08 23:27:44 字数 537 浏览 3 评论 0原文

我现在有一个在一台服务器上运行的 Web 应用程序。我想切换到应用程序服务器集群(码头),以处理增加的负载和故障转移。然而,该应用程序有几个守护线程,它们每 10 分钟运行一次,以便处理传入的数据。这些数据必须仅处理一次(它与外部服务器通信,并且不好)如果做两次就会发生)。

扩大规模的最佳实践是什么?

我拥有的一些选项是:

  1. 有一个标志来指示应用程序是否应该运行守护程序任务。然后只将其中一个标志设置为 true。这是有效的,但这意味着我不再有简单的故障转移 - 我需要监视该特殊的应用程序服务器并在它出现故障时采取行动。

  2. 设计出一些系统,其中不同的应用程序服务器相互了解,并有某种方式选择一个节点来运行它,例如,所有服务器都选择一个随机数,并且哪个节点最高就可以运行它。每 10 分钟做一次。这具有自动故障转移(如果其他节点因为一个节点宕机而无法与该节点通信,它就会被忽略),但这也意味着每个应用程序服务器都需要了解彼此的应用程序服务器,我觉得我正在重新发明 设计出一些系统,

这种情况通常如何处理?

I have a web application that runs on one server right now. I'd like to switch to a cluster of application servers (jetty), to handle increased load and failover. However, the application has a couple of daemon threads, which run once every 10 minutes in order to process data that has come in. This data must be processed only once (it communicates with external servers, and bad things happen if it's done twice).

What are the best practices for scaling that?

Some of the options I have are:

  1. Have a flag for whether or not the application should run the daemon tasks. Then only have one of them with that flag set to true. This works, but it means that I no longer have easy failover - I need to monitor that special application server and take action if it goes down.

  2. Work out some system where different application servers know about eachother and have some way of picking a node to run it, eg all pick a random number and whichever node is highest gets to run it. Do that every 10 minutes. This has automatic failover (if other nodes can't communicate with one node because it's down, it just gets ignored), but it also means each application server needs to know about each other application server, and I feel like I'm reinventing the wheel here.

How is this situation typically handled?

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

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

发布评论

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

评论(2

怂人 2024-11-15 23:27:44

您可以使用 Quartz 来安排任务,它具有集群支持

除了在 Quartz 中安排任务之外,您还必须使用 Quartz 的模式创建一个数据库(或使用现有的数据库)。集群中的所有服务器必须同步其时间(ntpd 会做到这一点)。

使用 Quartz 将为您提供故障转移、负载平衡并保证每个任务仅执行一次。

You can use Quartz to schedule your tasks, it has cluster support.

Besides scheduling your tasks in Quartz, you'll have to create a database (or use an existing one) with Quartz's schema. All servers in the cluster must have their times synchronized (ntpd will do it).

Using Quartz will give you fail-over, load-balancing and the guarantee that each task will be only executed once.

溺深海 2024-11-15 23:27:44

为什么不使用数据库来协调呢?任何具有空闲周期的节点都可以在作业表中插入“进行中”行以锁定其他节点。这利用了这样一个事实:您可能已经依赖所有节点中的单个数据库,该数据库内置了事务管理。

您需要设计一个简单的计时算法来确保所有节点不会每十分钟同时醒来并争夺锁。也许引入 0-10 秒的随机延迟。

Why not use the database to coordinate? Any node that has free cycles could insert an "in progress" row in a jobs table to lock out other nodes. This takes advantage of the fact that you probably already rely on a single database among all the nodes, that has built in transaction management.

You would need to devise a simple timing algorithm to ensure that all the nodes didn't wake up at the same time every ten minutes and fight for the lock. Maybe introduce a random delay of 0-10 seconds.

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