服务器端执行对云服务的多个请求 [英] Server-side performing multiple requests against cloud services

查看:205
本文介绍了服务器端执行对云服务的多个请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个web的应用程序,使用多个网络的API的过程。
对于单个用户的一个请求,我的应用程序可能需要执行多达30个HTTP请求到其他站点。该网站的住房在web-app可以有数百个并发用户。

I am in the process of writing a web-app that uses multiple web APIs. For a single request of a single user, my app may need to perform up to 30 HTTP requests to other sites. The site housing the web-app can have hundreds of concurrent users.

我一直在四处寻找,试图找出我应该使用哪个库。我在寻找一个成熟的项目已经详细的文档和测试code,一个仍然会在今后几年里各地。不知道这样的事情存在(!)

I've been looking around trying to figure out which library should I use. I'm looking for a mature project that has detailed documentation and tested code, one that will still be around in years to come. Not sure if something like that exists (!)

问题的夫妇:


  1. 在一个情况下,如上述,我应该使用异步HTTP客户端(不带螺纹)或常规(可能共用)HTTP客户端(带螺纹)?异步性功能可减轻使用线程我的应用程序,但使得code比较分散 - 将请求负担我的服务器上面提到的人数太多? (它说,这里异步更具可扩展性)

  1. In a case such as described above, should I be using an asynchronous HTTP client (without threading), or a regular (possibly pooled) HTTP client (with threading)? Asynchronicity relieves my app from using threads, but makes the code more scattered - will the above mentioned number of requests burden my server too much? (it says here that asynchronous is more scalable)

哪个库是用常见的一种?它是阿帕奇HttpComponenets HttpClient的或它的非同步couterpart的 HttpAsynchClient - 这是在阿尔法)?如何jfarcand的 AsyncHttpClient

Which library is the common one to use? Is it Apache HttpComponenets HttpClient or its asynch couterpart HttpAsynchClient - which is in Alpha...)? How about jfarcand's AsyncHttpClient?

好吧,让我们说,我将使用线程。
周围挖后,我认识到,一个servlet中产卵从线程(在我的情况 - 一个Struts动作),可能是一个大的否否的:


Okay, let's say I will use threads. After digging around I realize that spawning threads from within a servlet (in my case - a Struts action), may be a big No No :

相关的问题:

<一个href=\"http://stackoverflow.com/questions/3745905/what-is-recommended-way-for-spawning-threads-from-a-servlet-in-tomcat\">What被推荐的方式产卵线程在Tomcat中一个servlet

<一个href=\"http://stackoverflow.com/questions/4424329/need-help-with-java-web-app-design-to-perform-background-tasks\">Need使用Java Web应用程序的设计有助于执行后台任务

我能产生一个线程从一个servlet?

我看到它的方式,这是我的选择:

The way I see it, these are my options:


  1. use我自己的线程池(容器不管理自己的线程)

  2. use WorkManager使用如CommonJ (似乎是一个无效的产品)

  3. use第三方调度,如石英(可能是矫枉过正...?)

  1. use my own thread pool (container doesn't manage my threads)
  2. use a WorkManager such as CommonJ (seems like an inactive product)
  3. use a 3rd party scheduler such as Quartz (may be an overkill ... ?)

我想AP preciate为这个特定用例的任何建议 - 汇聚来自不同的Web服务lotsa数据(这种聚合是由单个用户的单个请求调用)

I would appreciate any recommendations for this specific use case - aggregating lotsa data from different web services (this aggregation is invoked by a single user's single request).

推荐答案

好问题。我先试试异步解决方案,看到的一切是如何工作的。异步解决方案是最简单的实现。

Good question. I would try an asynchronous solution first to see how everything works. The asynchronous solution would be the simplest to implement.

如果还是不行,请尝试使用更多的线程模型。

If that doesn't work, try a more threaded model.

我会用HttpClient的,让你的请求。我用它做了很多,并用它为我做任何HTTP的工作。

I would use HttpClient for making your requests. I've worked with it a lot and use it for any http work that I have to do.

这篇关于服务器端执行对云服务的多个请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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