??xml version="1.0" encoding="utf-8" standalone="yes"?>久久综合网色—综合色88,日韩午夜av,亚洲黄色成人网http://www.aygfsteel.com/xiaomage234/category/53838.html生命本就是一ơ凄的漂流Q记忆中放不下的Q永q是孩提时代的那一份浪漫与U真Q?/description>zh-cnThu, 12 Oct 2017 15:00:50 GMTThu, 12 Oct 2017 15:00:50 GMT60转: Nginx + Tomcat + HTTPS 配置不需要在 Tomcat 上启?SSL 支持http://www.aygfsteel.com/xiaomage234/archive/2017/10/12/432853.html马?/dc:creator>马?/author>Thu, 12 Oct 2017 03:02:00 GMThttp://www.aygfsteel.com/xiaomage234/archive/2017/10/12/432853.htmlhttp://www.aygfsteel.com/xiaomage234/comments/432853.htmlhttp://www.aygfsteel.com/xiaomage234/archive/2017/10/12/432853.html#Feedback0http://www.aygfsteel.com/xiaomage234/comments/commentRss/432853.htmlhttp://www.aygfsteel.com/xiaomage234/services/trackbacks/432853.html

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

遇到问题

  1. nginx强制使用https讉K(http跌{到https)
  2. http的jsQcss {静态资源被览器拦截(http不被信QQ?/li>

最后的解决Ҏ

首先解决W一个问?/strong>全站https 
参?/a> 
三种方式Q跟大家׃n一?/p>

nginx的rewriteҎ

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

nginx?97状态码Q我选择了这U方?/strong>

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

index.htmlh|页

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

当http讉K到index.html时候自动蟩转到https


接下来解?strong style="box-sizing: border-box;">W二个问?/strong> 
如果tomcat 和nginx 双方没有配置X-Forwarded-Proto tomcat׃能正区分实际用hhttp q是httpsQ导致tomcat 里配|的静态资源被认ؓ是http而被览器拦截,request.getScheme()L httpQ而不是实际的http或https

分别配置一?Nginx ?Tomcat Q果然好了?nbsp;
配置 Nginx 的{发选项Q?/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 模块下配|一?ValveQ?/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端口 Q用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配置Q不然request.getServerPort()Ҏq回 443. 
</Engine>

关于 RemoteIpValve,可以阅读?doc

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



]]>
Tomcat7调试q行环境搭徏与源代码分析入门http://www.aygfsteel.com/xiaomage234/archive/2015/12/24/428814.html马?/dc:creator>马?/author>Thu, 24 Dec 2015 07:54:00 GMThttp://www.aygfsteel.com/xiaomage234/archive/2015/12/24/428814.htmlhttp://www.aygfsteel.com/xiaomage234/comments/428814.htmlhttp://www.aygfsteel.com/xiaomage234/archive/2015/12/24/428814.html#Feedback0http://www.aygfsteel.com/xiaomage234/comments/commentRss/428814.htmlhttp://www.aygfsteel.com/xiaomage234/services/trackbacks/428814.html原文  http://zhh2009.iteye.com/blog/1557891


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

 

JDK 1.6+

Maven 2?

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

Eclipse 3.5+

 

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

另外Q分析tomcat源代码不需要对q?个工具做什么特D配|?/p>

 

 

 

2. 下蝲Tomcat的源代码

 

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

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

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

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


 

目前tomcat?个大分支: 

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

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

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

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

 

5.5分支会在今年9?0号后停止l护Q所以除非有历史遗留pȝQ不推荐再去d的代码,

 

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

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

我个Z不推荐读它的代码Q代码相?.0来讲比较脏ؕ?/p>

 

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

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

 

8.0分支主要xweb socket和spdyQ正处于z跃开发阶D,代码变动比较频繁Q保持关注即可?/p>

 

 

所以这文章讲的是7.0分支Q研Itomcat推荐直接提取svn的源代码:

 

用TortoiseSVN checkoutq个svn的代?http://svn.apache.org/repos/asf/tomcat/tc7.0.x/trunk

攑ֈD:\Tomcat7\trunk (你可以换别的目录)

 

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

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

 

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

用这个二q制分发包而不是从源代码构建只是ؓ了节省时_

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

 

 

3. 把它变成maven工程

 

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

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

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

直接攑ֈD:\Tomcat7目录卛_(pom.xml与之前的launch、trunk目录q列)

 

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

 

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://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

 

 

在命令行H口中进入D:\Tomcat7目录Q执?mvn eclipse:eclipse 可以{成eclipse工程目了,

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

最后打开D:\Tomcat7p看到Tomcat7.0q个目了?/p>

 

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

 

 

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

 

在Eclipse中打开org.apache.catalina.startup.Bootstrapc,

在编辑区叛_Q点"Run As->Run configurations"Q然后双?Java Aplication"׃出来一个新?Bootstrap"Q?/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按钮Q就可以启动tomcat了,启动成功会在Eclipse的console中显C?

 

 

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

 

 

除上面这U方式外Q这里还有一个Eclipse的launch脚本 (start-tomcat7.launch  (? 在附件中) ) Q?/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目录Q然后flush一下EclipseQ在Eclipse中右击这个文Ӟ点Run As启动TomcatQ点Debug As可以调试Tomcat?/p>

 

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


 

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

 

 

6. 单的源代码阅L?

 

 

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

 

 

阅读序:

 

可以从org.apache.catalina.startup.Bootstrapq个cd始看P

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

 

在CatalinacM会触发conf/server.xml文g的解析,

q时要看org.apache.tomcat.util.digester中的c,

解析的过E中会用到org.apache.catalina.startup包中的很多RuleSetc,

 

server.xml文g解析完后Q会生成org.apache.catalina.core包中的各UStandardXXXcȝ实例Q?/p>

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

q些Standardlg都是有生命周期的Q接着会调用他们的init、start{方法,

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

org.apache.catalina.connector.Connector

org.apache.coyote.http11.Http11Protocol

org.apache.tomcat.util.net.JIoEndpoint

 

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

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

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

然后转到各种Valve、应用FilterQ最后到辑ֺ用的Servlet/JSP?/p>

 

下图描述了Tomcat7的核心架?


 



]]>zookeeper 大量q接断开重连原因排查[转]http://www.aygfsteel.com/xiaomage234/archive/2015/09/10/427237.html马?/dc:creator>马?/author>Thu, 10 Sep 2015 02:41:00 GMThttp://www.aygfsteel.com/xiaomage234/archive/2015/09/10/427237.htmlhttp://www.aygfsteel.com/xiaomage234/comments/427237.htmlhttp://www.aygfsteel.com/xiaomage234/archive/2015/09/10/427237.html#Feedback0http://www.aygfsteel.com/xiaomage234/comments/commentRss/427237.htmlhttp://www.aygfsteel.com/xiaomage234/services/trackbacks/427237.html

问题现象

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

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

但是改了之后Q发C天的日志量就?00多MQ滚动日志一天就被冲掉了Q这个不U学?/p>

再仔l查看下日志里的内容Q发现有很多q接建立好,马上又断开Q?/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)  
从日志输出的旉来看Q秒q秒断,非常诡异?/span>

排查问题

用netstat查看|络q接状?/h3>

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

  1. netstat -antp | grep 2181  

发现有很多TIME_WAIT状态的q接Q?/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状态的q接是看不到q程L。搜索研I了下netstat的参敎ͼ发现没有办法输出TIME_WAIT状态的q接的pidQ只好尝试其它的办法?/span>

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

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

没找C么有用的信息Q只好再研究下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应用Q在不断地连接zookeeper。于是停止javaE序Q发现没有TIME_WAITq接了?/span>
但是认是Java应用的问题,于是再重启Java应用Q但没有再发现TIME_WAIT情况。很诡异?/span>

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

用tcpdump抓包和wireshark分析

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

  1. tcpdump -vv host 192.168.66.27 and port 2181 -w 2181.cap  
但是也没有发C么有用信息,的确是TCPq接q上Q再FINQACKq接断开?/span>

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

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

q好Q去下btrace之后Q先ȝ了下应用的日志,发现应用报了一些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)  

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

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

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

