Skip to content

Demo project to show different Java templating engines in combination with Spring MVC

License

Notifications You must be signed in to change notification settings

chrisjfunk/spring-comparing-template-engines

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Comparing Template engines for Spring MVC

Build Status

This is a demo project, which accompanied my "Shoot-out! Template engines for the JVM" presentation, which shows the differences among several Java template engines in combination with Spring MVC. Template engines used in this project are:

Build and run

You need Java 8 (or higher) and Maven 3 to build and run this project. Build the project with

mvn package

Run the project with

mvn tomcat7:run

See the demo URLs:

Benchmarking

In case you want to benchmark the different template engines I would recommend using Apache HTTP server benchmarking tool or Siege an HTTP/HTTPS stress tester. You can try any of the following URLs.

$ ab -n 10000 -c 10 http://localhost:8080/jsp
$ ab -n 10000 -c 10 http://localhost:8080/velocity
$ ab -n 10000 -c 10 http://localhost:8080/freemarker
$ ab -n 10000 -c 10 http://localhost:8080/thymeleaf
$ ab -n 10000 -c 10 http://localhost:8080/mustache
$ ab -n 10000 -c 10 http://localhost:8080/jade
$ ab -n 10000 -c 10 http://localhost:8080/pebble
$ ab -n 10000 -c 10 http://localhost:8080/handlebars
$ ab -n 10000 -c 10 http://localhost:8080/jtwig
$ ab -n 10000 -c 10 http://localhost:8080/chunk
$ ab -n 10000 -c 10 http://localhost:8080/rocker
$ ab -n 10000 -c 10 http://localhost:8080/j2html
$ ab -n 10000 -c 10 http://localhost:8080/kotlinhtml
$ ab -n 10000 -c 10 http://localhost:8080/htmlFlow

For creating the below benchmark results I used ApacheBench(Version 2.3) with the following settings:

ab -n 25000 -c 25 -k http://localhost:8080/jsp

With 25 concurrent requests and 25.000 requests in total this resulted in the following numbers:

Benchmarks 2018

These tests were done on a local machine with the following specs:

Microsoft Windows 10 Education  OS Version: 10.0.17134 N/A Build 17134
Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz, 2808 Mhz, 4 Core(s), 8 Logical Processor(s)
Java(TM) SE Runtime Environment 18.9 (build 11+28)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11+28, mixed mode)
Apache Tomcat 7.0.53 with 512M RAM

Results in order (low to high):

Total time taken for processing 25.000 requests with a concurrency level of 25. (lower is better)

HtmlFlow	1.172 seconds
Rocker		1.299 seconds
Jade		3.071 seconds
Mustache	3.098 seconds
Pebble		3.172 seconds
Freemarker	3.224 seconds
Velocity	3.283 seconds
Chunk		3.334 seconds
Jtwig		3.399 seconds
JSP		3.424 seconds
Thymeleaf	3.645 seconds
Handlebars	3.765 seconds
J2Html		4.561 seconds
Kotlin		6.111 seconds
Scalate		7.880 seconds

Keep in mind that in the real world, these results will differ depending on the complexity of the templates, hardware, etc, so it's just an indication and if you want to know the truth you will have to run the benchmark yourself to see how such a template engine performs in your specific environment.

How were the results measured?

Before the performance of each template engines was measured, there were at least 2 dry runs with the exact same settings, to make sure that initialization of the engines, warm up of the JVM and additional caches have taken place. There were at least 5 iterations of the same benchmark before calculating the average time it took.

For Mac OSX users

Mac OS X has only 16K ports available that won't be released until socket TIME_WAIT is passed. The default timeout for TIME_WAIT is 15 seconds. Consider reducing in case of available port bottleneck.

You can check whether this is a problem with netstat:

# sysctl net.inet.tcp.msl
net.inet.tcp.msl: 15000

Now if you want to change this you can do so by doing:

# sudo sysctl -w net.inet.tcp.msl=1000
net.inet.tcp.msl: 15000 -> 1000

In case you still run into problem you might want to read this thread on ephemeral ports.

Contributing

In case you see an improvement to the benchmark or know about ways to improve the results, please file an issue and send a pull request.

About

Demo project to show different Java templating engines in combination with Spring MVC

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 52.0%
  • HTML 26.3%
  • JavaScript 14.9%
  • Kotlin 3.7%
  • FreeMarker 1.9%
  • Scala 1.2%