Apache-2.2

Apache2 mod_proxy 到遠端 Tomcat7 - 響應慢

  • November 4, 2012

被這個卡住了幾天。將嘗試提供盡可能多的資訊,但請隨時詢問更多詳細資訊。

我在 NAT 後面有 2 個虛擬機,192.168.0.100 和 192.168.0.102,它們都執行 Ubuntu 11.04 x64。第一個映射到外部,是我們的網路伺服器,安裝了一個 Apache/2.2.17 和幾個虛擬主機來提供靜態內容,還有 mod_jk 用於負載平衡。第二個安裝了帶有多個 J2EE REST web 服務但沒有 apache 的 tomcat 7 - 請求預計將直接從 .100 apache 傳遞到 .102 tomcat。我打算準備一個tomcat集群環境。

我的問題:請求到達 192.168.0.100 沒有任何問題,但是大約需要100 秒才能使數據實際到達 .102 - 那時 apache 已經超時,但 tomcat 接收並正常處理請求。這在使用 mod_jk、mod_proxy 或 mod_ajp_proxy 時都會發生。不知道為什麼,因為兩台機器上都沒有防火牆,所以兩者都是可 ping 的——不僅如此,還有 NFS 共享像一個魅力一樣活躍——而且 mod_proxy 的經驗表明直接來自 .100 的請求可以正常處理。

此外,為了雪上加霜,我們的辦公網路也設置了類似的環境。一切都很完美。-_- 唯一的區別?我們在辦公室沒有 IP 翻譯,所有事情都是通過內部地址來做的——不知道這是否有任何關係。

一些配置:

阿帕奇虛擬主機:

<VirtualHost *:80>
   ServerAdmin webmaster@localhost
   DocumentRoot /var/www/
   ServerName www.example.com

   ProxyRequests Off
   <Proxy *>
           Options Indexes FollowSymLinks MultiViews
           AllowOverride all
           Order allow,deny
           allow from all
   </Proxy>

   ProxyPass /bork http://192.168.0.102:8080/bork
   ProxyPassReverse /bork http://192.168.0.102:8080/bork
   LogLevel debug

   CustomLog ${APACHE_LOG_DIR}/api_access.log combined
   ErrorLog ${APACHE_LOG_DIR}/api_error.log
</VirtualHost>

Tomcat 連接器

<Connector port="8080" protocol="HTTP/1.1"
          connectionTimeout="20000"
          redirectPort="8443" />
<Connector port="8009"
   enableLookups="false"
   redirectPort="8443"
   protocol="AJP/1.3"
/>

以及來自 apache 的調試日誌,來自使用 mod_proxy_ajp 的測試。mod_proxy 中的行為幾乎相同,至少在延遲方面。請注意,tomcat 最終會接收並處理請求,或多或少是在日誌再次開始更新時:

