我可以限制分布式应用程序发出的请求吗? [英] Can I throttle requests made by a distributed app?

查看:163
本文介绍了我可以限制分布式应用程序发出的请求吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序发出Web服务请求;提供商将处理的请求的最大速率,因此我需要限制它们。

My application makes Web Service requests; there is a max rate of requests the provider will handle, so I need to throttle them down.

当应用程序在单个服务器上运行时,我曾经在应用程序级别:跟踪目前已完成的请求数量的对象,并等待当前请求是否超过允许的最大负载。

When the app ran on a single server, I used to do it at the application level: an object that keeps track of how many requests have been made so far, and waits if the current request makes it exceeds the maximum allowed load.

现在,我们正在从一台服务器迁移到一个集群,因此有两个应用程序正在运行。

Now, we're migrating from a single server to a cluster, so there are two copies of the application running.


  • 我无法继续检查对于应用程序代码的最大负载,因为两个节点组合可能超过允许的负载。

  • 我不能简单地减少每个服务器上的负载,因为如果另一个节点是空闲的,第一个节点可以发出更多请求。

这是一个JavaEE 5环境。限制应用程序发出请求的最佳方法是什么?

This is a JavaEE 5 environment. What is the best way to throttle the requests the application sends out ?

推荐答案

由于您已经在Java EE环境中,所以可以创建一个MDB,根据JMS队列处理对Web服务的所有请求。应用程序的实例可以简单地将其请求发布到队列,MDB将接收它们并调用Web服务。

Since you are already in a Java EE environment, you can create an MDB that handles all requests to the webservice based on a JMS queue. The instances of the application can simply post their requests to the queue and the MDB will recieve them and call the webservice.

实际上,队列可以配置适当数量的会话,这些会话将限制对您的Web服务的并发访问,因此您的限制是通过队列配置来处理的。

The queue can actually be configured with the appropriate number of sessions that will limit the concurrent access to you webservice, thus your throttling is handled via the queue config.

结果可以通过另一个队列(甚至是每个应用程序实例的队列)返回。

The results can be returned via another queue (or even a queue per application instance).

这篇关于我可以限制分布式应用程序发出的请求吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