Performance comparisons for Java RESTful frameworks

Source: Internet
Author: User
Tags jboss

2017-02-03 importnew

(Click the public number above for a quick follow-up)

Source: Bird's Nest,

colobu.com/2015/11/17/jax-rs-performance-comparison/

If you have a good article to submit, please click here to learn more

Today, in the popularity of microservices, we will break down the logic of the code from both portrait and landscape, implementing independent, stateless code units as microservices, publishing them to some distributed computing units or Docker, and creating more service units in a timely manner when performance is needed.

MicroServices are a concept that does not specify the format of the service, but many vendors and frameworks invariably adopt restful architectures, although there are other RPC frameworks that perform well.

How do I choose a lightweight restful framework in the Java ecosystem? You can refer to some other people's experiences, such as my translation: the best 8 Java RESTful frameworks.

Personally, the reason I chose the framework was simple:

    • Simple, lightweight

    • Good performance

    • Stable, reliable

    • Easy to develop and maintain

I would prefer to follow the Java Specification (JSR339) framework, which is lightweight and easy to publish into Docker containers. So I will not choose Spring Boot, Spring MVC, CXF and other relatively heavy frameworks, will not choose pure netty such as too low level, but also to implement the basic functional framework such as routing.

Because the pursuit of lightweight, easy to publish into the Docker container, I will not look at JBoss, tomcat such a JEE container, but choose Jetty, undertow such an embedded container.

So, here I have selected several candidates:

    • Jersey + Grizzly

    • Jersey + Jetty

    • Dropwizard

    • Resteasy + Netty

    • Resteasy + undertow

[Updated on 2015/11/18]

I've added more RESTful frameworks, some not JAX-RS implementations, but there are also very active communities.

    • Jersey + Jetty4

    • Spring Boot

    • Pure Netty

    • Vert.x

You will find some interesting test results.

Jersey is the official reference implementation of JAX-RS and can be well integrated with other JEE containers. The Resteasy is a jboss-produced framework that is also easily integrated with other containers. Dropwizard actually integrates jersey, jetty and other third-party libraries such as its metrics, providing a one-stop development that is slightly heavier.

The test-related code is already on GitHub (Https://github.com/smallnest/Jax-RS-Performance-Comparison).

Compiling code

The test code is a multi-module MAVEN project, and you can generate individual jars by running the maven clean package directly, and these jars contain the classes you depend on to perform fairly simply.

You can also run the MVN exec:java boot service under each module and then access the Http://localhost:8080/rest/hello in the browser (for Jersey + Jetty, the address is Http://localhost:8080/hello)

Test environment

Server

AWS C3.2xlarge

    • 8 Cores (e5-2666 v3 @ 2.90GHz)

    • MEMORY:16G (service only allocates 4G of memory)

Java

1.8.0_51

Test tools

Wrk

Test commands such as: wrk-t16-c1000-d30s Http://127.0.0.1:8080/rest/hello.

For each case, I used 16 threads, and 100/200/500/1000 concurrency to test.

Service Start command

Java-xmx4g-xms4g-jar Jersey-grizzly2-1.0-snapshot.jar

Java-xmx4g-xms4g-jar Jersey-jetty-1.0-snapshot.jar

Java-xmx4g-xms4g-jar Dropwizard-1.0-snapshot.jar hello.yml

Java-xmx4g-xms4g-jar Resteasy-netty-1.0-snapshot.jar

Java-xmx4g-xms4g-jar Resteasy-undertow-1.0-snapshot.jar

Java-xmx4g-xms4g-jar Springboot-1.0-snapshot.jar

Java-xmx4g-xms4g-jar Resteasy-netty4-1.0-snapshot.jar

Java-xmx4g-xms4g-jar Nativenetty-1.0-snapshot.jar

Java-xmx4g-xms4g-jar vertx-verticles-1.0-snapshot.jar-instances 20

Test results

Test result data can be viewed here: Test data (Http://colobu.com/2015/11/17/Jax-RS-Performance-Comparison/Jax-RS-Performance-Comparison),

The latency is essentially between a few milliseconds and 10 milliseconds.

Graphical test results (Y-axis is requests/sec, x-axis is concurrency):

Conclusion

The results show that

    • Resteasy performance is better than Jersey, regardless of which embedded JEE container.

    • Jersey+grizzly2 and Jersey+jetty, Dropwizard performance is not very different

    • The Dropwizard bottom is actually jersey+jetty, and the performance results are the same as Jersey+jetty.

    • The results of Resteasy+netty (NETTY3) were not superior to Resteasy+undertow. It's not my surprise that maybe the CPU and memory will be better.

    • Resteasy+netty4 's performance was much lower than Resteasy+netty3, which was unexpected. Perhaps because of the change of the Netty thread pool.

    • Pure Netty performance is much higher than other frameworks, on the one hand because there is no HTTP router logic, on the other hand also shows the excellent Netty framework. If you are not implementing very complex routes and a lot of service, you might want to use pure Netty for high performance.

    • Spring boot is too heavy to use spring MVC syntax, with only half the performance of Jersey.

    • The Vert.x bottom uses Netty, Java 8 lambda syntax, and support for other languages, but the performance does not look good, and as the concurrency increases the throughput rate decreases. The previous Vert.x test has a problem, only use the single core, thank @stream Netizen's reminder, I added the Vertx-verticles module in the code, support multicore (Java-jar Vertx-verticles-1.0-snapshot.jar- Instances 20). Vert.x performance is also good. @heng

Of course, the test is also a little regret, that is, there is no record of the test CPU occupancy and memory occupancy, in my personal experience, this aspect of Netty will occupy some advantages.

Performance comparisons for Java RESTful frameworks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.