Fine Tuning Performance
I'm going to assume a couple of things. One is that you know what you're doing on a nix box and that you can alter file paths to suit yourself. I'm also assuming that this is a production server - meaning that you're not deploying stuff on it frequently (like new themes). You also need to know your fully qualified domain name (FQDN) Another is that you know what kind of hardware you actually have - in particular how much RAM. This particular tutorial is for Liferay 5.2.3 running on Ubuntu LTS 8.04 (Hardy Heron) Tomcat 6, and MySQL 5. That said, it should be pretty similar for the same bundle (Tomcat6 and Liferay 5.2.3) on Windows.
Don't install any of the other java packages. Install Sun's Java 6. We have seen some modest performace gains with 6 over 5 and with using Sun's java over some of the other java packages.
If you're on any Ubuntu distro, you can type in "aptitude install sun-java6-bin sun-java6-jdk sun-java6-jre" and it will fetch the right stuff.
If you're on Windows, you can get this from www.java.com. Make sure that you get the entire JDK (Java Developer Kit) and not just the JVM (Java Virtual Machine).
Now we start setting envrionment variables. If you're on Ubuntu, you set that in /etc/environment and it will go system-wide. Setting them instead of making the server fetch them or figure them out seems to result in some modest performance gains. Make sure that JAVA_HOME and JRE_HOME are set appropriately. You may also want to set CATALINA_HOME, CATALINA_BASE, and CATALINA_TMPDIR.
My JAVA_HOME is /usr. My CATALINA_BASE: /opt/liferay-portal-5.2.4/tomcat-6.0.18. My CATALINA_HOME: /opt/liferay-portal-5.2.4/tomcat-6.0.18. My CATALINA_TMPDIR: /opt/liferay-portal-5.2.4/tomcat-6.0.18/temp. My JRE_HOME: /usr/lib/jvm/java-6-sun.
If you're on windows, you can set your enviroment variables by right-clicking My Computer, going to properties, and then the "Advanced Tab". Your mileage may vary and it will certainly be different on Windows. On my desktop, the JAVA_HOME is C:
Program Files\Java\jdk1.6.0_13. CATALINA_BASE = where you have tomcat and is probably the same as CATALINA_HOME. JRE_HOME will be where the JVM lives.
First, we're going to go edit the portal-ext.properties file. You know it... It gets tweaked out the wazoo in order get your instance running like you want it, so you should know where to find it. If you don't have one yet, you will HAVE to create it. Just open up a text editor and make one. It goes in .../liferay-bundle/tomcat_version/webapps/ROOT/WEB-INF/classes directory. You can subsitute the bundle and version in the file path and the ... for your particular installation. This section will be same regardless of operating system.
Note: It's fairly important that you understand that these things go into the TOP of your portal-ext.properties. We have seen some tiny performance gains by placing them in the very TOP of the file, so location within the portal-ext.properties does seem to matter.
Stuff you need to put in your file will be show in italics.
First, be sure you declare you host name explicity. It seems to speed things up if the server doesn't have to figure out who it is. This should be the very first entry in your file. You will need to know your Fully Qualified Domain Name (FQDN). If you don't, get it from your network administrator. If you're not sure what it is, Google is your friend. DNS is beyond the scope of this document.
#Set the Host name web.server.host=my.fqdn.hostname
Next, you're going to set your database connection stuff. This should be the SECOND thing in your file. Note: You will only use the IP address if you've set your MYSQL instance to accept network connections. Otherwise it will simply be localhost.
#MySQL Options jdbc.default.driverClassName=com.mysql.jdbc.Driver jdbc.default.url=jdbc:mysql://my.i.p.address.here/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false jdbc.default.username=mydatabaseuser jdbc.default.password=mydatabasepassword
Unless you REALLY need it, turn off the Hibernate stuff
#Turn off Hibernate Stuff hibernate.bytecode.use_reflection_optomizer=false hibernate.cache.use_minimal_puts=false hibernate.cache.use_query_cache=false hibernate.cache.use_second_level_cache=false hibernate.cache.use_structured_entries=false
Now, we get to the real meat here - setting the stuff that will give you the MOST performance boost. With the exception of the theme.css.fast.load and theme.images.fast.load, you can set them to what you for your server. However, this should be the THIRD thing in your file.
#Set Up Some Performance Tags theme.css.fast.load=true theme.images.fast.load=true theme.portlet.decorate.default=true theme.porlet.sharing.default=true portlet.css.enabled=false
Note: If you want to do any kind of virtual hosting via an Apache front-end, now is a really good time to configure your context. You'll want to do that before you get started really adding pages to Liferay. Otherwise, if you decide to do it later, you'll be changing all of your links, URL pages, etc.
Be sure to add this to your portal-ext.properties files. Keep in mind you can change /portal to anything that strikes your fancy. I'm just using this as an example.
The reason for this is that when you add a context other than the "ROOT" it changes the URL. Instead of www.myserver.com:8080/web/guest, you would have www.myserver.com:8080/portal/web/guest.
Ok, save the porlet-ext.properties and keep rolling. Next we go look at tomcat.
First, you will want to make sure that you have the tomcat native libs installed. You can get this as a package from the repository. It is in backports as I recall. Edit your /etc/apt/sources.list so that you can get the backports. I'm not going to put directions here on how to do that. You can Google for it.
sudo aptitude install libtcnative1
That will install it for you. That results in a really modest performance gain but all this stuff is cumulative. We keep shaving a little here and a little there and pretty soon it all adds up to a nice performance bonus.
Note: On some systems, you will need to disable IPV6 networking. If you actually need the IPV6 stuff, you will want to build and install the Tomcat libs from source and not use the Ubuntu package. Failure to start with IPV6 enabled is a known issue with the Ubuntu package.
Next we go edit the server.xml. Make a copy before you start editing, just in case. The stuff that's already in your file will be underlined and the stuff that we're replacing it with will be in italics.
sudo cp server.xml server.1
It's always good system administration practice to keep incremental copies of configuration files so that you can roll back easily if you accidentally create a problem.
Now we're going to edit it. Somewhere around line 68 you'll see...
connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" />
We're going to replace that with....
maxHttpHeaderSize="8192" maxSpareThreads="75" enableLookups="false" acceptCount="100" loadTimeout="true" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" />
Now save that and we're done here...
Note: You can change the "acceptCount" but if you do, keep track of that number since you'll need it to tune the database.
Now we're going to go edit the /etc/my.cnf and tune MySQL a bit.
Find your key_buffer and set it to 20% of your physical RAM. That DOES NOT include swap space or anything other than RAM.
Set your max_allowed_packet to at least 16MB if it isn't already.
Set your max_connections to what ever you have in your server.xml for accept count. In our case, that's 100.
Set your table_cache to at least 64 if its not already there.
Save that and restart mysql.