??xml version="1.0" encoding="utf-8" standalone="yes"?>快乐12:BlogJava-xiaomage234-随笔分类 - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/xiaomage234/category/53838.html生命本就是一次凄美的漂流,记忆中放不下的,永远是孩提时代的那一份浪漫与纯真?/description>zh-cnThu, 12 Oct 2017 15:00:50 GMTThu, 12 Oct 2017 15:00:50 GMT60转: Nginx + Tomcat + HTTPS 配置不需要在 Tomcat 上启?SSL 支持 - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/xiaomage234/archive/2017/10/12/432853.html小马?/dc:creator>小马?/author>Thu, 12 Oct 2017 03:02:00 GMT//www.ot7t.com.cn/xiaomage234/archive/2017/10/12/432853.html//www.ot7t.com.cn/xiaomage234/comments/432853.html//www.ot7t.com.cn/xiaomage234/archive/2017/10/12/432853.html#Feedback0//www.ot7t.com.cn/xiaomage234/comments/commentRss/432853.html//www.ot7t.com.cn/xiaomage234/services/trackbacks/432853.html

最近做了个Web项目, 架构上使用了 Nginx +tomcat 集群, 且全站HTTPS,用nginx 做负载,nginx和tomcat 使用内网http通信,遇到http css,js静态资源被浏览器拦截问题,网上搜索到的很多文章在描?Nginx + Tomcat 启用 HTTPS 支持的时候,都必须在 Nginx ?Tomcat 两边同时配置 SSL 支持,今天做个总结?/p>

