X

Blogs about Deep Learning, Machine Learning, AI, NLP, Security, Oracle Traffic Director,Oracle iPlanet WebServer

  • June 8, 2006

Dynamic compression of static files in Sun Java System Web Server 7.0

Dynamic compression of static files in Sun Java System Web Server 7.0



    Check out the new cool features in Sun Java
System Web Server 7.0 which can be downloaded for
free from http://www.sun.com/download/index.jsp?cat=Web%20%26%20Proxy%20Servers&tab=3&subcat=Web%20Servers .

In this blog I will talk about dynamic compression of static files.

    We have also implemented caching of compressed data
for static files. We have added a new service function "compress-file" which will
compress static files (if the compressed file doesn't exist) and serves
it from the cache if the compressed version already exists.


Lets say if I want to create .gz files on the fly for  static
files, all I have to do is to modify obj.conf as shown below. Use it
with find-compressed SAF.
Add it before send-file
function.

<Object
name="default">

...
NameTrans fn="assign-name" from="\*.html" name="find-compressed"

...
Service method=(GET|HEAD|POST)
type=\*~magnus-internal/\* fn=compress-file subdir=".compressed-files"


Service method=(GET|HEAD|POST) type=\*~magnus-internal/\* fn=send-file

...

</Object>


<Object name="find-compressed">

PathCheck fn="find-compressed"

</Object>
Note that subdir is a directory name only relative to the
directory in which the original
non-compressed file is located. "." means use the
same directory as the original file to create compressed files.



Parameters
this new "compress-file" SAF takes are subdir,
check-age(true), vary(true), compression-level(6), min-size(256),
max-size(1048576)
.


Let me take an example, if we have a static file in the docroot
static1.txt.
#
ls -al

-rwxr--r-- 1 root root 1386 Aug 1
21:16 static1.txt


Send a GET request with Accept-Encoding: gzip header,
it returns the compressed content,
#
telnet 0 2701

Trying 0.0.0.0...
Connected to 0.
Escape character is '\^]'.
GET /static1.txt HTTP/1.0
Accept-Encoding:
gzip


HTTP/1.1 200 OK
Server:
Sun-Java-System-Web-Server/7

Date: Mon, 01 Aug 2005 15:47:11
GMT

Content-length: 892
Content-type: text/plain
Vary: accept-encoding
Content-encoding: x-gzip
Last-modified: Mon, 01 Aug 2005
15:47:11 GMT

Accept-ranges: bytes
Connection: close

z`B®(¼?øKä0¢TeÑB¨÷Q$A
....
O9êÓÌ
iñÂ6ì¹­ ³Í§8z
ªè)óÍ6



We can verify that the Web Server creates a .gz file in .compressed-files subdirectory.
# ls -la
drwxr-xr-x 2 webservd webservd
512 Aug 1 21:17 .compressed-files

-rwxr-xr-x 1 root root 1386 Aug 1
21:16 static1.txt

# ls -l .compressed-files/
total 2
-rw------- 1 webservd webservd
892 Aug 1 21:17 static1.txt.gz



Also note that the content length on access file is the same as the .gz
file in the .compressed-files
directory.
#
tail ../logs/access

format=%Ses->client.ip% -
%Req->vars.auth-user% [%SYSDATE%] "%Req->reqpb.clf-request%"
%Req->srvhdrs.clf-status% %Req->srvhdrs.content-length%

abc.def.com - -
[01/Aug/2005:21:17:11 +0530] "GET /static1.txt HTTP/1.0" 200 892

...



Join the discussion

Comments ( 2 )
  • Joe McCabe Monday, February 26, 2007

    This may be obvious, but never-the-less:

    This requires that the document directories have write permission of UID that Web Server is running as. Lacking these permission will result in errors in the errors log indicating an inability to create the file structure.

    How aggressive is Web Server in checking for freshness of the compressed file vs the uncompressed original?

  • Meena Vyas Tuesday, March 6, 2007
    When the request comes to "compress-file" SAF or "find-compressed" SAF, if "check-age" is true, it compares the timestamp of the two files before serving it. You can set "check-age" to "false", for faster results in which case it will not compare the time stamps.
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.