Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance degradation after moving to jersey 2

We're working on a server using spring 4, embedded jetty 9 and jersey. Recently, we moved to jersey 2.13 and we noticed a degradation in performance. I performed some investigations using YourKit. I saw that there is a massive CPU usage in reflection done by jersey. Also, there are many NoSuchMethodExceptions and ClassNotFoundExceptions in Yourkit snapshot.

enter image description here

Are there any jersey configuration or a best practice to avoid this issue, or to optimize jersey? Or maybe it is a known issue in jersey 2?

Here are two screenshots from YourKit, showing the hot-spots, after excluding the socket read (java.net.SocketInputStream.socketRead0). The first one is with Merged Callees:

enter image description here

And the second one is with Back Trace:

enter image description here

Thanks.

like image 701
nahsh Avatar asked Dec 10 '14 08:12

nahsh


People also ask

Why we use Jersey for REST?

RESTful service development (on Jersey) is an architecture, which inherently uses servlets. JAX-RS compliant tools like Jersey provide easy marshalling-unmarshalling of XML/JSON data, helping the developers. REST helps us use GET/POST/PUT/DELETE in a fashion that is far efficient than normal servlets.

What is the difference between Jersey and RESTEasy?

Both Jersey and RESTEasy provide their own implementation. The difference is that Jersey additionally provides something called Chunked Output. It allows the server to send back to the client a response in parts (chunks).

Which is better JAX-RS or spring?

JAX-RS is only a specification and it needs a compatible implementation to be used. On the other hand, Spring MVC is a complete framework with REST capabilities. Like JAX-RS, it also provides us with useful annotations to abstract from low-level details.

What is the difference between Jersey and spring boot?

Jersey is an alternative to Spring RESTFul applications created with @RestController . Spring is a popular Java application framework for creating enterprise applications. Spring Boot is the next step in evolution of Spring framework.


1 Answers

By looking at your question I can not pin point the exact issue. But I can suggest you to check the following things:

  1. Check if there are any duplicate libraries/jars with different versions in your final build
  2. Check whether you have recommended Spring/jersey transitive dependency/jar versions in your final build

If you are using maven to build your project, then I suggest using the maven dependency tree plugin to check the above mentioned points.

- Chiru

like image 104
Diablo Avatar answered Nov 10 '22 17:11

Diablo