遇到问题

  1. nginx强制使用https访问(http跳转到https)
  2. http的js,css 等静态资源被浏览器拦截(http不被信任?/li>

最后的解决方案

首先解决第一个问?/strong>全站https 
参?/a> 
三种方式,跟大家共享一?/p>

nginx的rewrite方法

server {   listen  192.168.1.111:80;   server_name test.com;   rewrite ^(.*)$  https://$host$1 permanent; }   

nginx?97状态码,我选择了这种方?/strong>

server {       listen       192.168.1.11:443;  #ssl端口       listen       192.168.1.11:80;   #用户习惯用http访问,加?0,后面通过497状态码让它自动跳到443端口       server_name  test.com;       #为一个server{......}开启ssl支持       ssl                  on;       #指定PEM格式的证书文?       ssl_certificate      /etc/nginx/test.pem;        #指定PEM格式的私钥文?      ssl_certificate_key  /etc/nginx/test.key;        #让http请求重定向到https请求        error_page 497  https://$host$uri?$args;   }   

index.html刷新网页

<html>   <meta http-equiv="refresh" content="0;url=https://test.com/">   </html>  

当http访问到index.html时候自动跳转到https


接下来解?strong style="box-sizing: border-box;">第二个问?/strong> 
如果tomcat 和nginx 双方没有配置X-Forwarded-Proto tomcat就不能正确区分实际用户是http 还是https,导致tomcat 里配置的静态资源被认为是http而被浏览器拦截,request.getScheme()总是 http,而不是实际的http或https

分别配置一?Nginx ?Tomcat ,果然好了?nbsp;
配置 Nginx 的转发选项?/strong>

 proxy_set_header       Host $host;       proxy_set_header  X-Real-IP  $remote_addr;       proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;       proxy_set_header X-Forwarded-Proto  $scheme;  
  • 1
  • 2
  • 3
  • 4

配置Tomcat server.xml ?Engine 模块下配置一?Valve?/strong>

<Valve className="org.apache.catalina.valves.RemoteIpValve"   remoteIpHeader="X-Forwarded-For"   protocolHeader="X-Forwarded-Proto"   protocolHeaderHttpsValue="https"/>  
  • 1
  • 2
  • 3
  • 4

?0端口配置 
Nginx增加以下配置 
proxy_set_header Host $host:$server_port; ?0端口 ,用80端口?不需?server_port 
proxy_set_header X-Real-IP $remote_addr; 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
proxy_set_header X-Forwarded-Proto $scheme; 

Tomcat server.xml配置 
<Engine name="Catalina" defaultHost="localhost"> 
<Valve className="org.apache.catalina.valves.RemoteIpValve" 
remoteIpHeader="X-Forwarded-For" 
protocolHeader="X-Forwarded-Proto" 
protocolHeaderHttpsValue="https" httpsServerPort="7001"/> ?0端口时,必须增加httpsServerPort配置,不然request.getServerPort()方法返回 443. 
</Engine>

关于 RemoteIpValve,可以阅读?doc

//tomcat.apache.org/tomcat-6.0-doc/api/org/apache/catalina/valves/RemoteIpValve.html



]]>
Tomcat7调试运行环境搭建与源代码分析入门 - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/xiaomage234/archive/2015/12/24/428814.html小马?/dc:creator>小马?/author>Thu, 24 Dec 2015 07:54:00 GMT//www.ot7t.com.cn/xiaomage234/archive/2015/12/24/428814.html//www.ot7t.com.cn/xiaomage234/comments/428814.html//www.ot7t.com.cn/xiaomage234/archive/2015/12/24/428814.html#Feedback0//www.ot7t.com.cn/xiaomage234/comments/commentRss/428814.html//www.ot7t.com.cn/xiaomage234/services/trackbacks/428814.html原文  //zhh2009.iteye.com/blog/1557891


1. 需要准备好下面这些工具

 

JDK 1.6+

Maven 2?

TortoiseSVN 1.7+ (?.7开?.svn"目录集中放在一处了,不再每个目录下都放一?

Eclipse 3.5+

 

?个工具不在这里描述怎么配置了,如果你是有两三年开发经验的Java开发人员,正常来讲都一直在用了?/p>

另外,分析tomcat源代码不需要对?个工具做什么特殊配置?/p>

 

 

 

2. 下载Tomcat的源代码

 

Apache旗下的开源项目基本上都放在这: //svn.apache.org/repos/asf

里面包含了tomcat、struts、hadoop、hbase等流行的开源项目的源代码,

可以直接用浏览器打开这个URL,或者用TortoiseSVN的Repository Browser打开它?/p>

tomcat的svn? //svn.apache.org/repos/asf/tomcat , 如下图所?


 

目前tomcat?个大分支: 

5.5 : //svn.apache.org/repos/asf/tomcat/tc5.5.x

6.0 : //svn.apache.org/repos/asf/tomcat/tc6.0.x

7.0 : //svn.apache.org/repos/asf/tomcat/tc7.0.x

8.0 : //svn.apache.org/repos/asf/tomcat/trunk

 

5.5分支会在今年9?0号后停止维护,所以除非有历史遗留系统,不推荐再去读它的代码,

 

6.0分支是比较成熟的,在生产环境用得比较多,

目前官方对这个分支进入维护、bugfix阶段,很少有新功能添加进来了?/p>

我个人也不推荐读它的代码,代码相?.0来讲比较脏乱?/p>

 

7.0分支完整实现了servlet 3.0规范,已陆续发布?7个小版本,己经稳定了,可用于生产环境?/span>

代码?.5?.0分支干净整洁得多,这也是我强烈向你推荐的版本?/span>

 

8.0分支主要关注web socket和spdy,正处于活跃开发阶段,代码变动比较频繁,保持关注即可?/p>

 

 

所以这篇文章讲的是7.0分支,研究tomcat推荐直接提取svn的源代码:

 

用TortoiseSVN checkout这个svn的代?//svn.apache.org/repos/asf/tomcat/tc7.0.x/trunk

放到D:\Tomcat7\trunk (你可以换别的目录)

 

然后再从这下载一个二进制分发?Binary Distributions)

//labs.mop.com/apache-mirror/tomcat/tomcat-7/v7.0.27/bin/apache-tomcat-7.0.27.zip

 

解压后放到D:\Tomcat7,顺便把"apache-tomcat-7.0.27"重命名成launch吧,

用这个二进制分发包而不是从源代码构建只是为了节省时间,

直接用它conf目录里面的配置文件和webapps下的例子?/p>

 

 

3. 把它变成maven工程

 

主要是添加几个依?ecj、ant、jaxrpc?,否则的话导入eclipse后会有编译错误,

另外,因为tomcat不是标准的maven工程项目,比如没有src\main\java这样的目录,

所以要调整一下sourceDirectory和testSourceDirectory,下面是一个完整的pom文件?/p>

直接放到D:\Tomcat7目录即可(pom.xml与之前的launch、trunk目录并列)

 

(? pom.xml文件在附件中)

 

<project xmlns="//maven.apache.org/POM/4.0.0" xmlns:xsi="//www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="//maven.apache.org/POM/4.0.0 //maven.apache.org/maven-v4_0_0.xsd">  <modelVersion>4.0.0</modelVersion>   <groupId>org.apache.tomcat</groupId>  <artifactId>Tomcat7.0</artifactId>  <name>Tomcat7.0</name>  <version>7.0</version>   <build>   <finalName>Tomcat7.0</finalName>   <sourceDirectory>trunk/java</sourceDirectory>   <testSourceDirectory>trunk/test</testSourceDirectory>   <resources>    <resource>     <directory>trunk/java</directory>    </resource>   </resources>   <testResources>    <testResource>     <directory>trunk/test</directory>    </testResource>   </testResources>   <plugins>    <plugin>     <groupId>org.apache.maven.plugins</groupId>     <artifactId>maven-compiler-plugin</artifactId>     <version>2.3</version>     <configuration>      <source>1.6</source>      <target>1.6</target>     </configuration>    </plugin>   </plugins>  </build>   <dependencies>   <dependency>    <groupId>junit</groupId>    <artifactId>junit</artifactId>    <version>4.4</version>    <scope>test</scope>   </dependency>   <dependency>    <groupId>org.eclipse.jdt.core.compiler</groupId>    <artifactId>ecj</artifactId>    <version>3.7.2</version>   </dependency>   <dependency>    <groupId>ant</groupId>    <artifactId>ant</artifactId>    <version>1.7.0</version>   </dependency>   <dependency>    <groupId>wsdl4j</groupId>    <artifactId>wsdl4j</artifactId>    <version>1.6.2</version>   </dependency>   <dependency>    <groupId>javax.xml</groupId>    <artifactId>jaxrpc</artifactId>    <version>1.1</version>   </dependency>  </dependencies>  </project>
 

 

4. 导入Eclipse

 

 

在命令行窗口中进入D:\Tomcat7目录,执?mvn eclipse:eclipse 就可以转成eclipse工程项目了,

然后打开eclipse,点"File->Import->General->Existing Projects into Workspace"?/p>

最后打开D:\Tomcat7就能看到Tomcat7.0这个项目了?/p>

 

(如果eclipse装了m2e插件不用执行mvn eclipse:eclipse的,可以直接导入maven工程)

 

 

5. 在Eclipse中让Tomcat跑起?/h3>

 

在Eclipse中打开org.apache.catalina.startup.Bootstrap类,

在编辑区右击,点"Run As->Run configurations",然后双?Java Aplication"就会出来一个新?Bootstrap"?/p>

选中它,在右边点?Arguments"那一栏,把下面的内容copy?VM arguments"?

-Dcatalina.home=launch -Dcatalina.base=launch -Djava.endorsed.dirs=launch/endorsed -Djava.io.tmpdir=launch/temp -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=launch/conf/logging.properties

 

如下?


 

然后点run按钮,就可以启动tomcat了,启动成功会在Eclipse的console中显?

 

 

2012-6-10 14:25:31 org.apache.catalina.startup.Catalina start 信息: Server startup in 359 ms
 

 

 

除上面这种方式外,这里还有一个Eclipse的launch脚本 (start-tomcat7.launch  (? 在附件中) ) ?/p>

 

 

<?xml version="1.0" encoding="UTF-8" standalone="no"?> <launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication"> <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> <listEntry value="/Tomcat7.0/trunk/java/org/apache/catalina/startup/Bootstrap.java"/> </listAttribute> <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> <listEntry value="1"/> </listAttribute> <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.apache.catalina.startup.Bootstrap"/> <stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="start"/> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="Tomcat7.0"/> <stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dcatalina.home=launch -Dcatalina.base=launch -Djava.endorsed.dirs=launch/endorsed -Djava.io.tmpdir=launch/temp -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=launch/conf/logging.properties"/> </launchConfiguration>
 

可以放到D:\Tomcat7目录,然后flush一下Eclipse,在Eclipse中右击这个文件,点Run As启动Tomcat,点Debug As可以调试Tomcat?/p>

 

下图是Tomcat在Eclipse中的项目布局:


 

最后,打开你的浏览器,输入 //127.0.0.1:8080/examples/ 看看例子吧?/p>

 

 

6. 简单的源代码阅读指?

 

 

包名                    用?================================================= javax                 servlet/jsp/el相关的api org.apache.catalina   tomcat自身架构 org.apache.coyote     http、ajp协议实现相关的类 org.apache.el         实现el规范 org.apache.jasper     实现jsp规范、编译jsp文件 org.apache.juli       tomcat的日志系?org.apache.naming     jndi实现 org.apache.tomcat     tomcat的工具包、net、digester xml解析?/pre> 

 

 

阅读顺序:

 

可以从org.apache.catalina.startup.Bootstrap这个类开始看起,

然后到org.apache.catalina.startup.Catalina, 

 

在Catalina类中会触发conf/server.xml文件的解析,

这时要看org.apache.tomcat.util.digester中的类,

解析的过程中会用到org.apache.catalina.startup包中的很多RuleSet类,

 

server.xml文件解析完后,会生成org.apache.catalina.core包中的各种StandardXXX类的实例?/p>

比如StandardServer、StandardService、StandardEngine等等?/p>

这些Standard组件都是有生命周期的,接着会调用他们的init、start等方法,

会触发下面这些组件进入init、start状?/p>

org.apache.catalina.connector.Connector

org.apache.coyote.http11.Http11Protocol

org.apache.tomcat.util.net.JIoEndpoint

 

在JIoEndpoint(或NioEndpoint、AprEndpoint)中会监听8080这样的端口,

有请求进来了,就进行相关的io操作,接着转到org.apache.coyote包中的相应类进行协议解析?/p>

生成org.apache.catalina.connector.Request和org.apache.catalina.connector.Response实例?/p>

然后转到各种Valve、应用Filter,最后到达应用的Servlet/JSP?/p>

 

下图描述了Tomcat7的核心架?


 



]]>zookeeper 大量连接断开重连原因排查[转] - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/xiaomage234/archive/2015/09/10/427237.html小马?/dc:creator>小马?/author>Thu, 10 Sep 2015 02:41:00 GMT//www.ot7t.com.cn/xiaomage234/archive/2015/09/10/427237.html//www.ot7t.com.cn/xiaomage234/comments/427237.html//www.ot7t.com.cn/xiaomage234/archive/2015/09/10/427237.html#Feedback0//www.ot7t.com.cn/xiaomage234/comments/commentRss/427237.html//www.ot7t.com.cn/xiaomage234/services/trackbacks/427237.html