但是Z么重启Tomcat之后Q没有重现TIME_WAIT的情况?

再折腾了下,发现只有当zookeeper重启后,应用才会出现大量的TIME_WAITq接。报的是下面q个异常Q?/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]  

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

最l原因分?/h2>

梳理下整个流E:

  1. Tomcat启动Q初始化webcontextQ?/li>
  2. 初始化spring, spring初始某些些beanQ这些bean包括了zookeeper的连接相关的beanQ?/li>
  3. q时zkClientQ独立线E)已经q接上服务器了,但是classloader没有加蝲到org/apache/zookeeper/proto/SetWatchesc;
  4. spring初始化失败,DTomcat webcontext初始化也p|Q应用在挂v状态,但zkClientU程q是正常的;
  5. zookeeper服务器重启,zkClient开始重q,q接上zookeeper服务器;
  6. zkClient触发watch的一些代码,ClassLoader试加蝲org/apache/zookeeper/proto/SetWatchesc,但是发现找不到类Q于是抛出异常;
  7. zkClient捕获到异常,认ؓ重连p|Qclose掉connectionQ休眠几U之后,再次重连Q?/li>

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


ȝQ?/h2>

q次排查׃不少旉Q有个原因是开始没有去查看应用的日志,以ؓ应用的是正常的,而且zookeeper.out的输出日志很多,也有一D|间了?/p>

