我使用jersey-client-1.2访问EHCache REST API来放置/获取我自己的自定义对象 .
泽西Maven依赖:
com.sun.jersey
jersey-client
1.2
客户代码:
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));
当我使用上面的代码执行负载测试时,应用程序服务器(上面的客户端正在运行)会产生不良的性能 . 由于泽西客户端调用,大多数线程进入等待阶段 . 但是,部署缓存REST API的服务器响应正常 . 看来球衣客户端表现不佳 .
我是否遵循上述代码中的Jersey客户端的最佳做法?我错过了导致性能问题的任何问题吗?请问任何想法 .