Most efficient way to call external web service in Java?

In one of our applications, we need to call the Yahoo Soap Webservice for weather and other related information.

I used the wsdl2java tool from axis1.4 and generated the required stubs and wrote a client. I am using jsp use bean to include a client bean and call methods defined in the client that call the yahoo inturn webservice.

Now the problem: when users call to jsp, the response time of the webservice is very different, for example one user takes less than 10 seconds and another on the same network took more than a minute.

I'm just wondering if Axis1.4 is worth asking for requests even if the jsps are multithreaded.

Finally, there is an efficient way to call a web service (Yahoo weather). I usually get about 200 concurrent requests from my users.

+2


source to share


3 answers


Why not schedule one thread to get the weather every minute or so, and expose that to the JSP, instead of letting each JSP get its own weather report?

This is much more efficient for you and Yahoo and the JSP is only for finding a local object (almost instantaneous) instead of connecting to a web service.

EDIT

Some new requirements in the comments to this answer suggest a different way of choosing solutions.

It seems that not only the weather, which not only does not change that often, but is the same for every user, is requested by the web service, but also other data such as flight data.

Flight data retrieval requirements are very different from weather requirements. So I think you should define multiple types of (deleted) data and choose a different solution for each category.



As a basis for the requirements, I would use something simple:

  • Users like their information quickly, they don't like waiting
  • The amount of data stored on the web server is finite.
  • Remote web services have a sort of EULA and are probably not happy with 200 simultaneous requests for the same data from the same source (you)

Fast data access for users is best achieved by using the data locally, be it transient (stored in a bean) or persistent (local database). This can be done by periodically requesting data from a remote source and using the cached data in the JSP. This will also keep you clear on the third point.

The finite amount of data stored in the web service means that not everything can be cached. Data that is different to the user, or large datasets that can change over short periods of time, cannot be easily cached. It is not a good idea to download all flights from all airports in the US every minute or so. Such requests will be better served by running a specific web service request when needed.

Now you need to determine when data caching is possible. If possible, do so, otherwise run the web service request in the background. This can be done by exposing a JSP and running the web service request in the background. A JSP can have an AJAX script that asks your web server if the data is ready and insert that data into the page when it is ready.

+4


source


I would use google tools to track how long a web service call takes.

Several things are happening here:

  • Forward the Java beans request to XML.
  • Sending an XML request to a web service.
  • Unmarshall XML request on the web service side.
  • Web service process request
  • Marshalles Web Service XML Response
  • Web service sends XML response to Java client
  • Debug and display Unmarshall XML messages on the client.


You cannot see on the Yahoo web service, but you can see what you see on the client side to see where the time is spent.

Also check the memory. If Axis generates .class files, your potential space is probably being consumed. The Visual VM is available to you with the JDK. Attach it to a PID on your client to see what's going on in memory on your application server.

Perhaps this would be a good place to make an AJAX call. This is a good solution if you can get the weather in the background while users are doing other things.

+1


source


I would recommend local caching and data merging. Instead of sending 200 separate requests for similar / identical places, start a background thread that pulls the weather only for the locations your users are interested in and caches them locally, this cache is updated every minute or so. When users ask for their personal preferences, the requests go into the cache and props if the new location or data in the cache is out of date. This way, the user will have a more seamless experience and you won't be using Yahoo's throttles and getting denial of service.

+1


source







All Articles