관련 아티클 : http://sarc.io/index.php/jboss/231-apache-jboss-2gb-response-header-content-length

어디서 Content-Length 가 사라지는가? 에 대한 의문으로 추가 테스트를 진행합니다.

이번에는 response.setHeader("Content-Length", ... )하여 Header 에 명시적으로 Content-Length 를 넣었을 때, Apache-JBoss 상에서의 반응입니다.

테스트 방법 : 아무 내용이 없는 jsp 파일 내에 response.setHeader("Content-Length", ...) 사용함

참고로 2147483647 가 테스트의 중심에 있는 이유는 2GB (2*1024*1024*1024) 의 경계선에 있기 때문입니다. 

 

명시적으로 Content-Length 를 지정하였을 때, only JBoss 와 Apache - JBoss 의 차이

 

1. JBoss EAP (6.2)

- 2147483647 로 지정하였음

Content-Length:2147483647
Content-Type:text/html;charset=ISO-8859-1
Date:Fri, 12 Sep 2014 22:47:45 GMT
Server:Apache-Coyote/1.1
X-Powered-By:JSP/2.2

▶ 명시적으로 지정한 Content-Length 가 Header 에 잘 들어있습니다.

 

2. Apache (2.2.27) - JBoss EAP (6.2)

- 2147483647 로 지정하였음

Connection:Keep-Alive
Content-Length:31
Content-Type:text/html;charset=ISO-8859-1
Date:Fri, 12 Sep 2014 22:42:11 GMT
Keep-Alive:timeout=3, max=100
Server:Apache
X-Powered-By:JSP/2.2

▶ 명시적으로 지정한 Content-Length 가 아닌 실제 body 크기인 31 바이트로 Content-Length 가 표시됩니다.

 

FushPackets, FlushHeader 를 사용했을 때의 차이

 

여기까지는 Apache - JBoss 연동을 위한 mod_jk 설정에서,

JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

를 사용했습니다. (제가 default 로 사용하는 옵션입니다)

 

여기에 추가로 옵션을 사용해보려고 합니다. 관련된 옵션으로 추정되는 두 옵션은 다음과 같습니다.

JkOptions FlushPackets, you ask mod_jk to flush Apache's connection buffer after each AJP packet chunk received from Tomcat. This option can have a strong performance penalty for Apache and Tomcat as writes are performed more often than would normally be required (ie: at the end of each response).

JkOptions FlushHeader, you ask mod_jk to flush Apache's connection buffer after the response headers have been received from Tomcat. 

 

JkOptions 에 +FlushPackets 를 추가하고 테스트 합니다.

JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories +FlushPackets

결과는 다음과 같습니다.

Connection:Keep-Alive
Content-Type:text/html;charset=ISO-8859-1
Date:Fri, 12 Sep 2014 22:56:21 GMT
Keep-Alive:timeout=3, max=100
Server:Apache
Transfer-Encoding:chunked
X-Powered-By:JSP/2.2

Content-Length 가 2147483647 도 아니고 31 도 아니고 아예 없습니다. 대신 이번에는 Transfer-Encoding:chunked 로 설정되어 있습니다.

 

이번에는 JkOptions 에 +FlushHeader 를 추가하고 테스트 합니다.

JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories +FlushHeader

결과는 다음과 같습니다.

Connection:Keep-Alive
Content-Type:text/html;charset=ISO-8859-1
Date:Fri, 12 Sep 2014 23:03:32 GMT
Keep-Alive:timeout=3, max=100
Server:Apache
Transfer-Encoding:chunked
X-Powered-By:JSP/2.2

결과는 +FlushPackets 를 추가했던 경우와 동일합니다.

 

2147483647 바이트와 2147683646 바이트의 차이

 

혹시 명시적으로 Content-Length 로 지정한 2147483647 에 어떠한 의미가 있는 것은 아닐까요? 그래서 이제부터 그보다 하나 적은 숫자인 2147483646 으로 테스트하려고 합니다.

JBoss 에 직접 요청하면 문제 없을 것으로 생각되고, Apache - JBoss 상에서, 기본 설정(JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories) 에서 요청합니다.

Connection:Keep-Alive
Content-Length:31
Content-Type:text/html;charset=ISO-8859-1
Date:Fri, 12 Sep 2014 23:09:46 GMT
Keep-Alive:timeout=3, max=100
Server:Apache
X-Powered-By:JSP/2.2