q有U上的应用比较坑爹,zd已经q期很久了,但是E序q是U上跑,也没有h是否出问题了?/p>

所以,主要_֊攑֜各种|络q接状态的获取上。对L看应用日志比较排斥?/p>

q有一个原因是Q问题比较诡异,有点N玎ͼ当发现可以重现时Q基本已l发现问题所在了?/p>

排查问题q是要耐心攉信息Q再分析判断?/p>

]]>提升tomcat服务器性能的七条经?/title><link>http://www.aygfsteel.com/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>http://www.aygfsteel.com/xiaomage234/archive/2014/07/29/416280.html</guid><wfw:comment>http://www.aygfsteel.com/xiaomage234/comments/416280.html</wfw:comment><comments>http://www.aygfsteel.com/xiaomage234/archive/2014/07/29/416280.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/xiaomage234/comments/commentRss/416280.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/xiaomage234/services/trackbacks/416280.html</trackback:ping><description><![CDATA[from:http://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服务器,它的处理性能直接关系到用户体验,在^时的工作和学习中Q归U_以下七种调优l验?/p><h1><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) 内存在大量数据处理的情况下,会有较大的内存定w需求,可以?Xmx -Xms -XX:MaxPermSize{参数对内存不同功能块进行划分。我们之前就遇到q内存分配不ID虚拟Z直处于full GCQ从而导致处理能力严重下降?br style="padding: 0px; margin: 0px;" />    (3) 盘主要问题是d性能Q当大量文gq行dӞ盘极容易成为性能瓉。最好的办法q是利用下面提到的缓存?/p><h1><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;">    对于静态页面最好是能够~存hQ这样就不必每次从磁盘上诅R这里我们采用了Nginx作ؓ~存服务器,图片、css、js文g都进行了~存Q有效的减少了后端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;">    另外Qؓ了能加快|络传输速度Q开启gzip压羃也是必不可少的。但考虑到tomcat已经需要处理很多东西了Q所以把q个压羃的工作就交给前端的Nginx来完成。可以参考之前写的?a target="_blank" style="padding: 0px; margin: 0px; color: #4b0002; text-decoration: none;">利用nginx加速web讉K</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压羃Q其实很多图片也可以用图像处理工具预先进行压~,扑ֈ一个^衡点可以让画质损失很而文件可以减很多。曾l我pq一个图片从300多kb压羃到几十kbQ自己几乎看不出来区别?/p><h1><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;">    单个服务器性能L有限的,最好的办法自然是实现横向扩展,那么l徏tomcat集群是有效提升性能的手Dc我们还是采用了Nginx来作求分的服务器,后端多个tomcat׃nsession来协同工作。可以参考之前写的?a target="_blank" style="padding: 0px; margin: 0px; color: #4b0002; text-decoration: none;">利用nginx+tomcat+memcachedl徏web服务器负载均?/a>》?/p><h1><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;">    q里以tomcat7的参数配|ؓ例,需要修改conf/server.xml文gQ主要是优化q接配置Q关闭客Ldns查询?/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><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模型Q在几百q发下性能会有很严重的下降。tomcat自带q有NIO的模型,另外也可以调用APR的库来实现操作系l别控制?/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模型是内|的Q调用很方便Q只需要将上面配置文g中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.Http11NioProtocolQ重启即可生效。上面配|我已经改过了,默认的是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则需要安装第三方库,在高q发下会让性能有明显提升。具体安装办法可以参?a style="padding: 0px; margin: 0px; color: #4b0002; text-decoration: none;">http://www.cnblogs.com/huangjingzhou/articles/2097241.html</a>。安装完成后<span style="padding: 0px; margin: 0px; font-size: 16px; line-height: 18px; font-family: 宋体;">重启卛_生效。如使用默认protocal是aprQ但最好把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.Http11AprProtocolQ会更加明确</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;">    在官ҎC个表Dl说明了q三U方式的区别Q?/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><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也明提Z优化|卡驱动可以有效提升性能Q这个对于集环境工作的时候尤为重要。由于我们采用了linux服务器,所以优化内核参C是一个非帔R要的工作。给一个参考的优化参数Q?/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文gQ在最后追加如下内容: </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><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ȝ最忌讳的就是只调优不测试,有时不适当的优化反而会让性能更低。以上所有的优化Ҏ都要在本地进行性能试q后再不断调整参敎ͼq样最l才能达到最佳的优化效果?/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;">    对于q几U模式,我用ab命o模拟1000q发试10000词,试l果比较意外Qؓ了确认结果,我每U方式反复测试了10多次Qƈ且在两个服务器上都测试了一遍。结果发现Bio和Nio性能差别非常微弱Q难怪默认居然还是Bio。但是采用aprQ连接徏立的速度会有50%?00%的提升。直接调用操作系l层果然速啊Q这里强烈推荐apr方式Q?/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;">http://16.199.geisvps.com/bbs/2836/24238.html</a></p><img src ="http://www.aygfsteel.com/xiaomage234/aggbug/416280.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/xiaomage234/" target="_blank">马?/a> 2014-07-29 10:31 <a href="http://www.aygfsteel.com/xiaomage234/archive/2014/07/29/416280.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Tomcat7调试q行环境搭徏与源代码分析入门http://www.aygfsteel.com/xiaomage234/archive/2013/08/21/403124.html马?/dc:creator>马?/author>Wed, 21 Aug 2013 04:30:00 GMThttp://www.aygfsteel.com/xiaomage234/archive/2013/08/21/403124.htmlhttp://www.aygfsteel.com/xiaomage234/comments/403124.htmlhttp://www.aygfsteel.com/xiaomage234/archive/2013/08/21/403124.html#Feedback0http://www.aygfsteel.com/xiaomage234/comments/commentRss/403124.htmlhttp://www.aygfsteel.com/xiaomage234/services/trackbacks/403124.html阅读全文

]]>
下蝲Tomcat源码Qƈ作ؓ工程导入到Eclipse?http://www.aygfsteel.com/xiaomage234/archive/2013/08/21/403118.html马?/dc:creator>马?/author>Wed, 21 Aug 2013 02:41:00 GMThttp://www.aygfsteel.com/xiaomage234/archive/2013/08/21/403118.htmlhttp://www.aygfsteel.com/xiaomage234/comments/403118.htmlhttp://www.aygfsteel.com/xiaomage234/archive/2013/08/21/403118.html#Feedback0http://www.aygfsteel.com/xiaomage234/comments/commentRss/403118.htmlhttp://www.aygfsteel.com/xiaomage234/services/trackbacks/403118.html导入Tomcat的源代码Q其实很单,可是如果没有扑ֈ正确的方法,你会费大量的时_我就是浪费了好多旉在配|编译环境上。最正确的办法是到Tomcat的官方网址L到答案?/div>
可以参考下边的q接Q这个是关于Tomcat7的?/div>
http://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 http://svn.apache.org/repos/asf/tomcat/tc7.0.x/tags/TOMCAT_7_0_11/ D:\Tomcat7\
上边的命令SVN会把最新的Tomcat7011的源码下载到你的盘D:\Tomcat7\ ?br />SVN 下蝲地址 http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91
 
