DWRComet4j在Nginx+Tomcat组合下的优化
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DWRComet4j在Nginx+Tomcat组合下的优化相关的知识,希望对你有一定的参考价值。
DWR、Comet4j这类推送框架在Tomcat下运行正常,但在nginx+tomcat组合下,可能会出现断连、延迟等各种问题。
如出现此类问题,可尝试以下优化方式:
1.Nginx-----nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip off; #关闭gzip
server {
listen 80;
server_name localhost:8080;
location / {
proxy_connect_timeout 60s;
proxy_read_timeout 5400s;
proxy_send_timeout 5400s;
proxy_pass http://localhost:8080;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
2.Tomcat-----server.xml
<Connector connectionTimeout="20000" port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" redirectPort="8443"/>
3.Comet4j-----web.xml
<!-- ****************************comet4j开始*************************** --> <listener> <listener-class>org.comet4j.core.CometAppListener</listener-class> </listener> <listener> <description>Observer</description> <listener-class> org.comet4j.listener.GPSAlarmObserver</listener-class> </listener> <servlet> <display-name>CometServlet</display-name> <servlet-name>CometServlet</servlet-name> <servlet-class>org.comet4j.core.CometServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>CometServlet</servlet-name> <url-pattern>/cometConn</url-pattern> </servlet-mapping> <!-- Comet4J可选参数配置--> <context-param> <description>语言[支持:zh,en,默认:zh,详细http://www.loc.gov/standards/iso639-2/php/English_list.php]</description> <param-name>Comet.Language</param-name> <param-value>zh</param-value> </context-param> <context-param> <description>请求超时时间/微妙[默认:60000,1分钟,建议至少设置3秒以上]</description> <param-name>Comet.Timeout</param-name> <param-value>60000</param-value> </context-param> <context-param> <description>连接空闲过期时间/微妙[默认:5000,5秒]</description> <param-name>Comet.ConnExpires</param-name> <param-value>15000</param-value> </context-param> <context-param> <description>连接检查频率/微妙[默认:5000,5秒]</description> <param-name>Comet.ConnFrequency</param-name> <param-value>15000</param-value> </context-param> <context-param> <description>缓存信息过期时间/微妙[默认:60000,1分种]</description> <param-name>Comet.CacheExpires</param-name> <param-value>60000</param-value> </context-param> <context-param> <description>缓存信息过期检查频率/微妙[默认:60000,1分种]</description> <param-name>Comet.CacheFrequency</param-name> <param-value>60000</param-value> </context-param> <context-param> <description>连接模式[auto(默认)/stream/lpool]</description> <param-name>Comet.WorkStyle</param-name> <param-value>lpool</param-value> </context-param> <context-param> <description>开启调试[false(默认)/true]</description> <param-name>Comet.Debug</param-name> <param-value>true</param-value> </context-param> <!-- ****************************comet4j结束*************************** -->
4.DWR-----web.xml
<servlet> <servlet-name>dwr-invoker</servlet-name> <servlet-class> org.directwebremoting.servlet.DwrServlet </servlet-class> <init-param> <param-name>allowGetForSafariButMakeForgeryEasier</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>crossDomainSessionSecurity</param-name> <param-value>false</param-value> </init-param> <init-param> <param-name>allowScriptTagRemoting</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>classes</param-name> <param-value>java.lang.Object</param-value> </init-param> <init-param> <param-name>activeReverseAjaxEnabled</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>initApplicationScopeCreatorsAtStartup</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>maxWaitAfterWrite</param-name> <param-value>100</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>logLevel</param-name> <param-value>WARN</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>dwr-invoker</servlet-name> <url-pattern>/dwr/*</url-pattern> </servlet-mapping>
<body onload="init();dwr.engine.setActiveReverseAjax(true);dwr.engine.setNotifyServerOnPageUnload(true);">
以上是关于DWRComet4j在Nginx+Tomcat组合下的优化的主要内容,如果未能解决你的问题,请参考以下文章