问题现象

最后发现线上的zookeeper的日志zookeeper.out 文件居然?G,后来设置下日志为滚动输出,参考:

//blog.csdn.net/hengyunabc/article/details/19006911

但是改了之后,发现一天的日志量就?00多M,滚动日志一天就被冲掉了,这个不科学?/p>

再仔细查看下日志里的内容,发现有很多连接建立好,马上又断开?/p>

  1. 2014-11-24 15:38:33,348 [myid:3] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1001] - Closed socket connection for client /10.0.0.3:47772 (no session established for client)  
  2. 2014-11-24 15:38:33,682 [myid:3] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@197] - Accepted socket connection from /10.0.0.3:32119  
  3. 2014-11-24 15:38:33,682 [myid:3] - WARN  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@349] - caught end of stream exception  
  4. EndOfStreamException: Unable to read additional data from client sessionid 0x0, likely client has closed socket  
  5.         at org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:220)  
  6.         at org.apache.zookeeper.server.NIOServerCnxnFactory.run(NIOServerCnxnFactory.java:208)  
  7.         at java.lang.Thread.run(Thread.java:745)  
  8. 2014-11-24 15:38:33,682 [myid:3] - INFO  [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1001] - Closed socket connection for client /10.0.0.0:32119 (no session established for client)  
