1

I am working on a project where REsT webservice calls are required very frequently. We are using Apache Outh2 to make

  1. client request: OAuthBearerClientRequest
  2. authorize it: OAuthBearerClientRequest( url).setAccessToken
  3. get the response: OAuthResourceResponse.

But mean while each WS call take takes more time to respond. Just wanted to know whats are the ways to optimize the WS call in this case so that content loading time will get reduced?

nilFi
  • 197
  • 2
  • 18

2 Answers2

5

You can consider the spring's caching if you are using spring in your application.

A cache is hidden and it will improves application's performance but does that by allowing the same data to be read multiple times in a fast fashion.

As mentioned in Spring Documentation:

At its core, the abstraction applies caching to Java methods, reducing thus the number of executions based on the information available in the cache. That is, each time a targeted method is invoked, the abstraction will apply a caching behavior checking whether the method has been already executed for the given arguments. If it has, then the cached result is returned without having to execute the actual method; if it has not, then method is executed, the result cached and returned to the user so that, the next time the method is invoked, the cached result is returned. This way, expensive methods (whether CPU or IO bound) can be executed only once for a given set of parameters and the result reused without having to actually execute the method again. The caching logic is applied transparently without any interference to the invoker.

 @Cacheable("books")
 public Book findBook(ISBN isbn) {...}

In the snippet above, the method findBook is associated with the cache named books. Each time the method is called, the cache is checked to see whether the invocation has been already executed and does not have to be repeated.

This is just a sample to give you an idea about the spring caching. The example is already given in their official site which you can refer and gain detailed knowledge from here.

Some more example you can find here also.

Nakul91
  • 1,245
  • 13
  • 30
  • Any other solution than caching? as in my case I cant use caching, always need to make the API calls for data synch. – nilFi Jul 14 '15 at 09:42
  • You can give the time limit i.e time to expire for that cache. For e.g. 5 mins. If you are authorizing the same data twice/thrice within 5 mins then it will take cached copy. Other wise it will fetch from data base for next request after expiration of that cache. – Nakul91 Jul 14 '15 at 09:47
  • yeah, I got your point but again cache comes into picture which I really dont wan't? I am looking for slution where cache is not envolved at all – nilFi Jul 15 '15 at 11:15
  • @nilFi did you find a solution without using cache – Shivam... Jun 16 '21 at 21:51
1

Are you compressing your data using gzip? typically, upload speeds are slower than download speeds on most networks. So use gzip compression while making REST calls.

More info here and here.

Community
  • 1
  • 1