jreijn / spring-comparing-template-engines

Demo project to show different Java templating engines in combination with Spring MVC
Apache License 2.0
422 stars 116 forks source link

Thymeleaf 2.1.2 / 2.1.4 performance is MUCH better #7

Closed adam-ah closed 7 years ago

adam-ah commented 9 years ago

Thanks for this project, great resource!

(ProductName: Mac OS X ProductVersion: 10.10.1 BuildVersion: 14B25, sudo sysctl net.inet.tcp.msl=1000)

The Thymeleaf 2.1.2 first run gives me 13.7s, second 8.5s, the third 6.6s. The Thymeleaf 2.1.4 first run gives me 14.1s, second 6.5s, the third 7.6s. The JSP test on the first run gives 7s, second run 6s, third run 6.3s.

However I test I cannot match that extreme difference that you've experienced between JSP and Thymeleaf.

The reason I was holding back from using Thymeleaf was your tests but looks like the performance isn't really an issue. Can you double check maybe?

n=10000 c=10
---------------------------------------------------------
Document Path:          /jsp
Document Length:        8506 bytes

Concurrency Level:      10
Time taken for tests:   6.691 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      87440000 bytes
HTML transferred:       85060000 bytes
Requests per second:    1494.53 [#/sec] (mean)
Time per request:       6.691 [ms] (mean)
Time per request:       0.669 [ms] (mean, across all concurrent requests)
Transfer rate:          12761.92 [Kbytes/sec] received
---------------------------------------------------------
Document Path:          /thymeleaf
Document Length:        8856 bytes

Concurrency Level:      10
Time taken for tests:   6.482 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      90190000 bytes
HTML transferred:       88560000 bytes
Requests per second:    1542.75 [#/sec] (mean)
Time per request:       6.482 [ms] (mean)
Time per request:       0.648 [ms] (mean, across all concurrent requests)
Transfer rate:          13587.92 [Kbytes/sec] received
n=25000 c=25
---------------------------------------------------------
Document Path:          /jsp
Document Length:        8506 bytes

Concurrency Level:      25
Time taken for tests:   17.993 seconds
Complete requests:      25000
Failed requests:        0
Total transferred:      218600000 bytes
HTML transferred:       212650000 bytes
Requests per second:    1389.42 [#/sec] (mean)
Time per request:       17.993 [ms] (mean)
Time per request:       0.720 [ms] (mean, across all concurrent requests)
Transfer rate:          11864.32 [Kbytes/sec] received

---------------------------------------------------------
Document Path:          /thymeleaf
Document Length:        8856 bytes

Concurrency Level:      25
Time taken for tests:   19.339 seconds
Complete requests:      25000
Failed requests:        0
Total transferred:      225475000 bytes
HTML transferred:       221400000 bytes
Requests per second:    1292.71 [#/sec] (mean)
Time per request:       19.339 [ms] (mean)
Time per request:       0.774 [ms] (mean, across all concurrent requests)
Transfer rate:          11385.69 [Kbytes/sec] received
jreijn commented 9 years ago

Hi @adam-ho ,

yes you are probably right. In my case I did the benchmark on a Core 2 Duo machine. What are you hardware specs? Thymeleaf is quite CPU bound, so the more CPU power the faster it is.

I'm working on improving this information, so I will also update the example project. Next to that I want to create a seperate git repo for benchmarking only the template engines (so without the Spring part) with JMH.

Jeroen

adam-ah commented 9 years ago

Hi Jeroen,

It's an i7 dual core. As it's all local environment without IO access, all tests must be CPU bound; both JSP and Thymeleaf. That still doesn't explain why you had that enormous performance difference between JSP and Thymeleaf; however it can be deterring for people looking into Thymeleaf as it looks like it's actually unusably slow compared to JSP or Freemarker. But that's not really the case... (note: I haven't worked much with Thymeleaf either).

Thanks,

Adam

jreijn commented 9 years ago

Hmm, it's indeed strange, but any concurrent test I perform shows about the same numbers. On my current machine (Quad core i7), I get these numbers:

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

Document Path:          /jsp
Document Length:        8506 bytes

Concurrency Level:      25
Time taken for tests:   1.832 seconds
Complete requests:      25000
Failed requests:        0
Keep-Alive requests:    0
Total transferred:      218600000 bytes
HTML transferred:       212650000 bytes
Requests per second:    13643.15 [#/sec] (mean)
Time per request:       1.832 [ms] (mean)
Time per request:       0.073 [ms] (mean, across all concurrent requests)
Transfer rate:          116499.67 [Kbytes/sec] received

$ ab -n 25000 -c 25 -k http://127.0.0.1:8080/thymeleaf

Document Path:          /thymeleaf
Document Length:        8856 bytes

Concurrency Level:      25
Time taken for tests:   3.600 seconds
Complete requests:      25000
Failed requests:        0
Keep-Alive requests:    0
Total transferred:      225475000 bytes
HTML transferred:       221400000 bytes
Requests per second:    6945.24 [#/sec] (mean)
Time per request:       3.600 [ms] (mean)
Time per request:       0.144 [ms] (mean, across all concurrent requests)
Transfer rate:          61171.03 [Kbytes/sec] received
gilbertoca commented 9 years ago

openSUSE 13.2 Intel(R) Core(TM) i5-2500 CPU @ 3.30GHz JSP

Document Path:          /jsp
Document Length:        8506 bytes

Concurrency Level:      25
Time taken for tests:   7.896 seconds
Complete requests:      25000
Failed requests:        0
Keep-Alive requests:    0
Total transferred:      218600000 bytes
HTML transferred:       212650000 bytes
Requests per second:    3166.22 [#/sec] (mean)
Time per request:       7.896 [ms] (mean)
Time per request:       0.316 [ms] (mean, across all concurrent requests)
Transfer rate:          27036.54 [Kbytes/sec] received

THYMELEAF

Document Path:          /thymeleaf
Document Length:        8856 bytes

Concurrency Level:      25
Time taken for tests:   9.406 seconds
Complete requests:      25000
Failed requests:        0
Keep-Alive requests:    0
Total transferred:      225475000 bytes
HTML transferred:       221400000 bytes
Requests per second:    2658.02 [#/sec] (mean)
Time per request:       9.406 [ms] (mean)
Time per request:       0.376 [ms] (mean, across all concurrent requests)
Transfer rate:          23410.79 [Kbytes/sec] received
jreijn commented 8 years ago

This is still interesting. I think I will try this out on a linux box to see if that makes any difference.

Vest commented 7 years ago

This issue is probably not relevant anymore, because we have Thymeleaf 3 (see #20).