从日志输出的时间来看,秒连秒断,非常诡异?/span>

排查问题

用netstat查看网络连接状?/h3>

到client的服务器上查看连接的状态:

  1. netstat -antp | grep 2181  

发现有很多TIME_WAIT状态的连接?/span>

  1. tcp        0      0 10.0.0.3:44269         10.0.1.77:2181         TIME_WAIT   -                     
  2. tcp        0      0 10.0.0.3:43646         10.0.1.77:2181         TIME_WAIT   -                     
  3. tcp        0      0 10.0.0.3:44184         10.0.1.77:2181         TIME_WAIT   -                     
  4. tcp        0      0 10.0.0.3:44026         10.0.1.77:2181         TIME_WAIT   -                     
  5. tcp        0      0 10.0.0.3:43766         10.0.1.77:2181         TIME_WAIT   -    

但是TIME_WAIT状态的连接是看不到进程号的。搜索研究了下netstat的参数,发现没有办法输出TIME_WAIT状态的连接的pid,只好尝试其它的办法?/span>

再用 jstack -l pid 来查看进程的线程栈,也没有发现什么异常的东东。查看到有几个zookeeper连接的线程,但也是正常状态?br />

再检查了机器的IO,CPU,内存,也没有异常的情况?/p>

没找到什么有用的信息,只好再研究下netstat的参数:
发现?netstat -ae 输出了一些信息:

  1. tcp        0      0 10.0.0.3:41772     10.0.1.77:eforward     TIME_WAIT   root       0            
  2. tcp        0      0 10.0.0.3:41412     10.0.1.77:eforward     TIME_WAIT   root       0            
  3. tcp        0      0 10.0.0.3:24226     10.0.1.77:2181         TIME_WAIT   root       0            
  4. tcp        0      0 10.0.0.3:24623     10.0.1.77:2181         TIME_WAIT   root       0  

发现user是root。于是以为是非Java应用,在不断地连接zookeeper。于是停止java程序,发现没有TIME_WAIT连接了?/span>
但是确认是Java应用的问题,于是再重启Java应用,但没有再发现TIME_WAIT情况。很诡异?/span>

问题不能重现了,相当的蛋疼。忽然想到线上的应用也许也有这个问题,于是到线下zookeeper服务器上查看了下,果然发现有同样的问题?/p>

用tcpdump抓包和wireshark分析

先用tcpdump来查看下具体的网络连接,发现的确是连接连上再断开。于是先保存成cap文件,再用wireshark来分析:

  1. tcpdump -vv host 192.168.66.27 and port 2181 -w 2181.cap  
但是也没有发现什么有用信息,的确是TCP连接连上,再FIN,ACK连接断开?/span>

查看应用日志,发现Tomcat webcontext没有正常启动

没办法了,有两种考虑,一个是用strace,二是用btrace。但是btrace好久没用过了,不太想再去看例子文??/p>

还好,去下btrace之后,先去看了下应用的日志,发现应用报了一些ClassLoader的错误:

  1. Nov 24, 2014 7:32:43 PM org.apache.catalina.loader.WebappClassLoader loadClass  
  2. INFO: Illegal access: this web application instance has been stopped already.  Could not load org.apache.zookeeper.ClientCnxnSocketNIO.  The eventual following stack trace is caused by an err  
  3. or thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.  
  4. java.lang.IllegalStateException  
  5.         at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1564)  
  6.         at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)  
  7.         at ch.qos.logback.classic.spi.PackagingDataCalculator.loadClass(PackagingDataCalculator.java:198)  
  8.         at ch.qos.logback.classic.spi.PackagingDataCalculator.bestEffortLoadClass(PackagingDataCalculator.java:226)  
  9.         at ch.qos.logback.classic.spi.PackagingDataCalculator.computeBySTEP(PackagingDataCalculator.java:132)  
  10.         at ch.qos.logback.classic.spi.PackagingDataCalculator.populateUncommonFrames(PackagingDataCalculator.java:107)  
  11.         at ch.qos.logback.classic.spi.PackagingDataCalculator.populateFrames(PackagingDataCalculator.java:99)  

因为有经验了,马上知道这个Tomcat因为其它原因webcontext实始化失败退出,然后后面的一些线程继续跑时,会抛出ClassLoader,或者Class not found的异常?/span>

于是猜想到原因了?/p>

Tomcat webcontext初始化失败,zookeeper的重连线程自动不断重连?/strong>

但是为什么重启Tomcat之后,没有重现TIME_WAIT的情况?