[Sun May 06 14:40:33 2012] [debug] proxy_util.c(1506): [client 188.81.234.2] proxy: ajp: found worker ajp://192.168.0.102:8008/bork for ajp://192.168.0.102:8008/bork/SSOIdentityProviderSoap
[Sun May 06 14:40:33 2012] [debug] mod_proxy.c(1015): Running scheme ajp handler (attempt 0)
[Sun May 06 14:40:33 2012] [debug] mod_proxy_ajp.c(661): proxy: AJP: serving URL ajp://192.168.0.102:8008/bork/SSOIdentityProviderSoap
[Sun May 06 14:40:33 2012] [debug] proxy_util.c(2011): proxy: AJP: has acquired connection for (192.168.0.102)
[Sun May 06 14:40:33 2012] [debug] proxy_util.c(2067): proxy: connecting ajp://192.168.0.102:8008/bork/SSOIdentityProviderSoap to 192.168.0.102:8008
[Sun May 06 14:40:33 2012] [debug] proxy_util.c(2193): proxy: connected /bork/SSOIdentityProviderSoap to 192.168.0.102:8008
[Sun May 06 14:40:33 2012] [debug] proxy_util.c(2444): proxy: AJP: fam 2 socket created to connect to 192.168.0.102
[Sun May 06 14:40:33 2012] [debug] ajp_header.c(224): Into ajp_marshal_into_msgb
[Sun May 06 14:40:33 2012] [debug] ajp_header.c(290): ajp_marshal_into_msgb: Header[0] [Accept-Encoding] = [gzip,deflate]
[Sun May 06 14:40:33 2012] [debug] ajp_header.c(290): ajp_marshal_into_msgb: Header[1] [Content-Type] = [text/xml;charset=UTF-8]
[Sun May 06 14:40:33 2012] [debug] ajp_header.c(290): ajp_marshal_into_msgb: Header[2] [SOAPAction] = [""]
[Sun May 06 14:40:33 2012] [debug] ajp_header.c(290): ajp_marshal_into_msgb: Header[3] [User-Agent] = [Jakarta Commons-HttpClient/3.1]
[Sun May 06 14:40:33 2012] [debug] ajp_header.c(290): ajp_marshal_into_msgb: Header[4] [Host] = [www.example.com]
[Sun May 06 14:40:33 2012] [debug] ajp_header.c(290): ajp_marshal_into_msgb: Header[5] [Content-Length] = [520]
[Sun May 06 14:40:33 2012] [debug] ajp_header.c(450): ajp_marshal_into_msgb: Done
[Sun May 06 14:40:33 2012] [debug] mod_proxy_ajp.c(267): proxy: APR_BUCKET_IS_EOS
[Sun May 06 14:40:33 2012] [debug] mod_proxy_ajp.c(272): proxy: data to read (max 8186 at 4)
[Sun May 06 14:40:33 2012] [debug] mod_proxy_ajp.c(287): proxy: got 520 bytes of data
[Sun May 06 14:40:33 2012] [debug] ajp_header.c(687): ajp_read_header: ajp_ilink_received 06
[Sun May 06 14:40:33 2012] [debug] ajp_header.c(697): ajp_parse_type: got 06
[Sun May 06 14:40:37 2012] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 2 in child 5916 for worker ajp://192.168.0.100:8008/coding
[Sun May 06 14:40:37 2012] [debug] proxy_util.c(1837): proxy: worker ajp://192.168.0.100:8008/coding already initialized
[Sun May 06 14:40:37 2012] [debug] proxy_util.c(1934): proxy: initialized single connection worker 2 in child 5916 for (192.168.0.100)
[Sun May 06 14:40:37 2012] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 3 in child 5916 for worker http://192.168.0.102:8080
[Sun May 06 14:40:37 2012] [debug] proxy_util.c(1837): proxy: worker http://192.168.0.102:8080 already initialized
[Sun May 06 14:40:37 2012] [debug] proxy_util.c(1934): proxy: initialized single connection worker 3 in child 5916 for (192.168.0.102)
[Sun May 06 14:40:37 2012] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 4 in child 5916 for worker ajp://192.168.0.102:8008/bork
[Sun May 06 14:40:37 2012] [debug] proxy_util.c(1837): proxy: worker ajp://192.168.0.102:8008/bork already initialized
[Sun May 06 14:40:37 2012] [debug] proxy_util.c(1934): proxy: initialized single connection worker 4 in child 5916 for (192.168.0.102)
[Sun May 06 14:40:38 2012] [debug] proxy_util.c(1934): proxy: initialized single connection worker 2 in child 5918 for (192.168.0.100)
[Sun May 06 14:40:38 2012] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 3 in child 5918 for worker http://192.168.0.102:8080
[Sun May 06 14:40:38 2012] [debug] proxy_util.c(1837): proxy: worker http://192.168.0.102:8080 already initialized
[Sun May 06 14:40:38 2012] [debug] proxy_util.c(1934): proxy: initialized single connection worker 3 in child 5918 for (192.168.0.102)
[Sun May 06 14:40:38 2012] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 4 in child 5918 for worker ajp://192.168.0.102:8008/bork
[Sun May 06 14:40:38 2012] [debug] proxy_util.c(1837): proxy: worker ajp://192.168.0.102:8008/bork already initialized
[Sun May 06 14:40:38 2012] [debug] proxy_util.c(1934): proxy: initialized single connection worker 4 in child 5918 for (192.168.0.102)
[Sun May 06 14:40:38 2012] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 2 in child 5917 for worker ajp://192.168.0.100:8008/coding
[Sun May 06 14:40:38 2012] [debug] proxy_util.c(1837): proxy: worker ajp://192.168.0.100:8008/coding already initialized
[Sun May 06 14:40:38 2012] [debug] proxy_util.c(1934): proxy: initialized single connection worker 2 in child 5917 for (192.168.0.100)
[Sun May 06 14:40:38 2012] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 3 in child 5917 for worker http://192.168.0.102:8080
[Sun May 06 14:40:38 2012] [debug] proxy_util.c(1837): proxy: worker http://192.168.0.102:8080 already initialized
[Sun May 06 14:40:38 2012] [debug] proxy_util.c(1934): proxy: initialized single connection worker 3 in child 5917 for (192.168.0.102)
[Sun May 06 14:40:38 2012] [debug] proxy_util.c(1818): proxy: grabbed scoreboard slot 4 in child 5917 for worker ajp://192.168.0.102:8008/bork
[Sun May 06 14:40:38 2012] [debug] proxy_util.c(1837): proxy: worker ajp://192.168.0.102:8008/bork already initialized
[Sun May 06 14:40:38 2012] [debug] proxy_util.c(1934): proxy: initialized single connection worker 4 in child 5917 for (192.168.0.102)
[Sun May 06 14:42:09 2012] [debug] ajp_header.c(687): ajp_read_header: ajp_ilink_received 04
[Sun May 06 14:42:09 2012] [debug] ajp_header.c(697): ajp_parse_type: got 04
[Sun May 06 14:42:09 2012] [debug] ajp_header.c(516): ajp_unmarshal_response: status = 200
[Sun May 06 14:42:09 2012] [debug] ajp_header.c(537): ajp_unmarshal_response: Number of headers is = 1
[Sun May 06 14:42:09 2012] [debug] ajp_header.c(599): ajp_unmarshal_response: Header[0]     [Content-Type] = [text/xml;charset=utf-8]
[Sun May 06 14:42:09 2012] [debug] ajp_header.c(609): ajp_unmarshal_response: ap_set_content_type done
[Sun May 06 14:42:09 2012] [debug] ajp_header.c(687): ajp_read_header: ajp_ilink_received 03
[Sun May 06 14:42:09 2012] [debug] ajp_header.c(697): ajp_parse_type: got 03
[Sun May 06 14:42:09 2012] [debug] ajp_header.c(687): ajp_read_header: ajp_ilink_received 03
[Sun May 06 14:42:09 2012] [debug] ajp_header.c(697): ajp_parse_type: got 03
[Sun May 06 14:42:09 2012] [debug] ajp_header.c(687): ajp_read_header: ajp_ilink_received 05
[Sun May 06 14:42:09 2012] [debug] ajp_header.c(697): ajp_parse_type: got 05
[Sun May 06 14:42:09 2012] [debug] mod_deflate.c(615): [client 188.81.234.2] Zlib: Compressed 447 to 255 : URL /bork/SSOIdentityProviderSoap
[Sun May 06 14:42:09 2012] [debug] mod_proxy_ajp.c(570): proxy: got response from (null) (192.168.0.102)
[Sun May 06 14:42:09 2012] [debug] proxy_util.c(2029): proxy: AJP: has released connection for (192.168.0.102)
[Sun May 06 14:42:09 2012] [info] [client 188.81.234.2] Request body read timeout

想知道是否有人可以提供一些建議,甚至指出任何可怕的、可怕的配置錯誤?提前致謝!

這幾乎可以肯定是 DNS。檢查從 0.102 反向 DNS 查找 0.100 的時間。

引用自:https://serverfault.com/questions/387025