Logging is often an overlooked performance drain on systems requiring high throughput. Here’s a simple change to the default Tomcat logging configuration to implement. It works on all operating systems.
In the file:
.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
.handlers = 1catalina.org.apache.juli.FileHandler
Categories: WebStandards, Work apache, configuration, linux, logging, performance, properties, server, tomcat, ubuntu, windows
These are useful for some advanced caching behavior, but there are cases where you might find them unnecessary for static files (in particular). Most network analysis tools will call attention to this header value, and while it seems like a trivial amount of bandwidth to send from the server to the client, the real reason for the negative score is more likely related to the behaviors that it causes in the client.
It should be noted that the default value used for the ETag is based upon the ‘inode’ of the file, as such it’s IS problematic in clustered server environments. I’ve shown the correction for this below.
Adding the following to your Apache http.conf file is a start:
# Change ETag to remove the iNode (for multi-server environments)
FileETag MTime Size
#Remove ETag from all static content, this could be done globally without the FilesMatch, but we want better control.
Header unset ETag
Categories: WebStandards, Work apache, browser, cache, caching, ETag, header, http, network, performance, server
Obviously “Cookies” have a lot of advantages in web applications to maintain “state”, unfortunately using standard server configurations leads to even static content serving them up un-necessarily wasting some (minimal) bandwidth.
Adding the following to the Apache httpd.conf file is a start:
Header unset Cookie
In my testing, you don’t need to fully embrace HTML5 markup to take advantage of the “offline” functionality, you simply need to add the attribute and related files to your existing website/page. Any modern browser that supports HTML5 should automatically recognize the offline content and use it when appropriate, unfortunately no version of MSIE yet supports this.
In that file, you must then specify the offline behavior, something like this is a good start:
#This is to provide minimal HTML5 offline capabilities
#MIME mapping must be 'appcache=text/cache-manifest'
#Reference to this file is per page, you can have different ones in an app.
#Common image files and css may be 'cached'
On the server side, you’ll have to serve up that file with the appropriate MIME type (
text/cache-manifest, for ApacheHTTPD you simply need to add one line to httpd.conf:
AddType text/cache-manifest .appcache
Categories: MSIE bugs, WebStandards, Work apache, appcache, application, cache, conf, html, html5, http, manifest, offline
There may come a time when you want to change server behaviors for a specific path on your web server. Often times this becomes necessary if you host web sites that the customer wants to manage externally.
There are only a few small changes required:
- In your httpd.conf file…
# use .htaccess files for overriding,
# and never show any file starting with .ht
<files ~ "^\.ht">
Deny from all
- The for the paths (or virtual hosts, you’ll need to add this line):
- Add the appropriate .htaccess files where needed.
DISCLAIMER: This technique CAN result in performance improvements, but should be put in your main server configuration file (httpd.conf), rather than in .htaccess files. .These files, by their very nature, cause performance degradation on your website, and so should be avoided whenever possible as they require an increase in file I/O (reads) on the server.
This is a relatively common problem in JSP based apps as you need to understand the configuration. It’s further complicated if you use Apache HTTPD in front of the Apache Tomcat server to process requests as you need to know where each request is processed.
For this example, we will use the standard 404 error, but you can also intercept other errors for custom pages.
- create 404.jsp
<% final SimpleDateFormat simpleDate = new SimpleDateFormat(”EE MMM dd yyyy hh:mm:ss aa zzz”);
final String dttm = simpleDate.format(new Date()); %>
<title>404 Not Found</title>
<li>Time: <%= dttm %></li>
<li>User-Agent: <%= request.getHeader(”User-Agent”) %></li>
<li>Server: <%= request.getServerName() %></li>
<li>Request: <%= request.getRequestURI() %></li>
<li>Remote: <%= request.getRemoteAddr() %></li>
<li>Referer: <%= request.getHeader(”Referer”) %></li>
- in WEB-INF/web.xml – add the following (NOTE: location within the file is important but outside the scope of this post)
- You might want to force the HTTP Header to give something other than a ‘404 status’ code, otherwise MSIE will show an unstyled ‘friendly error message’ if the user has not turned off the default setting. Unfortunately, this also means that search engines might index these pages that should not exist.
Categories: MSIE bugs, WebStandards, Work 404, apache, error, html, http, jsp, networking, page, tomcat
This one escaped me for a long time and I never saw a decent example of it in any of the documentation.
GZip compression saves on network bandwidth as files are compressed during transport between the HTTP Server and browser/client. If you already use Apache HTTP or a similar webserver to front Tomcat, this is not always necessary, but in cases where you expose your appserver directly, even if it is just for testing, you may want to add this configuration item as it increases the perceived speed of the application.
The solution is simple:
- To be safe, first stop the server and backup your configuration files
- Look in the /TOMCAT/conf installation folder.
- In the ’server.xml’ file, you will find a line resembling…
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
- This one controls the HTTP/1.1 connections, add a new value to the list…
- NOTE You might also see a value for for AJP/1.3, unfortunately compression only works for HTTP:
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
- Restart your server.
If you have ever looked at the console or logs while starting a Tomcat instance on Windows you have probably seen the following line about APR.
INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path
As long as the “tcnative-1.dll” is in the Windows PATH, generally you can place it in c:\windows\system32, but any other location in the PATH will work should you need it to be portable, or have different versions in use.
NOTE: Other Operating Systems use a similar approach as Windows to add an environmental variable, optionally you can also add the appropriate location to the “java.library.path” attribute used when calling the VM, if you are more technically inclined.
Occasionally, there becomes a need to expose the use of the .htaccess file to the domains hosted on your Apache server. This technique is particularly useful when you host websites for external clients (or developers).
The steps to enable it are relatively easy,
Uncomment the ‘httpd.conf’ line that reads as:
LoadModule rewrite_module modules/mod_rewrite.so
Review (and replace as appropriate) all cases of :
AllowOverride None with
in the following files:
httpd.conf, /extra/httpd-vhosts.conf, /extra/httpd-autoindex.conf and any related files you may be using.
- Add the .htaccess file into the appropriate websites/folders
- Restart the server to accept the changes
NOTE: If you develop or host on Windows, you’ll likely have problems creating the file because there is no filename, just a file extension. You can create (or download) it from any non-Windows host and use it without additional changes. Apache does let you use a different filename, but you also need to be careful to update related security configuration that is used to prevent download of such files.
If you do any development or even production testing with Apache Tomcat, you may have seen the following message in your logs.
“The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path”
Here’s a quick solution that will leave you with greatly improved performance.
- Go to the following URI’s:
- Download the appropriate version of tcnative-1.dll
- For Windows, place that file in c:\windows\system32\
- Restart your Tomcat server
- You are done!