再折腾了下,发现只有当zookeeper重启后,应用才会出现大量的TIME_WAIT连接。报的是下面这个异常?/p>

  1. 2014-11-24 19:42:44,399 [Thread-3-SendThread(192.168.90.147:4181)] WARN  org.apache.zookeeper.ClientCnxn - Session 0x149c21809731325 for server 192.168.90.147/192.168.90.147:4181, unexpected error, closing socket connection and attempting reconnect  
  2. java.lang.NoClassDefFoundError: org/apache/zookeeper/proto/SetWatches  
  3.         at org.apache.zookeeper.ClientCnxn$SendThread.primeConnection(ClientCnxn.java:867) ~[zookeeper-3.4.5.jar:3.4.5-1392090]  
  4.         at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:352) ~[zookeeper-3.4.5.jar:3.4.5-1392090]  

这个异常的原因,是某些zookeeper的类没有加载到?/span>

最终原因分?/h2>

梳理下整个流程:

  1. Tomcat启动,初始化webcontext?/li>
  2. 初始化spring, spring初始某些些bean,这些bean包括了zookeeper的连接相关的bean?/li>
  3. 这时zkClient(独立线程)已经连接上服务器了,但是classloader没有加载到org/apache/zookeeper/proto/SetWatches类;
  4. spring初始化失败,导致Tomcat webcontext初始化也失败,应用在挂起状态,但zkClient线程还是正常的;
  5. zookeeper服务器重启,zkClient开始重连,连接上zookeeper服务器;
  6. zkClient触发watch的一些代码,ClassLoader尝试加载org/apache/zookeeper/proto/SetWatches类,但是发现找不到类,于是抛出异常;
  7. zkClient捕获到异常,认为重连失败,close掉connection,休眠几秒之后,再次重连?/li>

于是出现了zkClient反复重试连接zookeeper服务器,而且都是秒连秒断的情况?/p>


总结?/h2>

这次排查花了不少时间,有个原因是开始没有去查看应用的日志,以为应用的是正常的,而且zookeeper.out的输出日志很多,也有一段时间了?/p>

还有线上的应用比较坑爹,活动已经过期很久了,但是程序还是线上跑,也没有人管是否出问题了?/p>

所以,主要精力放在各种网络连接状态的获取上。对去查看应用日志比较排斥?/p>

还有一个原因是,问题比较诡异,有点难重现,当发现可以重现时,基本已经发现问题所在了?/p>

