flow icon indicating copy to clipboard operation
flow copied to clipboard

Performance Issues using Undertow compared to Tomcat

Open masbaehr opened this issue 7 years ago • 6 comments

With Vaadin 12.0.3 i am seeing some performance issues when Undertow is used as a underlying Server environment. The same does not happen with Tomcat.

I'm trying to figure out what might cause the issue and i noticed this hot spot using JProfiler. This Call adds about 138ms to a request. Could you help me figuring out what the issue could be?

The exact same request using Tomcat takes about 25ms while on Undertow it takes about 400ms. Generally i noticed that Tomcat is a LOT faster than both Undertow and Jetty while using Vaadin. While there are differences between in general, this can not explain such a huge difference for the same request. So i'm currently lost.. Any idea?

image

masbaehr avatar Jan 06 '19 10:01 masbaehr

I guess this has to do with how we're spamming ServletContext::getResource and/or ServletContext::getResourceAsStream when trying to determine whether there are theme-specific variants of any imports. It's possible that those methods are significantly more complex in Undertow compared to Tomcat.

This is something that we suspected might need some caching on our end, but that hasn't yet been the topmost priority. We might want to prioritize it higher based on these findings.

Legioth avatar Jan 07 '19 08:01 Legioth

Using Vaadin Platform 12.0.3 and Spring Boot, informal testing trying Tomcat, Jetty, and Undertow show a meaningful visual performance improvement when using Tomcat as compared to Jetty and Undertow with Undertow being the worst. In Tomcat, pages load almost instantaneously while in Undertow most pages show the Vaadin "loading bar" across the top.

Even attempted to use the latest version of Undertow with Spring and the same result.

implementation("org.springframework.boot:spring-boot-starter-undertow:${springBootVersion}") {
        exclude group: 'io.undertow', module: 'undertow-core'
        exclude group: 'io.undertow', module: 'undertow-websockets-jsr'
        exclude group: 'io.undertow', module: 'undertow-servlet'
    }  
	
	// Include latest version of Undertow - https://github.com/undertow-io/undertow/releases
	implementation "io.undertow:undertow-core:2.0.15.Final"
	implementation "io.undertow:undertow-websockets-jsr:2.0.15.Final"
	implementation "io.undertow:undertow-servlet:2.0.15.Final" 

integrigy avatar Jan 09 '19 02:01 integrigy

@masbaehr @integrigy can you please clarify, do you see this difference in performance only in development mode or also production mode ?

Partly related to https://github.com/vaadin/flow/issues/4928.

pleku avatar Jan 09 '19 13:01 pleku

I always use vaadin.productionMode: false for now as it is not correctly starting due to this error:

java.lang.IllegalArgumentException: Failed to find the bundle manifest file 'frontend://vaadin-flow-bundle-manifest.json' in the servlet context for 'ES6' browsers. If you are running a dev-mode servlet container in maven e.g. `jetty:run` change it to `jetty:run-exploded`. If you are not compiling frontend resources, include the 'vaadin-maven-plugin' in your build script. Otherwise, you can skip this error either by disabling production mode, or by setting the servlet parameter 'original.frontend.resources=true'.

If by development mode you mean exploded vs. packaged (jar) - The difference in performance is measurable in both. (Undertow way slower than Tomcat under all circumstances)

masbaehr avatar Jan 09 '19 13:01 masbaehr

@masbaehr that error means that you are probably running the dependency vaadin-server-production-mode instead of vaadin-server. When you are developing the app, as in development mode, you should use vaadin-server instead. Then for production mode, you need to add the dependency vaadin-server-production-mode (with Maven profile for instance) and because you will use the Maven plugin to make a production build of the frontend resources, that error will not happen. See https://vaadin.com/docs/v12/flow/production/tutorial-production-mode-basic.html for more details.

The reason why I'm asking whether it occurs during production time is that during at that point, Flow doesn't have to check for the frontend resources imported in Components and polymer templates used, but it does do it at the moment. If the performance issue is still there when you run your application in production mode, then we need to take a look at optimizing things like this. Thus far we have not noticed it to be an issue.

pleku avatar Jan 10 '19 05:01 pleku

I'm not sure i can use that tutorial for my use-case. I don't need a *.war but a spring-boot "uber" runnable jar. Also i use Gradle and not Maven :/

That being said - even when developing - the performance hit with undertow is so big that i would not like to develop like that - instead i just use Tomcat for now ;)

masbaehr avatar Jan 10 '19 07:01 masbaehr