Your browser (Internet Explorer 7 or lower) is out of date. It has known security flaws and may not display all features of this and other websites. Learn how to update your browser.

X

Navigate / search

Liferay 6.1 Performance: serving static resources through Apache Web server

It is known fact that if we serve static resources like images, java script, css etc. through web server then we can improve response time. This fact also applies to Liferay portal as well. By default static resources of Portal, Portlet and Themes are served through Liferay portal server. Liferay portal adds certain overhead like servlet filters to serve these static resources. If we serve these static resources directly from web server then we can improve the response time. In majority of the production deployments web server is used in front of Liferay portal servers. This blog provides step by step guide to configure Apache Web server to serve static resource.
Configuration Steps
These configuration steps are based on the assumption that we have one apache server in front of one Liferay tomcat bundle. We are going to use mod_jk connector to connect Apache Web server and Liferay Portal server. Configuration also assumes we have bot apache web server and Liferay portal server on the same machine.

 

Step 1   As a first step we need to copy static resources on Apache Web server document root directory. Copy all the directories except ROOT directory from {CATALINA_HOME}\webapps\ to Apache web server document root ({APACH_HOME}\htdocs). The from the {CATALINA_HOME}\webapps\ROOT directory copy html and layouttpl to {APACH_HOME}\htdocs directory.

NOTE: We copied whole directories just to make it simple. Ideally we should copy only static resource files including their folder structure. For actual deployment a script can be written to do this task.

Step 2   Now we will configure mod_jk configuration file. Before doing that we need to download mod_jk binary and put it in modules directory of Apache web server. (You can download mod_jk binary from http://apache.techartifact.com/mirror//tomcat/tomcat-connectors/jk/binaries
Step 3   As a first step we will create worker.properties file in {APACH_HOME}\conf directory. Add following details in worker.properties.

In the worker.properties provided configuration to connect Liferay Portal tomcat server to apache web server using AJP protocol. Tomcat is by default configured with AJP connector and listens on 8009 port for AJP requests. You can find AJP connector configuration in server.xml file of tomcat server. 

Step 4   Now create httpd-mod_jk.conf file in {APACH_HOME}\conf directory and add following content in the file.
In this file we loaded mod_jk connector in apache web server and provided reference to worker.properties file. Which tells apache mod_jk connector to connect with Liferay tomcat server. We also provided log file configuration. Then we mapped all the requests to mod_jk connector by adding JkMount /* worker1. Which means all the request received by apache web server will be delegated to Liferay portal server. Then we unmount static resource requests from tomcat server by adding Jkunmount lines. So altogether this configuration tells that all requests except static resource requests should be served by tomcat and static resource requests should be served by apache web server from its document root.
Step 5   We added mod_jk configuration in httpd-mod_jk.conf. So now we need to wire this configuration in apache web servers main configuration file (httpd.conf). So add following line at the bottom of httpd.conf file.
Step 6   That’s it. So we are done with the configuration. Now restart apache web server and test the configuration.

Summary

So we configured static resources to be served from apache web server. In practice we found that by implementing this we can improve response time by at least 20-30%. If we have CDN in our deployment architecture then this is not required. Also we need to note that by implementing this configuration, we need one additional step in deployment process to copy static resources on apache web server. This should be automated using deployment scripts.

Samir Bhatt

I am Samir Bhatt. I have more than 12 years of experience in IT Industry. I have been performing role of Software Architect since last four years. I am focused on open source technologies. I have specialized knowledge of Liferay Portal and has written two books on the subject. I lead Liferay practice in my organization with a strength of more than 140+ people. I am also Certified Liferay Trainer and conducted many public and private Liferay trainings across the world. Apart from Liferay I have good knowledge of Big Data technologies like MongoDB, Apache Hadoop. Throughout my carrier I worked on variety of technologies & Frameworks that includes JAVA, J2EE,Visual Basic, Oracle PLSQL, Spring Framework, Struts, Hibernate,Liferay, Pentaho and so on.

Comments

Aldo
Reply

Hi Samir,

if I understand correctly you did not include the CSS files ? Any specific reason ?

Samir Bhatt
Reply

Liferay has introduced dynamic CSS from Liferay 6.1. The are processed by filter before actually sent to browser. Hence they are not included.

Liferay US
Reply

Great article but Liferay was never written with apache+cdn in mind. Details here @ http://www.liferay.us/4/liferay-cdn-setup-test1

How will you copy following to Apache?

/combo/*
/html/js/barebone.jsp
/html/js/everything.jsp
/image/*

We did some mod_perl trick and were able to terminate almost everything @ Apache that doesn’t need portal container.

Samir Bhatt
Reply

Hi,

As mentioned my article images will be served through apache. I have unmounted images based on extension. About everything.jsp and barebone.jsp we need to put generated jsp files on apache web server and then unmount urls of these two jsp files. You can refer my book Liferay Portal Performance Best Practices (http://bit.ly/11A4SdG), in which I provided this in more details. About /combo/* files I don’t think so they are combined by ComboServlet based on the request parameter.

Leave a comment

name

email (not published)

website

Current month ye@r day *