排查问题还是要耐心收集信息,再分析判断?/p>

]]>提升tomcat服务器性能的七条经?/title><link>//www.ot7t.com.cn/xiaomage234/archive/2014/07/29/416280.html</link><dc:creator>小马?/dc:creator><author>小马?/author><pubDate>Tue, 29 Jul 2014 02:31:00 GMT</pubDate><guid>//www.ot7t.com.cn/xiaomage234/archive/2014/07/29/416280.html</guid><wfw:comment>//www.ot7t.com.cn/xiaomage234/comments/416280.html</wfw:comment><comments>//www.ot7t.com.cn/xiaomage234/archive/2014/07/29/416280.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>//www.ot7t.com.cn/xiaomage234/comments/commentRss/416280.html</wfw:commentRss><trackback:ping>//www.ot7t.com.cn/xiaomage234/services/trackbacks/416280.html</trackback:ping><description><![CDATA[from://passover.blog.51cto.com/2431658/732629<br /><br /><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">在线上环境中我们是采用了tomcat作为Web服务器,它的处理性能直接关系到用户体验,在平时的工作和学习中,归纳出以下七种调优经验?/p><h1>快乐12:<span style="padding: 0px; margin: 0px; font-size: 22px;">1. 服务器资?/span></h1><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">    服务器所能提供CPU、内存、硬盘的性能对处理能力有决定性影响?br style="padding: 0px; margin: 0px;" />    (1) 对于高并发情况下会有大量的运算,那么CPU的速度会直接影响到处理速度?br style="padding: 0px; margin: 0px;" />    (2) 内存在大量数据处理的情况下,将会有较大的内存容量需求,可以?Xmx -Xms -XX:MaxPermSize等参数对内存不同功能块进行划分。我们之前就遇到过内存分配不足,导致虚拟机一直处于full GC,从而导致处理能力严重下降?br style="padding: 0px; margin: 0px;" />    (3) 硬盘主要问题就是读写性能,当大量文件进行读写时,磁盘极容易成为性能瓶颈。最好的办法还是利用下面提到的缓存?/p><h1 class="yibqv"><span style="padding: 0px; margin: 0px; font-size: 22px;">2. 利用缓存和压?/span></h1><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">    对于静态页面最好是能够缓存起来,这样就不必每次从磁盘上读。这里我们采用了Nginx作为缓存服务器,将图片、css、js文件都进行了缓存,有效的减少了后端tomcat的访问?/p><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">    另外,为了能加快网络传输速度,开启gzip压缩也是必不可少的。但考虑到tomcat已经需要处理很多东西了,所以把这个压缩的工作就交给前端的Nginx来完成。可以参考之前写的?a target="_blank" style="padding: 0px; margin: 0px; color: #4b0002; text-decoration: none;">利用nginx加速web访问</a>》?/p><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">    除了文本可以用gzip压缩,其实很多图片也可以用图像处理工具预先进行压缩,找到一个平衡点可以让画质损失很小而文件可以减小很多。曾经我就见过一个图片从300多kb压缩到几十kb,自己几乎看不出来区别?/p><h1 class="yibqv"><span style="padding: 0px; margin: 0px; font-size: 22px;">3. 采用集群</span></h1><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">    单个服务器性能总是有限的,最好的办法自然是实现横向扩展,那么组建tomcat集群是有效提升性能的手段。我们还是采用了Nginx来作为请求分流的服务器,后端多个tomcat共享session来协同工作。可以参考之前写的?a target="_blank" style="padding: 0px; margin: 0px; color: #4b0002; text-decoration: none;">利用nginx+tomcat+memcached组建web服务器负载均?/a>》?/p><h1 class="yibqv"><span style="padding: 0px; margin: 0px; font-size: 22px;">4. 优化tomcat参数</span></h1><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">    这里以tomcat7的参数配置为例,需要修改conf/server.xml文件,主要是优化连接配置,关闭客户端dns查询?/p><pre style="padding: 0px; margin-top: 0px; font-family: 'Courier New', monospace; font-size: 12px; overflow: auto; width: 712.796875px; color: #555555; background: #f7f7f7;"><ol style="padding: 5px 0px; margin: 0px; color: #5c5c5c; list-style-position: initial; list-style-image: initial; border-left-width: 3px; border-style: none none none solid; border-left-color: #146b00; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><li style="padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: inherit; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;"><span style="padding: 0px; margin: 0px; border: none; color: #006699; font-weight: bold; background-color: inherit;"><</span><span style="padding: 0px; margin: 0px; border: none; color: #006699; font-weight: bold; background-color: inherit;">Connector</span> <span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">port</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;">=</span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">"8080"</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;">   </span></span></li><li style="margin-left: 20px; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none; padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;">           <span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">protocol</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;">=</span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">"org.apache.coyote.http11.Http11NioProtocol"</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;">  </span></span></li><li style="padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: inherit; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;">           <span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">connectionTimeout</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;">=</span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">"20000"</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;">  </span></span></li><li style="margin-left: 20px; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none; padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;">           <span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">redirectPort</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;">=</span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">"8443"</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;">   </span></span></li><li style="padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: inherit; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;">           <span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">maxThreads</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;">=</span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">"500"</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;">   </span></span></li><li style="margin-left: 20px; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none; padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;">           <span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">minSpareThreads</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;">=</span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">"20"</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;">  </span></span></li><li style="padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: inherit; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;">           <span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">acceptCount</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;">=</span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">"100"</span> </span></li><li style="margin-left: 20px; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none; padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;">           <span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">disableUploadTimeout</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;">=</span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">"true"</span> </span></li><li style="padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: inherit; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;">           <span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">enableLookups</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;">=</span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">"false"</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;">   </span></span></li><li style="margin-left: 20px; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none; padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;">           <span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">URIEncoding</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;">=</span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">"UTF-8"</span> <span style="padding: 0px; margin: 0px; border: none; color: #006699; font-weight: bold; background-color: inherit;">/></span> </span></li></ol></pre><h1 class="yibqv"><span style="padding: 0px; margin: 0px; font-size: 22px;">5. 改用APR?/span></h1><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">    tomcat默认采用的BIO模型,在几百并发下性能会有很严重的下降。tomcat自带还有NIO的模型,另外也可以调用APR的库来实现操作系统级别控制?/p><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">    NIO模型是内置的,调用很方便,只需要将上面配置文件中protocol修改?span style="padding: 0px; margin: 0px; font-family: 宋体;"><span style="padding: 0px; margin: 0px; font-size: 16px;"><span style="padding: 0px; margin: 0px; line-height: 18px;">org.apache.coyote.http11.Http11NioProtocol,重启即可生效。上面配置我已经改过了,默认的是HTTP/1.1?/span></span></span></p><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">    APR则需要安装第三方库,在高并发下会让性能有明显提升。具体安装办法可以参?a style="padding: 0px; margin: 0px; color: #4b0002; text-decoration: none;">//www.cnblogs.com/huangjingzhou/articles/2097241.html</a>。安装完成后<span style="padding: 0px; margin: 0px; font-size: 16px; line-height: 18px; font-family: 宋体;">重启即可生效。如使用默认protocal就是apr,但最好把将protocol修改?span style="padding: 0px; margin: 0px; font-size: 14px; line-height: 25px; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #efefef;">org.apache.coyote.http11.Http11AprProtocol,会更加明确</span></span><span style="padding: 0px; margin: 0px; line-height: 25px; font-family: Helvetica, Tahoma, Arial, sans-serif; background-color: #efefef;">?/span></p><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">    在官方找到一个表格详细说明了这三种方式的区别?/p><pre style="padding: 0px; margin-top: 0px; font-family: 'Courier New', monospace; font-size: 12px; overflow: auto; width: 712.796875px; color: #555555; background: #f7f7f7;"><ol style="padding: 5px 0px; margin: 0px; color: #5c5c5c; list-style-position: initial; list-style-image: initial; border-left-width: 3px; border-style: none none none solid; border-left-color: #146b00; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><li style="padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: inherit; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;">                  Java Blocking Connector   Java Nio Blocking Connector   APR/native Connector </span></li><li style="margin-left: 20px; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none; padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;">                             BIO                         NIO                       APR </span></li><li style="padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: inherit; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;">Classname                AjpProtocol               AjpNioProtocol           AjpAprProtocol </span></li><li style="margin-left: 20px; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none; padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;">Tomcat Version           3.x onwards                 7.x onwards              5.5.x onwards </span></li><li style="padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: inherit; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;">Support Polling              NO                          YES                       YES </span></li><li style="margin-left: 20px; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none; padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;">Polling Size                 N/A                   maxConnections             maxConnections </span></li><li style="padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: inherit; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;">Read Request Headers      Blocking                  Sim Blocking                   Blocking </span></li><li style="margin-left: 20px; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none; padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;">Read Request Body         Blocking                  Sim Blocking                   Blocking </span></li><li style="padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: inherit; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;">Write Response            Blocking                  Sim Blocking                   Blocking </span></li><li style="margin-left: 20px; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none; padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;">Wait for next Request     Blocking                  Non Blocking               Non Blocking </span></li><li style="padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: inherit; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;">Max Connections        maxConnections              maxConnections             maxConnections </span></li></ol></pre><h1 class="yibqv"><span style="padding: 0px; margin: 0px; font-size: 22px;">6. 优化网络</span></h1><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">    Joel也明确提出了优化网卡驱动可以有效提升性能,这个对于集群环境工作的时候尤为重要。由于我们采用了linux服务器,所以优化内核参数也是一个非常重要的工作。给一个参考的优化参数?/p><pre style="padding: 0px; margin-top: 0px; font-family: 'Courier New', monospace; font-size: 12px; overflow: auto; width: 712.796875px; color: #555555; background: #f7f7f7;"><ol style="padding: 5px 0px; margin: 0px; color: #5c5c5c; list-style-position: initial; list-style-image: initial; border-left-width: 3px; border-style: none none none solid; border-left-color: #146b00; background-image: initial; background-attachment: initial; background-size: initial; background-origin: initial; background-clip: initial; background-position: initial; background-repeat: initial;"><li style="padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: inherit; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;">1. 修改/etc/sysctl.cnf文件,在最后追加如下内容: </span></li><li style="margin-left: 20px; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none; padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important;"> </li><li style="padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: inherit; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;"><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">net.core.netdev_max_backlog</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;"> = </span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">32768</span> </span></li><li style="margin-left: 20px; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none; padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;"><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">net.core.somaxconn</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;"> = </span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">32768</span> </span></li><li style="padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: inherit; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;"><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">net.core.wmem_default</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;"> = </span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">8388608</span> </span></li><li style="margin-left: 20px; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none; padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;"><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">net.core.rmem_default</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;"> = </span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">8388608</span> </span></li><li style="padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: inherit; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;"><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">net.core.rmem_max</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;"> = </span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">16777216</span> </span></li><li style="margin-left: 20px; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none; padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;"><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">net.core.wmem_max</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;"> = </span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">16777216</span> </span></li><li style="padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: inherit; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;"><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">net.ipv4.ip_local_port_range</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;"> = </span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">1024</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;"> 65000 </span></span></li><li style="margin-left: 20px; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none; padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;"><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">net.ipv4.route.gc_timeout</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;"> = </span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">100</span> </span></li><li style="padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: inherit; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;"><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">net.ipv4.tcp_fin_timeout</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;"> = </span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">30</span> </span></li><li style="margin-left: 20px; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none; padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;"><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">net.ipv4.tcp_keepalive_time</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;"> = </span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">1200</span> </span></li><li style="padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: inherit; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;"><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">net.ipv4.tcp_timestamps</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;"> = </span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">0</span> </span></li><li style="margin-left: 20px; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none; padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;"><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">net.ipv4.tcp_synack_retries</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;"> = </span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">2</span> </span></li><li style="padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: inherit; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;"><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">net.ipv4.tcp_syn_retries</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;"> = </span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">2</span> </span></li><li style="margin-left: 20px; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none; padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;"><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">net.ipv4.tcp_tw_recycle</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;"> = </span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">1</span> </span></li><li style="padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: inherit; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;"><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">net.ipv4.tcp_tw_reuse</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;"> = </span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">1</span> </span></li><li style="margin-left: 20px; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none; padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;"><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">net.ipv4.tcp_mem</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;"> = </span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">94500000</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;"> 915000000 927000000 </span></span></li><li style="padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: inherit; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;"><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">net.ipv4.tcp_max_orphans</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;"> = </span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">3276800</span> </span></li><li style="margin-left: 20px; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none; padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;"><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit;">net.ipv4.tcp_max_syn_backlog</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit;"> = </span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit;">65536</span> </span></li><li style="padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important; margin-left: 20px; color: inherit; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none;"> </li><li style="margin-left: 20px; line-height: 1.3em; list-style: decimal-leading-zero outside; border: none; padding: 0px 3px 0px 10px !important; margin-top: 0px !important; margin-right: 0px !important; margin-bottom: 0px !important;"><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit;">2. 保存退出,执行sysctl -p生效 </span></li></ol></pre><h1 class="yibqv"><span style="padding: 0px; margin: 0px; font-size: 22px;">7. 让测试说?/span></h1><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">    优化系统最忌讳的就是只调优不测试,有时不适当的优化反而会让性能更低。以上所有的优化方法都要在本地进行性能测试过后再不断调整参数,这样最终才能达到最佳的优化效果?/p><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;"> </p><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">补充Bio、Nio、Apr模式的测试结果:</p><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">    对于这几种模式,我用ab命令模拟1000并发测试10000词,测试结果比较意外,为了确认结果,我每种方式反复测试了10多次,并且在两个服务器上都测试了一遍。结果发现Bio和Nio性能差别非常微弱,难怪默认居然还是Bio。但是采用apr,连接建立的速度会有50%?00%的提升。直接调用操作系统层果然神速啊,这里强烈推荐apr方式?/p><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;"> </p><p style="padding: 0px; margin: 0px; clear: both; height: auto; overflow: hidden; color: #555555; font-family: 宋体, 'Arial Narrow', arial, serif; line-height: 28px; background-color: #ffffff;">参考资料:<br style="padding: 0px; margin: 0px;" /><a style="padding: 0px; margin: 0px; color: #4b0002; text-decoration: none;">//16.199.geisvps.com/bbs/2836/24238.html</a></p><img src ="//www.ot7t.com.cn/xiaomage234/aggbug/416280.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="//www.ot7t.com.cn/xiaomage234/" target="_blank">小马?/a> 2014-07-29 10:31 <a href="//www.ot7t.com.cn/xiaomage234/archive/2014/07/29/416280.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Tomcat7调试运行环境搭建与源代码分析入门 - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/xiaomage234/archive/2013/08/21/403124.html小马?/dc:creator>小马?/author>Wed, 21 Aug 2013 04:30:00 GMT//www.ot7t.com.cn/xiaomage234/archive/2013/08/21/403124.html//www.ot7t.com.cn/xiaomage234/comments/403124.html//www.ot7t.com.cn/xiaomage234/archive/2013/08/21/403124.html#Feedback0//www.ot7t.com.cn/xiaomage234/comments/commentRss/403124.html//www.ot7t.com.cn/xiaomage234/services/trackbacks/403124.html阅读全文

]]>
下载Tomcat源码,并作为工程导入到Eclipse? - 四川福利彩票快乐12快乐12开奖直播快乐12开奖辽宁福彩快乐12快乐彩12选5走势图//www.ot7t.com.cn/xiaomage234/archive/2013/08/21/403118.html小马?/dc:creator>小马?/author>Wed, 21 Aug 2013 02:41:00 GMT//www.ot7t.com.cn/xiaomage234/archive/2013/08/21/403118.html//www.ot7t.com.cn/xiaomage234/comments/403118.html//www.ot7t.com.cn/xiaomage234/archive/2013/08/21/403118.html#Feedback0//www.ot7t.com.cn/xiaomage234/comments/commentRss/403118.html//www.ot7t.com.cn/xiaomage234/services/trackbacks/403118.html导入Tomcat的源代码,其实很简单,可是如果没有找到正确的方法,你会浪费大量的时间,我就是浪费了好多时间在配置编译环境上。最正确的办法是到Tomcat的官方网址去找到答案?/div>
可以参考下边的连接,这个是关于Tomcat7的?/div>
//tomcat.apache.org/tomcat-7.0-doc/building.html
1. 设置环境
   1.1 JDK1.6 or above           JAVA_HOME
   1.2 Ant 1.8.1 or later        ANT_HOME
 
