Server-side performing multiple requests against cloud services

本小妞迷上赌 提交于 2019-12-06 10:36:10

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.

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.

A single thread for each remote http connection, and using a synchronous http client will probably be easier. I would try this approach first, and see if it is fast/scalable enough. For the synchronous approach, apache http client is a good choice.

If a synchronous solution is not good enough, something like netty may be a good fit. It uses NIO so you won't get thousands of threads.

I do not know of any existing software to do this for you that will not be overkill. But you might try splitting things up. That is, separate the fetching of the data of the showing of the result. Since you do not provide no further details on the problem at hand I cannot say for you whether that would be feasible or not.

Basically the idea is to create a service that will fetch those 30 subsequent requests for you and if possible process it into a request. The client of this service is the service that is running on the web. It will receive a request from a user and subsequently put it's own request trough to your data service. When the data service is ready it will return it's response. Either synchronously or asynchronously.

You could program your data service in any language you want, even Java, without being bound to servlets ensuring that fetching the subsequent 30 request and combining them in a response isn't being done by the webserver. This could also enhance the responsiveness of your web server itself.

Nutshell: branch of the ``difficult" tasks to a specialised service where you can transparently handle parallelism.

I would use Jetty and in the servlets I'd use the continuation mechanism to free up the thread while waiting for the third party web request to complete. This will allow maximum concurrency on your server, as you can have a lot more suspended requests than threads.

You can use either continuations or the servlet 3.0 asynchronous API, the end result is the same.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!