Choosing an Embedded Web Server
Overview
An embedded Web server is a HTTP server that can be shipped as part of your application without having to install the server separately and then deploy your application on it.The embedded Web server has a small foot print and if your application doesn't need the J2EE stack, then might be suitable for your application. These are great for use in microservices where each microservice is a small "feature/service" running in a container (like docker), each having it's own embedded server. An application would consist of multiple microservices.
We considered a number of Web servers for our application. The following table lists the comparison of
Tomcat vs Jetty vs Grizzly vs Undertow
Tomcat vs Jetty vs Grizzly vs Undertow
Tomcat
|
Jetty
|
Grizzly
|
Undertow
| |
|---|---|---|---|---|
| Description | The Apache Tomcat® software is an open source implementation of the Java Servlet, JavaServer Pages, Java Expression Language and Java WebSocket technologies. | Jetty is an open-source project providing an HTTP server, HTTP client, and javax.servlet container. | Project Grizzly is a pure Java web service built using the NIO API, supporting Web Framework (HTTP/S), WebSocket, Comet, | Undertow is a flexible performant web server written in java. Undertow has a composition based architecture that allows you to build a web server by combining small single purpose handlers. The gives you the flexibility to choose between a full Java EE servlet 3.1 container, or a low level non-blocking handler, to anything in between. |
| NIO/BIO | Supports NIO/BIO. | Version 9+ only supports NIO | NIO | NIO/BIO |
| Limitation | Not a full Servlet container | |||
| Spring Boot | Supported OOTB | Supported OOTB | N/A https://stackoverflow.com/questions/44565549/embed-grizzly-glassfish-servlet-container-with-spring-boot-java?rq=1 | Supported OOTB |
| Embeddable | Yes, more configuration/jars required | Yes | Yes | Yes |
Performance
| Tomcat came in fourth | Jetty throughput and responsetime were close behind Grizzly | Grizzly seems to give us the very best through-output and response time no matter the concurrency level. | Undertow came in behind Jetty |
Performance with max worker threads (250)
| Tomcat came in third | Jetty came in behind Grizzly | Grizzly is the fastest container when it comes to serving JAX-RS requests. | Undertow came in fourth. |
Performance findings
- Running from exploded jar shaves up to 6MB off the heap (the difference is cached jar data in the launcher). Also, makes startup a bit faster: less than 5s compared to as much as 7s when memory is constrained with the fat jar.
- Using Jetty instead of Tomcat makes no difference whatsoever to the overall memory or heap, even though the
NioEndpointis high on the “Biggest objects” list in YourKit (takes about 1MB), and there is no corresponding blip for Jetty. It also doesn’t start up any quicker.
Please feel free to add comments if there are more differences/comparison you know of.
Comments
Post a Comment