I am using jersey-client-1.2 to access EHCache REST APIs to put/get my own custom objects.
Jersey Maven Dependency:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.2</version>
</dependency>
Client Code:
MyObject myObject = new MyObject();
myObject.setName("Narendra");
long start = System.currentTimeMillis();
Client client = Client.create();
WebResource webResource = client.resource("http://localhost:9080/ehcache-server/rest/mycache/");
System.out.println("Time spend in creating client - " + (System.currentTimeMillis() - start));
start = System.currentTimeMillis();
ClientResponse putResponse = webResource.type("application/x-java-serialized-object").put(ClientResponse.class, SerializationUtils.serialize(myObject));
System.out.println("Time spend in serializing and putting Object into cache - " + (System.currentTimeMillis() - start));
start = System.currentTimeMillis();
ClientResponse getResponse = webResource.accept("application/x-java-serialized-object").get(ClientResponse.class);
byte[] bytes = getResponse.getEntity(byte[].class);
System.out.println("Time spend in getting and deseralizing object from cache " + (System.currentTimeMillis() - start));
When I perform load test with above code, the application server (where above client is running) gives bad performance. Most of the threads went into waiting stage due to jersey client call.However, the server where cache REST APIs are deployed responding properly. It seems jersey client is not performing well.
Am I following best practices of Jersey client in above code? Am I missing anything which is causing performance issues? Any Idea please.