3. 为Eclipse~译工程
   cd ${tomcat.source}
   ant ide-eclipse
  [注] a. ${tomcat.source} 是你下蝲的源码在机器上的路径
       b. ant ide-eclipse: q个q程会比较慢Q因Z下蝲一些依赖的W三方jarQ这些jar都会攑ֈ你在
          build.properties 中设|的 ${base.path} 所指向的\?/div>
4. 讄Eclipse 环境 (Class-path Variables)
   讄TOMCAT_LIBS_BASEQANT_HOME
   TOMCAT_LIBS_BASE 要指?nbsp;${base.path}
   ANT_HOME 指向安装ant的目录就好了
5. 导入工程
   File -> Import and choose Existing Projects into Workspace
6. ~译问题
   往往我们在这时会遇到一些编译错误,q是因ؓ我们Eclipse中JRE环境讄的不正确Q需要调?/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
       当然Q这个也可以在工E中讑֮Q如果你q有其他的工E必ȝ以前的jdk版本的话?/div>
   6.3 Eclipse 版本问题
       调整好Java Compiler ?JRE 后,一般可以编译通过了,但是我就遇到了Eclipse版本问题QL一?nbsp;
       compiler ArrayIndexOutofBoundaryException 的错误,后来更新了一下Eclipse,好了,我用?/div>
       Eclipse 版本?.2的。我又用了Eclipse Galileo试着打开工程Q就没有cM的问题?/div>
7. 最周到的服?/div>
   Cq里Q您的工E应该就~译成功了。该x怎么run, debug TOMCAT了,怎么讄啊?哈,最周到的服?/div>
   来了Q在 run(debug) ... -> Java Application 中,我们会看到已l有两个applications 了,分别叫做
   start-tomcat, stop-tomcat.


]]> վ֩ģ壺 | ɿ| Т| ľ| | | | | | 㽭ʡ| | | ׯ| н| | | ٹ| | ߮| Դ| Ϳ| غ| ֽ| | | Ȫ| | ɣ| ׯ| ƺ| | ľ| ٲ| ͺ| | ͷ| | | | ʯ| ɽ|