Content-Length 가 31 로 2147483647 로 지정하나 2147483646 으로 지정하나 결과에 차이는 없습니다.

 

이번에는 Apache - JBoss 상에서, JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories +FlushPackets 설정에서 요청합니다.

Connection:Keep-Alive
Content-Length:2147483646
Content-Type:text/html;charset=ISO-8859-1
Date:Fri, 12 Sep 2014 23:14:39 GMT
Keep-Alive:timeout=3, max=100
Server:Apache
X-Powered-By:JSP/2.2

드디어 변화가 있습니다. 2147483647 으로 지정하였을 때는 Transfer-Encoding:chunked 되었는데, 이번에는 명시적으로 지정한 Content-Length 값인 2147483646 가 보입니다.

 

JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories +FlushHeader 로 테스트 했을 때도 마찬가지입니다.

Connection:Keep-Alive
Content-Length:2147483646
Content-Type:text/html;charset=ISO-8859-1
Date:Fri, 12 Sep 2014 23:14:39 GMT
Keep-Alive:timeout=3, max=100
Server:Apache
X-Powered-By:JSP/2.2

역시, 명시적으로 지정한 Content-Length 값인 2147483646 가 보입니다.

 

2147483646 바이트의 실제 크기의 파일을 요청했을 때의 차이

 

명시적으로 Content-Length 를 지정한 것이 아닌, 실제 그 크기의 파일을 요청했을 때는 어떤 결과가 나올지 추가 테스트합니다. 마지막 사용했던 JkOptions 인 JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories +FlushHeader 에서 계속합니다. 파일 크기는 2147483646 의 gz 파일입니다.

Accept-Ranges:bytes
Connection:Keep-Alive
Content-Length:2147483646
Content-Type:application/x-gzip
Date:Fri, 12 Sep 2014 23:57:57 GMT
ETag:W/"2147483646-1410566188000"
Keep-Alive:timeout=3, max=100
Last-Modified:Fri, 12 Sep 2014 23:56:28 GMT
Server:Apache

파일 크기대로 2147483646 바이트의 Content-Length 가 잘 표시됩니다.

 

이어서 기본 JkOptions 로 사용했던 JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories 에서 테스트합니다. 역시 파일 크기는 2147483646 의 gz 파일입니다.

 

Accept-Ranges:bytes
Connection:Keep-Alive
Content-Length:2147483646
Content-Type:application/x-gzip
Date:Sat, 13 Sep 2014 00:03:39 GMT
ETag:W/"2147483646-1410566188000"
Keep-Alive:timeout=3, max=100
Last-Modified:Fri, 12 Sep 2014 23:56:28 GMT
Server:Apache

마찬가지로 2147483646 바이트의 파일 크기대로 Content-Length 가 잘 표시됩니다.

 

2147483647 바이트의 실제 크기의 파일을 요청했을 때의 차이

 

많이 달려왔지요. 그러면 이제는 2147483646 가 아닌 2147483647 바이트의 파일을 요청했을 때 어떤 결과인지 테스트 합니다. 먼저 JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories +FlushHeader 입니다.

 

Connection:Keep-Alive
Content-Type:application/x-gzip
Date:Sat, 13 Sep 2014 00:07:01 GMT
ETag:W/"2147483647-1410566607000"
Keep-Alive:timeout=3, max=100
Last-Modified:Sat, 13 Sep 2014 00:03:27 GMT
Server:Apache
Transfer-Encoding:chunked

역시 예전처럼 Content-Length 는 표시되지 않고 Transfer-Encoding:chunked 가 표시됩니다.

 

이번에는 JkOptions 기본 옵션으로 사용했던 JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories 에서의 테스트입니다.

Accept-Ranges:bytes
Connection:Keep-Alive
Content-Type:application/x-gzip
Date:Sat, 13 Sep 2014 00:08:49 GMT
ETag:W/"2147483647-1410566607000"
Keep-Alive:timeout=3, max=100
Last-Modified:Sat, 13 Sep 2014 00:03:27 GMT
Server:Apache
Transfer-Encoding:chunked

동일합니다. Content-Length 는 표시되지 않고 Transfer-Encoding:chunked 가 표시됩니다.

 

이제까지의 테스트를 통해 명확히 알 수 있는 사실은, 경계는 2147483646 | 2147483647 이라는 것입니다. 즉, 2147483646 바이트까지는 Content-Length 가 잘 표시되지만, 2147483647 바이트부터는 Transfer-Encoding:chunked 로 표시된다는 것이죠.