2. Check out the latest tomcat source code
svn --force export //svn.apache.org/repos/asf/tomcat/tc7.0.x/tags/TOMCAT_7_0_11/ D:\Tomcat7\
上边的命令SVN会把最新的Tomcat7011的源码下载到你的硬盘D:\Tomcat7\ ?br />SVN 下载地址 //subversion.tigris.org/servlets/ProjectDocumentList?folderID=91
 
3. 为Eclipse编译工程
   cd ${tomcat.source}
   ant ide-eclipse
  [注] a. ${tomcat.source} 是你下载的源码在机器上的路径
       b. ant ide-eclipse: 这个过程会比较慢,因为会下载一些依赖的第三方jar,这些jar都会放到你在
          build.properties 中设置的 ${base.path} 所指向的路?/div>
4. 设置Eclipse 环境 (Class-path Variables)
   设置TOMCAT_LIBS_BASE,ANT_HOME
   TOMCAT_LIBS_BASE 要指?nbsp;${base.path}
   ANT_HOME 指向安装ant的目录就好了
5. 导入工程
   File -> Import and choose Existing Projects into Workspace
6. 编译问题
   往往我们在这时会遇到一些编译错误,这是因为我们Eclipse中JRE环境设置的不正确,需要调?/div>
   6.1 Java Compiler, 需?6.0 (1.6) 以上
       Window -> Preferences -> Java -> Complier -> JDK Compliance -> 6.0 (1.6)
   6.2 Default JRE, 需?1.6 以上
       Window -> Preferences -> Java -> Installed JREs -> jdk1.6
       当然,这个也可以在工程中设定,如果你还有其他的工程必须用以前的jdk版本的话?/div>
   6.3 Eclipse 版本问题
       调整好Java Compiler ?JRE 后,一般可以编译通过了,但是我就遇到了Eclipse版本问题,总有一?nbsp;
       compiler ArrayIndexOutofBoundaryException 的错误,后来更新了一下Eclipse,就好了,我用?/div>
       Eclipse 版本?.2的。我又用了Eclipse Galileo试着打开工程,就没有类似的问题?/div>
7. 最周到的服?/div>
   到了这里,您的工程应该就编译成功了。该想想怎么run, debug TOMCAT了,怎么设置啊?哈,最周到的服?/div>
   来了,在 run(debug) ... -> Java Application 中,我们会看到已经有两个applications 了,分别叫做
   start-tomcat, stop-tomcat.


]]>