Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web application deployed on tomcat is slow on first access?

We have a Spring MVC web application deployed on Tomcat 7. Every time I deploy a new build, it runs very slowly for first time. Even the login page takes time to come up.

What would be the reason for this and what can be done to make it faster?

like image 578
ashishjmeshram Avatar asked Oct 12 '12 11:10

ashishjmeshram


2 Answers

This is a valid scenario. Your server load the servlets and action on first heat. So it will be slow on first access.

You can set the <loadonstartup>1</loadonstartup> in web.xml.

The above option will load required files on server startup.

like image 60
Gunjan Shah Avatar answered Oct 19 '22 15:10

Gunjan Shah


If you are using Spring annotations make sure you have the correct packages configured in the <component:scan /> tag. That is do not include the same package(s) to scan in applicationContext.xml and xxx-servlet.xml file. Spring will scan them twice otherwise, I have seen this.

Also remember any JSPs will be compiled the first you use them, so this will be slower on first hit.

like image 1
Ayub Malik Avatar answered Oct 19 '22 15:10

Ayub Malik