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
Jetty
Grizzly
Undertow
DescriptionThe 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/BIOSupports NIO/BIO.Version 9+ only supports NIONIONIO/BIO
LimitationNot a full Servlet container
Spring BootSupported OOTBSupported OOTBN/A
https://stackoverflow.com/questions/44565549/embed-grizzly-glassfish-servlet-container-with-spring-boot-java?rq=1
Supported OOTB
EmbeddableYes, more configuration/jars requiredYesYesYes
Performance
Tomcat came in fourthJetty throughput and responsetime were close behind GrizzlyGrizzly 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 thirdJetty came in behind GrizzlyGrizzly 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 NioEndpoint is 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