﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-Todd</title><link>http://www.blogjava.net/Todd/</link><description /><language>zh-cn</language><lastBuildDate>Tue, 12 May 2026 21:33:43 GMT</lastBuildDate><pubDate>Tue, 12 May 2026 21:33:43 GMT</pubDate><ttl>60</ttl><item><title>【unix】crontab 中使用环境变量</title><link>http://www.blogjava.net/Todd/archive/2012/08/17/385698.html</link><dc:creator>Todd</dc:creator><author>Todd</author><pubDate>Fri, 17 Aug 2012 08:13:00 GMT</pubDate><guid>http://www.blogjava.net/Todd/archive/2012/08/17/385698.html</guid><wfw:comment>http://www.blogjava.net/Todd/comments/385698.html</wfw:comment><comments>http://www.blogjava.net/Todd/archive/2012/08/17/385698.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Todd/comments/commentRss/385698.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Todd/services/trackbacks/385698.html</trackback:ping><description><![CDATA[<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; ">环境:(产品,平台,机型,软件版本,等)AIX5L</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; ">问题描述:crontab中启动的shell脚本不能正常运行，但是使用手动执行没有问题，在$home/.profile中设定了脚本所需要的环境变量。</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; ">解答:cron命令的默认shell是/usr/bin/bsh，如果要在cron启动的脚本中使用ksh，就必须在脚本中的第一行添加&#8220;#!/usr/bin/ksh&#8221;的声明。</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; ">如果cron进程启动的shell脚本要用登录时的环境变量，就必须在cron启动的shell脚本中添加下面的内容，才能够在启动的脚本中使用<br />
$home/.profile文件中的环境变量。</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; ">. $home/.profile</p>
<p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; ">这是因为cron进程执行的shell脚本是不会自动加载用户目录下的.profile文件，所以需要脚本自己加载所需要的环境变量。<br />
================<br />
环境变量文件加载顺序<br />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; color: blue; ">/etc/profile:</span><span style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; ">&nbsp;此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.</span><br style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; " />
<span style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; ">并从/etc/profile.d目录的配置文件中搜集shell的设置.</span><br style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; " />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; color: blue; ">/etc/bashrc:</span><span style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; ">&nbsp;为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取.</span><br style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; " />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; color: blue; ">~/.bash_profile:</span><span style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; ">&nbsp;每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该</span><br style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; " />
<span style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; ">文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件.</span><br style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; " />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; color: blue; ">~/.bashrc:</span><span style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; ">&nbsp;该文件包含专用于你的bash shell的bash信息,当登录时以及每次打开新的shell时,该</span><br style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; " />
<span style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; ">该文件被读取.</span><br style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; " />
<span style="font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; color: blue; ">~/.bash_logout:</span><span style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; ">&nbsp;当每次退出系统(退出bash shell)时,执行该文件.&nbsp;</span><br style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; " />
<br style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; " />
<span style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; ">另外,/etc/profile中设定的变量(全局)的可以作用于任何用户,而~/.bashrc等中设定的变量(局部)只能继承/etc/profile中的变量,他们是"父子"关系.</span><br style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; " />
<br style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; " />
<span style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; ">~/.bash_profile 是交互式、login 方式进入 bash 运行的</span><br style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; " />
<span style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; ">~/.bashrc 是交互式 non-login 方式进入 bash 运行的</span><br style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; " />
<span style="color: #000000; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 19px; text-align: -webkit-auto; background-color: #28557e; ">通常二者设置大致相同，所以通常前者会调用后者。</span>&nbsp;<br />
</p>
<img src ="http://www.blogjava.net/Todd/aggbug/385698.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Todd/" target="_blank">Todd</a> 2012-08-17 16:13 <a href="http://www.blogjava.net/Todd/archive/2012/08/17/385698.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【oracle】高并发量表更新注意点</title><link>http://www.blogjava.net/Todd/archive/2012/07/25/383896.html</link><dc:creator>Todd</dc:creator><author>Todd</author><pubDate>Tue, 24 Jul 2012 18:29:00 GMT</pubDate><guid>http://www.blogjava.net/Todd/archive/2012/07/25/383896.html</guid><wfw:comment>http://www.blogjava.net/Todd/comments/383896.html</wfw:comment><comments>http://www.blogjava.net/Todd/archive/2012/07/25/383896.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Todd/comments/commentRss/383896.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Todd/services/trackbacks/383896.html</trackback:ping><description><![CDATA[移动一个业务高并发，接入一个客户电话就发一个特殊邀请码（码为字符加数字混编，无规律），码已存表，业务上要 码和用户手机号码一一对应；<br />
所以，来个用户就得对未标记的码更新手机号码；高并发时，行锁及等待比较耗时，导致数据库性能下降严重；<br />
解决办法，<br />
码表增加seqid,字段；导入数据时使用rownum,做该字段值,建索引；<br />
更新时，使用序列，
<div></div>
<div>CREATE SEQUENCE SQ_U_SEQ INCREMENT BY 1 START WITH 1 MAXVALUE 50000000 CYCLE CACHE 2000 NOORDER;<br />
更新则：update ... where ... and t.seqid =&nbsp;SQ_U_SEQ.nextval ...;<br />
以后有新的数据要导入，则序列需重置，则：</div>
<div style="font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; border-image: initial; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; background-color: #eeeeee; "><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #0000FF; ">create</span>&nbsp;<span style="color: #808080; ">or</span>&nbsp;<span style="color: #FF00FF; ">replace</span>&nbsp;<span style="color: #0000FF; ">procedure</span>&nbsp;seq_reset(v_seqname&nbsp;<span style="font-weight: bold; ">varchar2</span>)&nbsp;<span style="color: #0000FF; ">as</span>&nbsp;n&nbsp;<span style="font-weight: bold; ">number</span>(<span style="color: #800000; font-weight: bold; ">10</span>);<br />
tsql&nbsp;<span style="font-weight: bold; ">varchar2</span>(<span style="color: #800000; font-weight: bold; ">100</span>);<br />
&nbsp;<span style="color: #0000FF; ">begin</span><br />
&nbsp;<span style="color: #0000FF; ">execute</span>&nbsp;immediate&nbsp;<span style="color: #FF0000; ">'</span><span style="color: #FF0000; ">select&nbsp;</span><span style="color: #FF0000; ">'</span><span style="color: #808080; ">||</span>v_seqname<span style="color: #808080; ">||</span><span style="color: #FF0000; ">'</span><span style="color: #FF0000; ">.nextval&nbsp;from&nbsp;dual</span><span style="color: #FF0000; ">'</span>&nbsp;<span style="color: #0000FF; ">into</span>&nbsp;n;<br />
&nbsp;&nbsp;n:<span style="color: #808080; ">=-</span>(n<span style="color: #808080; ">-</span><span style="color: #800000; font-weight: bold; ">1</span>);<br />
&nbsp;&nbsp;tsql:<span style="color: #808080; ">=</span><span style="color: #FF0000; ">'</span><span style="color: #FF0000; ">alter&nbsp;sequence&nbsp;</span><span style="color: #FF0000; ">'</span><span style="color: #808080; ">||</span>v_seqname<span style="color: #808080; ">||</span><span style="color: #FF0000; ">'</span><span style="color: #FF0000; ">&nbsp;increment&nbsp;by&nbsp;</span><span style="color: #FF0000; ">'</span><span style="color: #808080; ">||</span>&nbsp;n;<br />
&nbsp;&nbsp;<span style="color: #0000FF; ">execute</span>&nbsp;immediate&nbsp;tsql;<br />
&nbsp;<span style="color: #0000FF; ">execute</span>&nbsp;immediate&nbsp;<span style="color: #FF0000; ">'</span><span style="color: #FF0000; ">select&nbsp;</span><span style="color: #FF0000; ">'</span><span style="color: #808080; ">||</span>v_seqname<span style="color: #808080; ">||</span><span style="color: #FF0000; ">'</span><span style="color: #FF0000; ">.nextval&nbsp;from&nbsp;dual</span><span style="color: #FF0000; ">'</span>&nbsp;<span style="color: #0000FF; ">into</span>&nbsp;n;<br />
&nbsp;&nbsp;tsql:<span style="color: #808080; ">=</span><span style="color: #FF0000; ">'</span><span style="color: #FF0000; ">alter&nbsp;sequence&nbsp;</span><span style="color: #FF0000; ">'</span><span style="color: #808080; ">||</span>v_seqname<span style="color: #808080; ">||</span><span style="color: #FF0000; ">'</span><span style="color: #FF0000; ">&nbsp;increment&nbsp;by&nbsp;1</span><span style="color: #FF0000; ">'</span>;<br />
&nbsp;<span style="color: #0000FF; ">execute</span>&nbsp;immediate&nbsp;tsql;<br />
&nbsp;<span style="color: #0000FF; ">end</span>&nbsp;seq_reset;</div>
另外，高并发时序列的cache要设置大点,一般业务设置100以上，但nocache的时候性能确实很差，最大相差20倍．
排序参数：oracle默认是NOORDER，如果设置为ORDER；在单实例环境没有影响，在RAC环境此时，多实例实际缓存相同的序列，此时在多个实例并发取该序列的时候，会有短暂的资源竞争来在多实例之间进行同步。因次性能相比noorder要差，所以RAC环境非必须的情况下不要使用ORDER，尤其要避免NOCACHE   ORDER组合；
<img src ="http://www.blogjava.net/Todd/aggbug/383896.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Todd/" target="_blank">Todd</a> 2012-07-25 02:29 <a href="http://www.blogjava.net/Todd/archive/2012/07/25/383896.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VI常用命令</title><link>http://www.blogjava.net/Todd/archive/2012/07/18/383419.html</link><dc:creator>Todd</dc:creator><author>Todd</author><pubDate>Wed, 18 Jul 2012 09:32:00 GMT</pubDate><guid>http://www.blogjava.net/Todd/archive/2012/07/18/383419.html</guid><wfw:comment>http://www.blogjava.net/Todd/comments/383419.html</wfw:comment><comments>http://www.blogjava.net/Todd/archive/2012/07/18/383419.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Todd/comments/commentRss/383419.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Todd/services/trackbacks/383419.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;VI常用命令_______________________________________________________一般模式&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb...&nbsp;&nbsp;<a href='http://www.blogjava.net/Todd/archive/2012/07/18/383419.html'>阅读全文</a><img src ="http://www.blogjava.net/Todd/aggbug/383419.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Todd/" target="_blank">Todd</a> 2012-07-18 17:32 <a href="http://www.blogjava.net/Todd/archive/2012/07/18/383419.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【2】freebsd netperf 网络性能测试工具 </title><link>http://www.blogjava.net/Todd/archive/2012/03/29/373010.html</link><dc:creator>Todd</dc:creator><author>Todd</author><pubDate>Thu, 29 Mar 2012 14:45:00 GMT</pubDate><guid>http://www.blogjava.net/Todd/archive/2012/03/29/373010.html</guid><wfw:comment>http://www.blogjava.net/Todd/comments/373010.html</wfw:comment><comments>http://www.blogjava.net/Todd/archive/2012/03/29/373010.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Todd/comments/commentRss/373010.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Todd/services/trackbacks/373010.html</trackback:ping><description><![CDATA[1.下载：<a href="http://www.netperf.org/netperf/DownloadNetperf.html">http://www.netperf.org/netperf/DownloadNetperf.html</a>
<br />2.安装，netperf-2.5.0.tar.gz；解压后执行一下命令：<br />cd&nbsp;netperf-2.5.0<div>./configure<br />make &amp;&amp; make install<br />默认安装目录：/usr/local/bin<br />有两个文件 netperf netserver<br />后者服务端（在要测试的机器上也要安装，并执行netserver启动之，否则客户端报错） &nbsp;前者客户端<br />3.测试--直接转别人的<br /></div><br /><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; "><a name="N100B4"><span style="font-size: 1.2em; font-weight: bold; ">TCP网络性能</span></a></p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">由于TCP协议能够提供端到端的可靠传输，因此被大量的网络应用程序使用。但是，可靠性的建立是要付出代价的。TCP协议保证可靠性的措施，如建立并维护连接、控制数据有序的传递等都会消耗一定的网络带宽。</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">Netperf可以模拟三种不同的TCP流量模式：</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">1）	单个TCP连接，批量（bulk）传输大量数据</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">2）	单个TCP连接，client请求/server应答的交易（transaction）方式</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">3）	多个TCP连接，每个连接中一对请求/应答的交易方式</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; "><a name="N100C9"><span style="font-size: 1.2em; font-weight: bold; ">UDP网络性能</span></a></p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">UDP没有建立连接的负担，但是UDP不能保证传输的可靠性，所以使用UDP的应用程序需要自行跟踪每个发出的分组，并重发丢失的分组。</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">Netperf可以模拟两种UDP的流量模式：</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">1）	从client到server的单向批量传输</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">2）	请求/应答的交易方式</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">由于UDP传输的不可靠性，在使用netperf时要确保发送的缓冲区大小不大于接收缓冲区大小，否则数据会丢失，netperf将给出错误的结果。因此，对于接收到分组的统计不一定准确，需要结合发送分组的统计综合得出结论。</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; "><a name="N100DE"><span style="font-size: 1.2em; font-weight: bold; ">Netperf的命令行参数</span></a></p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">在unix系统中，可以直接运行可执行程序来启动netserver，也可以让inetd或xinetd来自动启动netserver。</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">当netserver在server端启动以后，就可以在client端运行netperf来测试网络的性能。netperf通过命令行参数来控制测试的类型和具体的测试选项。根据作用范围的不同，netperf的命令行参数可以分为两大类：全局命令行参数、测试相关的局部参数，两者之间使用--分隔：</p><table width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size: 0.8em; color: #000000; font-family: Simsun; text-align: left; "><tbody><tr><td style="font-family: arial, nsimsun, sans-serif; background-color: #f7f7f7 !important; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 2px; padding-right: 2px; padding-bottom: 5px; padding-left: 2px; "><pre style="width: 694px; margin-top: 0px; margin-bottom: 0px; font-family: 'Andale Mono', 'Lucida Console', Monaco, Liberation, fixed, monospace; font-size: 11px; overflow-x: auto; overflow-y: auto; background-image: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; ">netperf [global options]-- [test-specific options] </pre></td></tr></tbody></table><br style="font-family: Simsun; text-align: left; font-size: medium; " /><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">这里我们只解释那些常用的命令行参数，其它的参数读者可以查询netperf的man手册。</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">-H host ：指定远端运行netserver的server IP地址。</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">-l testlen：指定测试的时间长度（秒）</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">-t testname：指定进行的测试类型，包括TCP_STREAM，UDP_STREAM，TCP_RR，TCP_CRR，UDP_RR，在下文中分别对它们说明。</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">在后面的测试中，netserver运行在192.168.0.28，server与client通过局域网连接（100M Hub）。</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; "><a name="N100FD"><span style="font-size: 1.2em; font-weight: bold; ">Netperf测试网络性能</span></a></p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; "><strong>测试批量（bulk）网络流量的性能</strong></p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">批量数据传输典型的例子有ftp和其它类似的网络应用（即一次传输整个文件）。根据使用传输协议的不同，批量数据传输又分为TCP批量传输和UDP批量传输。</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">1．	TCP_STREAM</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">Netperf缺省情况下进行TCP批量传输，即-t TCP_STREAM。测试过程中，netperf向netserver发送批量的TCP数据分组，以确定数据传输过程中的吞吐量：</p><table width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size: 0.8em; color: #000000; font-family: Simsun; text-align: left; "><tbody><tr><td style="font-family: arial, nsimsun, sans-serif; background-color: #f7f7f7 !important; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 2px; padding-right: 2px; padding-bottom: 5px; padding-left: 2px; "><pre style="width: 694px; margin-top: 0px; margin-bottom: 0px; font-family: 'Andale Mono', 'Lucida Console', Monaco, Liberation, fixed, monospace; font-size: 11px; overflow-x: auto; overflow-y: auto; background-image: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; "> ./netperf -H 192.168.0.28 -l 60 TCP STREAM TEST to 192.168.0.28 Recv   Send    Send Socket Socket  Message  Elapsed Size   Size    Size     Time     Throughput bytes  bytes   bytes    secs.    10^6bits/sec    87380  16384  16384    60.00      88.00  </pre></td></tr></tbody></table><br style="font-family: Simsun; text-align: left; font-size: medium; " /><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">从netperf的结果输出中，我们可以知道以下的一些信息：</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">1）	远端系统（即server）使用大小为87380字节的socket接收缓冲</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">2）	本地系统（即client）使用大小为16384字节的socket发送缓冲</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">3）	向远端系统发送的测试分组大小为16384字节</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">4）	测试经历的时间为60秒</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">5）	吞吐量的测试结果为88Mbits/秒</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">在缺省情况下，netperf向发送的测试分组大小设置为本地系统所使用的socket发送缓冲大小。</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">TCP_STREAM方式下与测试相关的局部参数如下表所示：</p><table border="1" width="70%" style="font-size: 0.8em; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; border-top-width: 0px; border-top-style: initial; border-top-color: initial; width: 708px; color: #000000; font-family: Simsun; text-align: left; "><tbody><tr><td style="font-family: arial, nsimsun, sans-serif; border-top-color: #cccccc; border-top-style: solid; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; ">参数</td><td style="font-family: arial, nsimsun, sans-serif; border-top-color: #cccccc; border-top-style: solid; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; ">说明</td></tr><tr><td style="font-family: arial, nsimsun, sans-serif; border-top-color: #cccccc; border-top-style: solid; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; ">-s size</td><td style="font-family: arial, nsimsun, sans-serif; border-top-color: #cccccc; border-top-style: solid; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; ">设置本地系统的socket发送与接收缓冲大小</td></tr><tr><td style="font-family: arial, nsimsun, sans-serif; border-top-color: #cccccc; border-top-style: solid; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; ">-S size</td><td style="font-family: arial, nsimsun, sans-serif; border-top-color: #cccccc; border-top-style: solid; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; ">设置远端系统的socket发送与接收缓冲大小</td></tr><tr><td style="font-family: arial, nsimsun, sans-serif; border-top-color: #cccccc; border-top-style: solid; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; ">-m size</td><td style="font-family: arial, nsimsun, sans-serif; border-top-color: #cccccc; border-top-style: solid; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; ">设置本地系统发送测试分组的大小</td></tr><tr><td style="font-family: arial, nsimsun, sans-serif; border-top-color: #cccccc; border-top-style: solid; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; ">-M size</td><td style="font-family: arial, nsimsun, sans-serif; border-top-color: #cccccc; border-top-style: solid; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; ">设置远端系统接收测试分组的大小</td></tr><tr><td style="font-family: arial, nsimsun, sans-serif; border-top-color: #cccccc; border-top-style: solid; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; ">-D</td><td style="font-family: arial, nsimsun, sans-serif; border-top-color: #cccccc; border-top-style: solid; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; ">对本地与远端系统的socket设置TCP_NODELAY选项</td></tr></tbody></table><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">通过修改以上的参数，并观察结果的变化，我们可以确定是什么因素影响了连接的吞吐量。例如，如果怀疑路由器由于缺乏足够的缓冲区空间，使得转发大的分组时存在问题，就可以增加测试分组（-m）的大小，以观察吞吐量的变化：</p><table width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size: 0.8em; color: #000000; font-family: Simsun; text-align: left; "><tbody><tr><td style="font-family: arial, nsimsun, sans-serif; background-color: #f7f7f7 !important; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 2px; padding-right: 2px; padding-bottom: 5px; padding-left: 2px; "><pre style="width: 694px; margin-top: 0px; margin-bottom: 0px; font-family: 'Andale Mono', 'Lucida Console', Monaco, Liberation, fixed, monospace; font-size: 11px; overflow-x: auto; overflow-y: auto; background-image: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; "> ./netperf -H 192.168.0.28 -l 60 -- -m 2048 TCP STREAM TEST to 192.168.0.28 Recv   Send    Send Socket Socket  Message  Elapsed Size   Size    Size     Time     Throughput bytes  bytes   bytes    secs.    10^6bits/sec    87380  16384   2048    60.00      87.62  </pre></td></tr></tbody></table><br style="font-family: Simsun; text-align: left; font-size: medium; " /><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">在这里，测试分组的大小减少到2048字节，而吞吐量却没有很大的变化（与前面例子中测试分组大小为16K字节相比）。相反，如果吞吐量有了较大的提升，则说明在网络中间的路由器确实存在缓冲区的问题。</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">2．	UDP_STREAM</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">UDP_STREAM用来测试进行UDP批量传输时的网络性能。需要特别注意的是，此时测试分组的大小不得大于socket的发送与接收缓冲大小，否则netperf会报出错提示：</p><table width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size: 0.8em; color: #000000; font-family: Simsun; text-align: left; "><tbody><tr><td style="font-family: arial, nsimsun, sans-serif; background-color: #f7f7f7 !important; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 2px; padding-right: 2px; padding-bottom: 5px; padding-left: 2px; "><pre style="width: 694px; margin-top: 0px; margin-bottom: 0px; font-family: 'Andale Mono', 'Lucida Console', Monaco, Liberation, fixed, monospace; font-size: 11px; overflow-x: auto; overflow-y: auto; background-image: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; ">./netperf -t UDP_STREAM -H 192.168.0.28 -l 60 UDP UNIDIRECTIONAL SEND TEST to 192.168.0.28 udp_send: data send error: Message too long </pre></td></tr></tbody></table><br style="font-family: Simsun; text-align: left; font-size: medium; " /><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">为了避免这样的情况，可以通过命令行参数限定测试分组的大小，或者增加socket的发送/接收缓冲大小。UDP_STREAM方式使用与TCP_STREAM方式相同的局部命令行参数，因此，这里可以使用-m来修改测试中使用分组的大小：</p><table width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size: 0.8em; color: #000000; font-family: Simsun; text-align: left; "><tbody><tr><td style="font-family: arial, nsimsun, sans-serif; background-color: #f7f7f7 !important; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 2px; padding-right: 2px; padding-bottom: 5px; padding-left: 2px; "><pre style="width: 694px; margin-top: 0px; margin-bottom: 0px; font-family: 'Andale Mono', 'Lucida Console', Monaco, Liberation, fixed, monospace; font-size: 11px; overflow-x: auto; overflow-y: auto; background-image: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; "> ./netperf -t UDP_STREAM -H 192.168.0.28 -- -m 1024 UDP UNIDIRECTIONAL SEND TEST to 192.168.0.28 Socket  Message  Elapsed      Messages Size    Size     Time         Okay Errors   Throughput bytes   bytes    secs            #      #   10^6bits/sec    65535    1024   9.99       114127      0      93.55  65535           9.99       114122             93.54  </pre></td></tr></tbody></table><br style="font-family: Simsun; text-align: left; font-size: medium; " /><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">UDP_STREAM方式的结果中有两行测试数据，第一行显示的是本地系统的发送统计，这里的吞吐量表示netperf向本地socket发送分组的能力。但是，我们知道，UDP是不可靠的传输协议，发送出去的分组数量不一定等于接收到的分组数量。</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">第二行显示的就是远端系统接收的情况，由于client与server直接连接在一起，而且网络中没有其它的流量，所以本地系统发送过去的分组几乎都被远端系统正确的接收了，远端系统的吞吐量也几乎等于本地系统的发送吞吐量。但是，在实际环境中，一般远端系统的socket缓冲大小不同于本地系统的socket缓冲区大小，而且由于UDP协议的不可靠性，远端系统的接收吞吐量要远远小于发送出去的吞吐量。</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; "><strong>测试请求/应答（request/response）网络流量的性能</strong></p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">另一类常见的网络流量类型是应用在client/server结构中的request/response模式。在每次交易（transaction）中，client向server发出小的查询分组，server接收到请求，经处理后返回大的结果数据。如下图所示：</p><br style="font-family: Simsun; text-align: left; font-size: medium; " /><img alt="" border="0" height="208" src="http://www.ibm.com/developerworks/cn/linux/l-netperf/images/image002.gif" width="283" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-family: Simsun; text-align: left; font-size: medium; " />&nbsp;<br style="font-family: Simsun; text-align: left; font-size: medium; " /><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">1．	TCP_RR</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">TCP_RR方式的测试对象是多次TCP request和response的交易过程，但是它们发生在同一个TCP连接中，这种模式常常出现在数据库应用中。数据库的client程序与server程序建立一个TCP连接以后，就在这个连接中传送数据库的多次交易过程。</p><table width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size: 0.8em; color: #000000; font-family: Simsun; text-align: left; "><tbody><tr><td style="font-family: arial, nsimsun, sans-serif; background-color: #f7f7f7 !important; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 2px; padding-right: 2px; padding-bottom: 5px; padding-left: 2px; "><pre style="width: 694px; margin-top: 0px; margin-bottom: 0px; font-family: 'Andale Mono', 'Lucida Console', Monaco, Liberation, fixed, monospace; font-size: 11px; overflow-x: auto; overflow-y: auto; background-image: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; ">./netperf -t TCP_RR -H 192.168.0.28 TCP REQUEST/RESPONSE TEST to 192.168.0.28 Local /Remote Socket Size   Request  Resp.   Elapsed  Trans. Send   Recv   Size     Size    Time     Rate bytes  Bytes  bytes    bytes   secs.    per sec   16384  87380  1        1       10.00    9502.73 16384  87380 </pre></td></tr></tbody></table><br style="font-family: Simsun; text-align: left; font-size: medium; " /><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">Netperf输出的结果也是由两行组成。第一行显示本地系统的情况，第二行显示的是远端系统的信息。平均的交易率（transaction rate）为9502.73次/秒。注意到这里每次交易中的request和response分组的大小都为1个字节，不具有很大的实际意义。用户可以通过测试相关的参数来改变request和response分组的大小，TCP_RR方式下的参数如下表所示：</p><table border="1" width="70%" style="font-size: 0.8em; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; border-top-width: 0px; border-top-style: initial; border-top-color: initial; width: 708px; color: #000000; font-family: Simsun; text-align: left; "><tbody><tr><td style="font-family: arial, nsimsun, sans-serif; border-top-color: #cccccc; border-top-style: solid; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; ">参数</td><td style="font-family: arial, nsimsun, sans-serif; border-top-color: #cccccc; border-top-style: solid; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; ">说明</td></tr><tr><td style="font-family: arial, nsimsun, sans-serif; border-top-color: #cccccc; border-top-style: solid; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; ">-r req,resp</td><td style="font-family: arial, nsimsun, sans-serif; border-top-color: #cccccc; border-top-style: solid; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; ">设置request和reponse分组的大小</td></tr><tr><td style="font-family: arial, nsimsun, sans-serif; border-top-color: #cccccc; border-top-style: solid; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; ">-s size</td><td style="font-family: arial, nsimsun, sans-serif; border-top-color: #cccccc; border-top-style: solid; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; ">设置本地系统的socket发送与接收缓冲大小</td></tr><tr><td style="font-family: arial, nsimsun, sans-serif; border-top-color: #cccccc; border-top-style: solid; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; ">-S size</td><td style="font-family: arial, nsimsun, sans-serif; border-top-color: #cccccc; border-top-style: solid; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; ">设置远端系统的socket发送与接收缓冲大小</td></tr><tr><td style="font-family: arial, nsimsun, sans-serif; border-top-color: #cccccc; border-top-style: solid; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; ">-D</td><td style="font-family: arial, nsimsun, sans-serif; border-top-color: #cccccc; border-top-style: solid; padding-top: 8px; padding-right: 5px; padding-bottom: 8px; padding-left: 5px; vertical-align: top; ">对本地与远端系统的socket设置TCP_NODELAY选项</td></tr></tbody></table><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">通过使用-r参数，我们可以进行更有实际意义的测试：</p><table width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size: 0.8em; color: #000000; font-family: Simsun; text-align: left; "><tbody><tr><td style="font-family: arial, nsimsun, sans-serif; background-color: #f7f7f7 !important; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 2px; padding-right: 2px; padding-bottom: 5px; padding-left: 2px; "><pre style="width: 694px; margin-top: 0px; margin-bottom: 0px; font-family: 'Andale Mono', 'Lucida Console', Monaco, Liberation, fixed, monospace; font-size: 11px; overflow-x: auto; overflow-y: auto; background-image: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; ">./netperf -t TCP_RR -H 192.168.0.28 -- -r 32,1024 TCP REQUEST/RESPONSE TEST to 192.168.0.28 Local /Remote Socket Size   Request  Resp.   Elapsed  Trans. Send   Recv   Size     Size    Time     Rate bytes  Bytes  bytes    bytes   secs.    per sec   16384  87380  32       1024    10.00    4945.97 16384  87380 </pre></td></tr></tbody></table><br style="font-family: Simsun; text-align: left; font-size: medium; " /><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">从结果中可以看出，由于request/reponse分组的大小增加了，导致了交易率明显的下降。 注：相对于实际的系统，这里交易率的计算没有充分考虑到交易过程中的应用程序处理时延，因此结果往往会高于实际情况。</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">2．	TCP_CRR</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">与TCP_RR不同，TCP_CRR为每次交易建立一个新的TCP连接。最典型的应用就是HTTP，每次HTTP交易是在一条单独的TCP连接中进行的。因此，由于需要不停地建立新的TCP连接，并且在交易结束后拆除TCP连接，交易率一定会受到很大的影响。</p><table width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size: 0.8em; color: #000000; font-family: Simsun; text-align: left; "><tbody><tr><td style="font-family: arial, nsimsun, sans-serif; background-color: #f7f7f7 !important; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 2px; padding-right: 2px; padding-bottom: 5px; padding-left: 2px; "><pre style="width: 694px; margin-top: 0px; margin-bottom: 0px; font-family: 'Andale Mono', 'Lucida Console', Monaco, Liberation, fixed, monospace; font-size: 11px; overflow-x: auto; overflow-y: auto; background-image: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; ">./netperf -t TCP_CRR -H 192.168.0.28  TCP Connect/Request/Response TEST to 192.168.0.28 Local /Remote Socket Size   Request  Resp.   Elapsed  Trans. Send   Recv   Size     Size    Time     Rate bytes  Bytes  bytes    bytes   secs.    per sec   131070 131070 1        1       9.99     2662.20 16384  87380 </pre></td></tr></tbody></table><br style="font-family: Simsun; text-align: left; font-size: medium; " /><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">即使是使用一个字节的request/response分组，交易率也明显的降低了，只有2662.20次/秒。TCP_CRR使用与TCP_RR相同的局部参数。</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">3．	UDP_RR</p><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">UDP_RR方式使用UDP分组进行request/response的交易过程。由于没有TCP连接所带来的负担，所以我们推测交易率一定会有相应的提升。</p><table width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size: 0.8em; color: #000000; font-family: Simsun; text-align: left; "><tbody><tr><td style="font-family: arial, nsimsun, sans-serif; background-color: #f7f7f7 !important; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; padding-top: 2px; padding-right: 2px; padding-bottom: 5px; padding-left: 2px; "><pre style="width: 694px; margin-top: 0px; margin-bottom: 0px; font-family: 'Andale Mono', 'Lucida Console', Monaco, Liberation, fixed, monospace; font-size: 11px; overflow-x: auto; overflow-y: auto; background-image: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; ">./netperf -t UDP_RR -H 192.168.0.28  UDP REQUEST/RESPONSE TEST to 192.168.0.28 Local /Remote Socket Size   Request  Resp.   Elapsed  Trans. Send   Recv   Size     Size    Time     Rate bytes  Bytes  bytes    bytes   secs.    per sec   65535  65535  1        1       9.99     10141.16 65535  65535 </pre></td></tr></tbody></table><br style="font-family: Simsun; text-align: left; font-size: medium; " /><p style="font-family: arial, nsimsun, sans-serif; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0.3em; padding-right: 5px; padding-bottom: 0.7em; padding-left: 5px; font-size: 0.76em; text-align: left; ">结果证实了我们的推测，交易率为10141.16次/秒，高过TCP_RR的数值。不过，如果出现了相反的结果，即交易率反而降低了，也不需要担心，因为这说明了在网络中，路由器或其它的网络设备对UDP采用了与TCP不同的缓冲区空间和处理技术。</p><div style="clear: both; background-image: url(http://1.www.s81c.com/i/solid.gif); background-attachment: initial; background-origin: initial; background-clip: initial; height: 1px; font-family: Simsun; text-align: left; font-size: medium; background-repeat: repeat no-repeat; "></div><a href="http://www.ibm.com/developerworks/cn/linux/l-netperf/">http://www.ibm.com/developerworks/cn/linux/l-netperf/<br /></a><img src ="http://www.blogjava.net/Todd/aggbug/373010.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Todd/" target="_blank">Todd</a> 2012-03-29 22:45 <a href="http://www.blogjava.net/Todd/archive/2012/03/29/373010.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转]暴雪总裁总结游戏十条经验 </title><link>http://www.blogjava.net/Todd/archive/2012/03/19/372197.html</link><dc:creator>Todd</dc:creator><author>Todd</author><pubDate>Mon, 19 Mar 2012 07:33:00 GMT</pubDate><guid>http://www.blogjava.net/Todd/archive/2012/03/19/372197.html</guid><wfw:comment>http://www.blogjava.net/Todd/comments/372197.html</wfw:comment><comments>http://www.blogjava.net/Todd/archive/2012/03/19/372197.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Todd/comments/commentRss/372197.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Todd/services/trackbacks/372197.html</trackback:ping><description><![CDATA[<table cellspacing="0" cellpadding="0" style="word-wrap: break-word; empty-cells: show; border-collapse: collapse; table-layout: fixed; width: 757px; color: #333333; font-family: Arial; font-size: 12px; line-height: 18px; background-color: #ffffff; "><tbody style="word-wrap: break-word; "><tr style="word-wrap: break-word; "><td id="postmessage_9002210" style="word-wrap: break-word; font-size: 14px; ">暴雪创办人兼总裁Michael Morhaime在GDC Austin上发表了演讲，谈论他从《魔兽世界》和其他暴雪游戏中总结出来的十条经验。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />1&#183;游戏性第一。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />&nbsp; &nbsp; 如果你了解暴雪，那你知道他们在游戏平衡性上力尽完美，或者说比任何人做的都好。暴雪哲学好懂但难掌握。他们希望你入门容易而维持长时间的兴趣，用同一款产品同时吸引休闲和核心玩家。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />2&#183;打造并保护品牌。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />&nbsp; &nbsp; 暴雪的目标是要消费者进入商店，看到暴雪的商标就知道那是好东西。但个人认为暴雪这方面做的不好，为何？他们欺负了可怜的BNetD（战网私服）人员，控告一群没有反抗能力的开发者。暴雪真坏。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />3&#183;抗拒提早上市的诱惑。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />&nbsp; &nbsp; 这一点很多人都做不到。游戏是要在完成之后再推出，而不是当日历上某个时候到来。如果照着日历办事，那你的结果就是创世纪9，更糟糕的，就是多bug的微软恶梦般的操作系统。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />&nbsp; &nbsp; Michael指出，公司应该用长远的目光去看，而不是考虑短期。短期考虑通常不会有好结果。《暗黑破坏神》错过了圣诞假期，在12月31日推出。你会觉得暗黑是个错过了圣诞的游戏，还是个卖了几百万的游戏？《燃烧远征》也错过了圣诞假期，但在第一天就卖出了240万份。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />4&#183;不要所有东西都同时做。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />&nbsp; &nbsp; 知道自己能做什么，然后把它做好。《魔兽世界》并不是他们第一款在线游戏，《魔兽3》就有大量在线内容，《暗黑2》也是。从它们之中吸取经验，WOW就诞生了。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />5&#183;暴雪是一个全球性的企业。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />&nbsp; &nbsp; 它曾经只是美国的公司。东西先做好英文的再去做其它地区的。游戏先在北美发售，然后到欧洲，然后到其它地方。这种做法有好些弊端。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />&nbsp; &nbsp; 星际争霸，韩国的国家级游戏，显示的却不是本地语言。唯一有本地语言的是日本版，但这个版本又与其它的冲突，韩国人玩的是英文版。而北美和欧洲的灰色市场意味着当游戏在美国发售，那在欧洲发售日期之前人们就能拿到它，而当游戏正式在欧洲发售的时候，人们已经买到了，销售自然不好，零售商也不高兴。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />&nbsp; &nbsp; 解决方法就是平等的对待所有玩家。进行全球范围的同步发售。这需要更多时间，但绝对值得。《暗黑2》便是全球同时发售，而结果也相当好。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />6&#183;地区性口味的神话。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />&nbsp; &nbsp; 暴雪不相信有地区性口味这玩意儿，全球兴趣都是一样的，只是人数不同。如果你制作一款适合所有人口味得游戏，那你就不用针对每个市场各做一个版本了。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />&nbsp; &nbsp; 有一件事还是得注意，就是文化问题，比如魔兽3里的熊猫。游戏里的熊猫穿着日本服装拿着日本武器。中国玩家对此颇有怨言。因此它后来就改穿了中式服装和中式武器，问题就解决了。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />7&#183;运营网络游戏不属于游戏开发。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />&nbsp; &nbsp; 你在三个大陆上24小时不停得运行着数千台服务器。你还需要管理一群活跃但虚拟的社区。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />&nbsp; &nbsp; 举个例子，你的开发小组在为游戏增加内容，但如果小组需要修正服务器的问题，他们就不能继续开发那些内容，哪个更重要？暴雪特别成立了一个小组专门应付游戏里的问题，这样开发小组就可以专注于他们的工作了。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />8&#183;交流。内部交流、外部交流。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />&nbsp; &nbsp; 如果你有社区，跟他们交谈，经常的，清楚的。如果有个大bug，或者服务器挂了，工作人员马上就开始工作，他们不会到论坛里解释问题，时间就这样浪费了。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />&nbsp; &nbsp; 因为这样，内部无关人员不知道发生了什么事，外面的人也不知道发生了什么事，然后人们开始抓狂，在论坛上疯狂发贴然后论坛就挂了。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />&nbsp; &nbsp; 为了解决这个问题，暴雪建立了一个正式的邮件系统。开发小组可以与内部人员交流，消息可以有秩序的传播开去。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />9&#183;避免涉及金钱。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />&nbsp; &nbsp; 只要你在WOW里显露出一点商机，人们就会滥用它。如果你把它隐藏，问题就变小了。如果坏人不能赚钱，淘金、窃取帐号、伪造信用卡等等这些问题就不再存在了。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />10&#183;持续测试游戏。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />&nbsp; &nbsp; 不要相信Ver.1.0。你测试的越多就越好，但很少人能做到。在暴雪，每时每刻每人都在测试。先有封测，然后公测，然后发售，希望游戏到了发售日的时候能有平衡性、流畅、无bug。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />&nbsp; &nbsp; 暴雪在燃烧远征的发售上相当接近这个目标。服务器的结构升级以减少网络延迟，并提升了容量。他们补充了很多的内容，最后把发售日期推迟到完成的那一天。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />&nbsp; &nbsp; 最后，他们在当地时间凌晨发售了。一天卖掉了240万份，这是很好的成绩。有管理员表示当他看着服务器的灯一个接一个亮起来的时候他感到非常欣慰。<br style="word-wrap: break-word; " /><br style="word-wrap: break-word; " />&nbsp; &nbsp; 暴雪奋斗了16年，现在有数百万玩家在线游戏，他们做出了不错的成绩。任何技术都会出现问题，但暴雪总能把它们减轻。希望日后的网络游戏可以从他们的错误和成功中学到一些经验</td></tr></tbody></table><img src ="http://www.blogjava.net/Todd/aggbug/372197.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Todd/" target="_blank">Todd</a> 2012-03-19 15:33 <a href="http://www.blogjava.net/Todd/archive/2012/03/19/372197.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【1】freebsd  安装，环境，资料</title><link>http://www.blogjava.net/Todd/archive/2012/02/09/369634.html</link><dc:creator>Todd</dc:creator><author>Todd</author><pubDate>Wed, 08 Feb 2012 17:26:00 GMT</pubDate><guid>http://www.blogjava.net/Todd/archive/2012/02/09/369634.html</guid><wfw:comment>http://www.blogjava.net/Todd/comments/369634.html</wfw:comment><comments>http://www.blogjava.net/Todd/archive/2012/02/09/369634.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Todd/comments/commentRss/369634.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Todd/services/trackbacks/369634.html</trackback:ping><description><![CDATA[<div>1.中文使用手册 必备<br /><a href="http://www.freebsd.org/doc/zh_CN/books/handbook/index.html">http://www.freebsd.org/doc/zh_CN/books/handbook/index.html</a><br />开发手册<br /><a href="http://www.freebsd.org/doc/en/books/developers-handbook/index.html">http://www.freebsd.org/doc/en/books/developers-handbook/index.html</a><br />2.系统安装<br />系统安装包FreeBSD-8.2-RELEASE-i386-disc1.iso 地址：<br /><a href="ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/ISO-IMAGES/8.2/">ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/ISO-IMAGES/8.2/</a><br />或者使用网易的镜像地址下载：<br /><a href="http://mirrors.163.com/FreeBSD/ISO-IMAGES-i386/8.2/">http://mirrors.163.com/FreeBSD/ISO-IMAGES-i386/8.2/</a><br />使用虚拟光驱加载iso文件，在vm中加载安装<br />安装步骤参见《手册》地址：<br /><a href="http://www.freebsd.org/doc/zh_CN/books/handbook/using-sysinstall.html">http://www.freebsd.org/doc/zh_CN/books/handbook/using-sysinstall.html</a><br />我使用标准安装，安装步骤很详细，若要ssh,标准安装中带ssh,检查下rc.conf中<pre class="SCREEN">sshd_enable="YES"
</pre><br />gcc也是自带装好的，可以hello验证下<br />#include &lt;stdio.h&gt;<br />int main()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("hello,todd^^\n");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0;<br />}<br />&gt;gcc hello.c -o hello<br />&gt;./hello<br />&gt;hello,todd^^<br />欧了<br /><br /><br /><br /><br /></div><img src ="http://www.blogjava.net/Todd/aggbug/369634.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Todd/" target="_blank">Todd</a> 2012-02-09 01:26 <a href="http://www.blogjava.net/Todd/archive/2012/02/09/369634.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转]linux下抓包命令--tcpdump的使用</title><link>http://www.blogjava.net/Todd/archive/2012/02/06/369460.html</link><dc:creator>Todd</dc:creator><author>Todd</author><pubDate>Mon, 06 Feb 2012 02:38:00 GMT</pubDate><guid>http://www.blogjava.net/Todd/archive/2012/02/06/369460.html</guid><wfw:comment>http://www.blogjava.net/Todd/comments/369460.html</wfw:comment><comments>http://www.blogjava.net/Todd/archive/2012/02/06/369460.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Todd/comments/commentRss/369460.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Todd/services/trackbacks/369460.html</trackback:ping><description><![CDATA[<div><div>例:tcpdump host 172.16.29.40 and port 4600 -X -s 500&nbsp;</div><div></div><div>tcpdump采用命令行方式，它的命令格式为：</div><div>　　tcpdump [ -adeflnNOpqStvx ] [ -c 数量 ] [ -F 文件名 ]</div><div>　　　　　　　　　　[ -i 网络接口 ] [ -r 文件名] [ -s snaplen ]</div><div>　　　　　　　　　　[ -T 类型 ] [ -w 文件名 ] [表达式 ]</div><div></div><div>　　1. tcpdump的选项介绍</div><div>　　　-a 　　　将网络地址和广播地址转变成名字；</div><div>　　　-d 　　　将匹配信息包的代码以人们能够理解的汇编格式给出；</div><div>　　　-dd 　　　将匹配信息包的代码以c语言程序段的格式给出；</div><div>　　　-ddd 　　　将匹配信息包的代码以十进制的形式给出；</div><div>　　　-e 　　　在输出行打印出数据链路层的头部信息；</div><div>　　　-f 　　　将外部的Internet地址以数字的形式打印出来；</div><div>　　　-l 　　　使标准输出变为缓冲行形式；</div><div>　　　-n 　　　不把网络地址转换成名字；</div><div>　　　-t 　　　在输出的每一行不打印时间戳；</div><div>　　　-v 　　　输出一个稍微详细的信息，例如在ip包中可以包括ttl和服务类型的信息；</div><div>　　　-vv 　　　输出详细的报文信息；</div><div>　　　-c 　　　在收到指定的包的数目后，tcpdump就会停止；</div><div>　　　-F 　　　从指定的文件中读取表达式,忽略其它的表达式；</div><div>　　　-i 　　　指定监听的网络接口；</div><div>　　　-r 　　　从指定的文件中读取包(这些包一般通过-w选项产生)；</div><div>　　　-w 　　　直接将包写入文件中，并不分析和打印出来；</div><div>　　　-T 　　　将监听到的包直接解释为指定的类型的报文，常见的类型有rpc （远程过程</div><div>调用）和snmp（简单　　　　　　　网络管理协议；）</div><div></div><div>　　2. tcpdump的表达式介绍</div><div>　　　表达式是一个正则表达式，tcpdump利用它作为过滤报文的条件，如果一个报文满足表</div><div>达式的条件，则这个报文将会被捕获。如果没有给出任何条件，则网络上所有的信息包将会</div><div>被截获。</div><div>　　　在表达式中一般如下几种类型的关键字，一种是关于类型的关键字，主要包括host，</div><div>net，port, 例如 host 210.27.48.2，指明 210.27.48.2是一台主机，net 202.0.0.0 指明</div><div>202.0.0.0是一个网络地址，port 23 指明端口号是23。如果没有指定类型，缺省的类型是</div><div>host.</div><div>　　　第二种是确定传输方向的关键字，主要包括src , dst ,dst or src, dst and src ,</div><div>这些关键字指明了传输的方向。举例说明，src 210.27.48.2 ,指明ip包中源地址是210.27.</div><div>48.2 , dst net 202.0.0.0 指明目的网络地址是202.0.0.0 。如果没有指明方向关键字，则</div><div>缺省是src or dst关键字。</div><div>　　　第三种是协议的关键字，主要包括fddi,ip ,arp,rarp,tcp,udp等类型。Fddi指明是在</div><div>FDDI(分布式光纤数据接口网络)上的特定的网络协议，实际上它是"ether"的别名，fddi和e</div><div>ther具有类似的源地址和目的地址，所以可以将fddi协议包当作ether的包进行处理和分析。</div><div>其他的几个关键字就是指明了监听的包的协议内容。如果没有指定任何协议，则tcpdump将会</div><div>监听所有协议的信息包。</div><div>　　　除了这三种类型的关键字之外，其他重要的关键字如下：gateway, broadcast,less,</div><div>greater,还有三种逻辑运算，取非运算是 'not ' '! ', 与运算是'and','&amp;&amp;';或运算 是'o</div><div>r' ,'||'；</div><div>　　　这些关键字可以组合起来构成强大的组合条件来满足人们的需要，下面举几个例子来</div><div>说明。</div><div>　　　(1)想要截获所有210.27.48.1 的主机收到的和发出的所有的数据包：</div><div>　　　　#tcpdump host 210.27.48.1&nbsp;</div><div>　　　(2) 想要截获主机210.27.48.1 和主机210.27.48.2 或210.27.48.3的通信，使用命令</div><div>：（在命令行中适用　　　括号时，一定要</div><div>　　　　#tcpdump host 210.27.48.1 and \ (210.27.48.2 or 210.27.48.3 \)&nbsp;</div><div>　　　(3) 如果想要获取主机210.27.48.1除了和主机210.27.48.2之外所有主机通信的ip包</div><div>，使用命令：</div><div>　　　　#tcpdump ip host 210.27.48.1 and ! 210.27.48.2</div><div>　　　(4)如果想要获取主机210.27.48.1接收或发出的telnet包，使用如下命令：</div><div>　　　　#tcpdump tcp port 23 host 210.27.48.1&nbsp;</div><div></div><div>　　3. tcpdump 的输出结果介绍</div><div>　　　下面我们介绍几种典型的tcpdump命令的输出信息</div><div>　　　(1) 数据链路层头信息</div><div>　　　使用命令#tcpdump --e host ice</div><div>　　　ice 是一台装有linux的主机，她的MAC地址是0：90：27：58：AF：1A</div><div>　　　H219是一台装有SOLARIC的SUN工作站，它的MAC地址是8：0：20：79：5B：46；上一条</div><div>命令的输出结果如下所示：</div><div>21:50:12.847509 eth0 &lt; 8:0:20:79:5b:46 0:90:27:58:af:1a ip 60: h219.33357 &gt; ice.</div><div>telne</div><div>t 0:0(0) ack 22535 win 8760 (DF)</div><div>　　分析：21：50：12是显示的时间， 847509是ID号，eth0 &lt;表示从网络接口eth0 接受该</div><div>数据包，eth0 &gt;表示从网络接口设备发送数据包, 8:0:20:79:5b:46是主机H219的MAC地址,它</div><div>表明是从源地址H219发来的数据包. 0:90:27:58:af:1a是主机ICE的MAC地址,表示该数据包的</div><div>目的地址是ICE . ip 是表明该数据包是IP数据包,60 是数据包的长度, h219.33357 &gt; ice.</div><div>telnet 表明该数据包是从主机H219的33357端口发往主机ICE的TELNET(23)端口. ack 22535</div><div>表明对序列号是222535的包进行响应. win 8760表明发送窗口的大小是8760.</div><div></div><div>　　(2) ARP包的TCPDUMP输出信息</div><div>　　　使用命令#tcpdump arp&nbsp;</div><div>　　　得到的输出结果是：</div><div>　　22:32:42.802509 eth0 &gt; arp who-has route tell ice (0:90:27:58:af:1a)</div><div>　　22:32:42.802902 eth0 &lt; arp reply route is-at 0:90:27:12:10:66 (0:90:27:58:af</div><div>:1a)</div><div>　　分析: 22:32:42是时间戳, 802509是ID号, eth0 &gt;表明从主机发出该数据包, arp表明是</div><div>ARP请求包, who-has route tell ice表明是主机ICE请求主机ROUTE的MAC地址。 0:90:27:5</div><div>8:af:1a是主机ICE的MAC地址。</div><div></div><div>　　(3) TCP包的输出信息</div><div>　　　用TCPDUMP捕获的TCP包的一般输出信息是：</div><div>　　src &gt; dst: flags data-seqno ack window urgent options</div><div>　　src &gt; dst:表明从源地址到目的地址, flags是TCP包中的标志信息,S 是SYN标志, F (F</div><div>IN), P (PUSH) , R (RST) "." (没有标记); data-seqno是数据包中的数据的顺序号, ack是</div><div>下次期望的顺序号, window是接收缓存的窗口大小, urgent表明数据包中是否有紧急指针.&nbsp;</div><div>Options是选项.</div><div></div><div>　　(4) UDP包的输出信息</div><div>　　　用TCPDUMP捕获的UDP包的一般输出信息是：</div><div>　　route.port1 &gt; ice.port2: udp lenth</div><div>　　UDP十分简单，上面的输出行表明从主机ROUTE的port1端口发出的一个UDP数据包到主机</div><div>ICE的port2端口，类型是UDP， 包的长度是lenth&nbsp;<br />=====================================================<br /><div><div id="appShareTitle" style="word-wrap: break-word; height: 24px; line-height: 24px; font-weight: bold; color: #333333; font-family: arial; background-color: #f4f8fb; ">tcpdump抓包分析详解</div><div id="appShareOpt" style="word-wrap: break-word; text-align: right; margin-bottom: 10px; margin-right: 5px; line-height: 24px; font-family: arial; background-color: #f4f8fb; "></div><div id="app-share-content" style="word-wrap: break-word; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #edf1f4; border-right-color: #edf1f4; border-bottom-color: #edf1f4; border-left-color: #edf1f4; border-image: initial; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #f4f8fb; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; color: #9a9a9a; font-size: 12px; font-family: arial; "><div style="word-wrap: break-word; ">說實在的，對於 tcpdump 這個軟體來說，你甚至可以說這個軟體其實就是個駭客軟體， 因為他不但可以分析封包的流向，連封包的內容也可以進行『監聽』， 如果你使用的傳輸資料是明碼的話，不得了，在 router 上面就可能被人家監聽走了！ 很可怕吶！所以，我們也要來瞭解一下這個軟體啊！(註：這個 tcpdump 必須使用 root 的身份執行)<br /><table fck__showtableborders"="" style="border-collapse: collapse; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; "><tbody><tr><td style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><pre>[root@linux ~]# <strong>tcpdump [-nn] [-i 介面] [-w 儲存檔名] [-c 次數] [-Ae]</strong>                 <strong>        [-qX] [-r 檔案] [所欲擷取的資料內容]</strong> 參數： -nn：直接以 IP 及 port number 顯示，而非主機名與服務名稱 -i ：後面接要『監聽』的網路介面，例如 eth0, lo, ppp0 等等的介面； -w ：如果你要將監聽所得的封包資料儲存下來，用這個參數就對了！後面接檔名 -c ：監聽的封包數，如果沒有這個參數， tcpdump 會持續不斷的監聽，      直到使用者輸入 [ctrl]-c 為止。 -A ：封包的內容以 ASCII 顯示，通常用來捉取 WWW 的網頁封包資料。 -e ：使用資料連接層 (OSI 第二層) 的 MAC 封包資料來顯示； -q ：僅列出較為簡短的封包資訊，每一行的內容比較精簡 -X ：可以列出十六進位 (hex) 以及 ASCII 的封包內容，對於監聽封包內容很有用 -r ：從後面接的檔案將封包資料讀出來。那個『檔案』是已經存在的檔案，      並且這個『檔案』是由 -w 所製作出來的。 所欲擷取的資料內容：我們可以專門針對某些通訊協定或者是 IP 來源進行封包擷取，      那就可以簡化輸出的結果，並取得最有用的資訊。常見的表示方法有：      'host foo', 'host 127.0.0.1' ：針對單部主機來進行封包擷取      'net 192.168' ：針對某個網域來進行封包的擷取；      'src host 127.0.0.1' 'dst net 192.168'：同時加上來源(src)或目標(dst)限制      'tcp port 21'：還可以針對通訊協定偵測，如 tcp, udp, arp, ether 等      還可以利用 and 與 or 來進行封包資料的整合顯示呢！  範例一：以 IP 與 port number 捉下 eth0 這個網路卡上的封包，持續 3 秒 [root@linux ~]# <strong>tcpdump -i eth0 -nn</strong> tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes 01:33:40.41 IP 192.168.1.100.22 &gt; 192.168.1.11.1190: P 116:232(116) ack 1 win 9648 01:33:40.41 IP 192.168.1.100.22 &gt; 192.168.1.11.1190: P 232:364(132) ack 1 win 9648 &lt;==按下 [ctrl]-c 之後結束 6680 packets captured              &lt;==捉下來的封包數量 14250 packets received by filter   &lt;==由過濾所得的總封包數量 7512 packets dropped by kernel     &lt;==被核心所丟棄的封包</pre></td></tr></tbody></table>如果你是第一次看 tcpdump 的 man page 時，肯定一個頭兩個大，因為 tcpdump 幾乎都是分析封包的表頭資料，使用者如果沒有簡易的網路封包基礎，要看懂粉難吶！ 所以，至少您得要回到<a style="color: #1463c4; text-decoration: none; ">網路基礎</a>裡面去將 TCP 封包的表頭資料理解理解才好啊！ ^_^！至於那個範例一所產生的輸出範例中，我們可以約略區分為數個欄位， 我們以範例一當中那個特殊字體行來說明一下：<br /><ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: initial; list-style-position: initial; list-style-type: none; ">01:33:40.41：這個是此封包被擷取的時間，『時:分:秒』的單位；</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: initial; list-style-position: initial; list-style-type: none; ">IP：透過的通訊協定是 IP ；</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: initial; list-style-position: initial; list-style-type: none; ">192.168.1.100.22 &gt;&nbsp;：傳送端是 192.168.1.100 這個 IP，而傳送的 port number 為 22，您必須要瞭解的是，那個大於 (&gt;) 的符號指的是封包的傳輸方向喔！</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: initial; list-style-position: initial; list-style-type: none; ">192.168.1.11.1190：接收端的 IP 是 192.168.1.11， 且該主機開啟 port 1190 來接收；</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: initial; list-style-position: initial; list-style-type: none; ">P 116:232(116)：這個封包帶有 PUSH 的資料傳輸標誌， 且傳輸的資料為整體資料的 116~232 byte，所以這個封包帶有 116 bytes 的資料量；</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: initial; list-style-position: initial; list-style-type: none; ">ack 1 win 9648：ACK與 Window size 的相關資料。</li></ul>最簡單的說法，就是該封包是由 192.168.1.100 傳到 192.168.1.11，透過的 port 是由 22 到 1190 ， 且帶有 116 bytes 的資料量，使用的是 PUSH 的旗標，而不是 SYN 之類的主動連線標誌。 呵呵！不容易看的懂吧！所以說，上頭才講請務必到&nbsp;<a style="color: #1463c4; text-decoration: none; ">TCP 表頭資料</a>的部分去瞧一瞧的啊！<br /><br />再來，一個網路狀態很忙的主機上面，你想要取得某部主機對你連線的封包資料而已時， 使用 tcpdump 配合管線命令與正規表示法也可以，不過，畢竟不好捉取！ 我們可以透過 tcpdump 的表示法功能，就能夠輕易的將所需要的資料獨立的取出來。 在上面的範例一當中，我們僅針對 eth0 做監聽，所以整個 eth0 介面上面的資料都會被顯示到螢幕上， 不好分析啊！那麼我們可以簡化嗎？例如只取出 port 21 的連線封包，可以這樣做：<br /><table fck__showtableborders"="" style="border-collapse: collapse; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; "><tbody><tr><td style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><pre>[root@linux ~]# <strong>tcpdump -i eth0 -nn port 21</strong> tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes 01:54:37.96 IP 192.168.1.11.1240 &gt; 192.168.1.100.21: . ack 1 win 65535 01:54:37.96 IP 192.168.1.100.21 &gt; 192.168.1.11.1240: P 1:21(20) ack 1 win 5840 01:54:38.12 IP 192.168.1.11.1240 &gt; 192.168.1.100.21: . ack 21 win 65515 01:54:42.79 IP 192.168.1.11.1240 &gt; 192.168.1.100.21: P 1:17(16) ack 21 win 65515 01:54:42.79 IP 192.168.1.100.21 &gt; 192.168.1.11.1240: . ack 17 win 5840 01:54:42.79 IP 192.168.1.100.21 &gt; 192.168.1.11.1240: P 21:55(34) ack 17 win 5840</pre></td></tr></tbody></table>瞧！這樣就僅提出 port 21 的資訊而已，且仔細看的話，你會發現封包的傳遞都是雙向的， client 端發出『要求』而 server 端則予以『回應』，所以，當然是有去有回啊！ 而我們也就可以經過這個封包的流向來瞭解到封包運作的過程。 舉例來說：<ol style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: none; list-style-position: outside; list-style-type: none; ">我們先在一個終端機視窗輸入『 tcpdump -i lo -nn 』 的監聽，</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: none; list-style-position: outside; list-style-type: none; ">再另開一個終端機視窗來對本機 (127.0.0.1) 登入『ssh localhost』</li></ol>那麼輸出的結果會是如何？<br /><table fck__showtableborders"="" style="border-collapse: collapse; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; "><tbody><tr><td style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><pre>[root@linux ~]# <strong>tcpdump -i lo -nn</strong>  1 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode  2 listening on lo, link-type EN10MB (Ethernet), capture size 96 bytes  3 11:02:54.253777 IP 127.0.0.1.32936 &gt; 127.0.0.1.22: S 933696132:933696132(0)     win 32767 &lt;mss 16396,sackOK,timestamp 236681316 0,nop,wscale 2&gt;  4 11:02:54.253831 IP 127.0.0.1.22 &gt; 127.0.0.1.32936: S 920046702:920046702(0)     ack 933696133 win 32767 &lt;mss 16396,sackOK,timestamp 236681316 236681316,nop,    wscale 2&gt;  5 11:02:54.253871 IP 127.0.0.1.32936 &gt; 127.0.0.1.22: . ack 1 win 8192 &lt;nop,    nop,timestamp 236681316 236681316&gt;  6 11:02:54.272124 IP 127.0.0.1.22 &gt; 127.0.0.1.32936: P 1:23(22) ack 1 win 8192     &lt;nop,nop,timestamp 236681334 236681316&gt;  7 11:02:54.272375 IP 127.0.0.1.32936 &gt; 127.0.0.1.22: . ack 23 win 8192 &lt;nop,    nop,timestamp 236681334 236681334&gt;</pre></td></tr></tbody></table>上表顯示的頭兩行是 tcpdump 的基本說明，然後：<ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: initial; list-style-position: initial; list-style-type: none; ">第 3 行顯示的是『來自 client 端，帶有 SYN 主動連線的封包』，</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: initial; list-style-position: initial; list-style-type: none; ">第 4 行顯示的是『來自 server 端，除了回應 client 端之外(ACK)，還帶有 SYN 主動連線的標誌；</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: initial; list-style-position: initial; list-style-type: none; ">第 5 行則顯示 client 端回應 server 確定連線建立 (ACK)</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-image: initial; list-style-position: initial; list-style-type: none; ">第 6 行以後則開始進入資料傳輸的步驟。</li></ul>從第 3-5 行的流程來看，熟不熟悉啊？沒錯！那就是&nbsp;<a style="color: #1463c4; text-decoration: none; ">三向交握</a>&nbsp;的基礎流程啦！夠有趣吧！ 不過 tcpdump 之所以被稱為駭客軟體之一可不止上頭介紹的功能吶！ 上面介紹的功能可以用來作為我們主機的封包連線與傳輸的流程分析， 這將有助於我們瞭解到封包的運作，同時瞭解到主機的防火牆設定規則是否有需要修訂的地方。<br /><br />更神奇的使用要來啦！如果我們使用 tcpdump 在 router 上面監聽『明碼』的傳輸資料時， 例如 FTP 傳輸協定，你覺得會發生什麼問題呢？ 我們先在主機端下達『 tcpdump -i lo port 21 -nn -X 』然後再以 ftp 登入本機，並輸入帳號與密碼， 結果你就可以發現如下的狀況：<br /><table fck__showtableborders"="" style="border-collapse: collapse; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; "><tbody><tr><td style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><pre>[root@linux ~]# <strong>tcpdump -i lo -nn -X 'port 21'</strong>     0x0000:  4500 0048 2a28 4000 4006 1286 7f00 0001  E..H*(@.@.......     0x0010:  7f00 0001 0015 80ab 8355 2149 835c d825  .........U!I.\.%     0x0020:  8018 2000 fe3c 0000 0101 080a 0e2e 0b67  .....&lt;.........g     0x0030:  0e2e 0b61 3232 3020 2876 7346 5450 6420  ...a220.(vsFTPd.     0x0040:  322e 302e 3129 0d0a                      2.0.1)..      0x0000:  4510 0041 d34b 4000 4006 6959 7f00 0001  E..A.K@.@.iY....     0x0010:  7f00 0001 80ab 0015 835c d825 8355 215d  .........\.%.U!]     0x0020:  8018 2000 fe35 0000 0101 080a 0e2e 1b37  .....5.........7     0x0030:  0e2e 0b67 5553 4552 2064 6d74 7361 690d  ...gUSER.dmtsai.     0x0040:  0a                                       .      0x0000:  4510 004a d34f 4000 4006 694c 7f00 0001  E..J.O@.@.iL....     0x0010:  7f00 0001 80ab 0015 835c d832 8355 217f  .........\.2.U!.     0x0020:  8018 2000 fe3e 0000 0101 080a 0e2e 3227  .....&gt;........2'     0x0030:  0e2e 1b38 5041 5353 206d 7970 6173 7377  ...8PASS.mypassw     0x0040:  6f72 6469 7379 6f75 0d0a                 ordisyou..</pre></td></tr></tbody></table>上面的輸出結果已經被簡化過了，你必須要自行在你的輸出結果當中搜尋相關的字串才行。 從上面輸出結果的特殊字體中，我們可以發現『該 FTP 軟體使用的是 vsftpd ，並且使用者輸入 dmtsai 這個帳號名稱，且密碼是 mypasswordisyou』 嘿嘿！你說可不可怕啊！如果使用的是明碼的方式來傳輸你的網路資料？ 所以我們才常常在講啊，網路是很不安全低！<br /><br />另外你得瞭解，為了讓網路介面可以讓 tcpdump 監聽，所以執行 tcpdump 時網路介面會啟動在 『錯亂模式 (promiscuous)』，所以你會在 /var/log/messages 裡面看到很多的警告訊息， 通知你說你的網路卡被設定成為錯亂模式！別擔心，那是正常的。 至於更多的應用，請參考 man tcpdump 囉！<br /><br /><table cellspacing="0" cellpadding="5" width="90%" border="1" style="border-collapse: collapse; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; "><tbody><tr><td style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">例題：如何使用 tcpdump 監聽 (1)來自 eth0 介面卡且 (2)通訊協定為 port 22 ，(3)目標來源為 192.168.1.100 的封包資料？<br /><br />答：<ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; ">tcpdump -i eth0 -nn 'port 22 and src host 192.168.1.100'</ul></td></tr></tbody></table></div><hr /><a name="ethereal" style="color: rgb(20, 99, 196); text-decoration: none; "></a><img height="23" alt="小標題的圖示" width="16" align="middle" src="http://linux.vbird.org/images/penguin-s.gif" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; " /><strong>ethereal<br /></strong><div style="word-wrap: break-word; ">除了 tcpdump 這個軟體之外，其實你還可以使用 ethereal 這個好用的網路流量分析軟體吶！ ethereal 分為文字介面與圖形介面，文字介面的用法與 tcpdump 相當的類似，不過他的指令名稱為 tethereal 就是了。因為用法差不多，所以建議您直接使用 man tethereal 查閱吧！ 在 CentOS 上原本就有 ethereal 了，所以請拿出光碟來安裝即可喔！ 需要安裝 ethereal 與 ethereal-gnome 才行吶！<br /><br />啟動的方法很簡單，你必須要在 X Window 底下，先開啟一個終端機，然後直接輸入 ethereal 後， 就會出現如下的畫面了：<br /><br /><center><img title="ethereal 使用範例圖" alt="ethereal 使用範例圖" src="http://linux.vbird.org/linux_server/0140networkcommand/ethereal_1.jpg" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; " /><br />圖五、ethereal 使用範例圖</center><br />簡單的作法，你可以點選如上圖顯示的那個按鈕，會出現挑選監聽的介面視窗，如下所示：<br /><br /><center><img title="ethereal 使用範例圖" alt="ethereal 使用範例圖" src="http://linux.vbird.org/linux_server/0140networkcommand/ethereal_2.jpg" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; " /><br />圖六、ethereal 使用範例圖</center><br />你應該選擇要監聽的介面，在這裡因為是測試用的，所以鳥哥使用的是 lo 這個內部介面， 你當然應該要選擇你自己的網路介面才是。然後按下 start 後，就會出現開始偵測的畫面了：<br /><br /><center><img title="ethereal 使用範例圖" alt="ethereal 使用範例圖" src="http://linux.vbird.org/linux_server/0140networkcommand/ethereal_3.jpg" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; " /><br />圖七、ethereal 使用範例圖</center><br />在這個畫面當中你可以看到很多類型的封包協定，在等你處理完畢後，就可以按下『stop』結束監聽， 而開始進入如下的封包分析畫面。<br /><br /><center><img title="ethereal 使用範例圖" alt="ethereal 使用範例圖" src="http://linux.vbird.org/linux_server/0140networkcommand/ethereal_4.jpg" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; " /><br />圖八、ethereal 使用範例圖</center><br />封包分析畫面共分為三大區塊，如上圖所示，第一區塊主要顯示的是封包的標頭資料， 內容就有點類似 tcpdump 的顯示結果，第二區塊則是詳細的表頭資料， 包括訊框的內容、通訊協定的內容以及 socket pair 等等資訊。 第三區塊則是 16 進位與 ASCII 碼的顯示結果。透過這個 ethereal 您就可以一口氣得到所需要的所有封包內容啦！ 而且還是圖形介面的，很方便吧！透過在第一區塊選擇不同的封包，就能夠查閱每個封包的資料內容囉！</div><hr /><a name="nc" style="color: rgb(20, 99, 196); text-decoration: none; "></a><img height="23" alt="小標題的圖示" width="16" align="middle" src="http://linux.vbird.org/images/penguin-s.gif" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; " /><strong>nc, netcat<br /></strong><div style="word-wrap: break-word; ">這個 nc 可以用來作為某些服務的檢測，因為他可以連接到某個 port 來進行溝通， 此外，還可以自行啟動一個 port 來傾聽其他用戶的連線吶！非常的不錯用！ 如果在編譯的時候給予『GAPING_SECURITY_HOLE』參數的話，嘿嘿！ 這個軟體還可以用來取得用戶端的 bash 哩！可怕吧！我們的 CentOS 比較人性化，並沒有給予上面的參數，所以我們不能夠用來作為駭客軟體～ 但是用來取代 telnet 也是個很棒的功能了！(有的系統將執行檔改名為 netcat 啦！)<br /><table fck__showtableborders"="" style="border-collapse: collapse; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; "><tbody><tr><td style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><pre>[root@linux ~]# <strong>nc [IP|host] [port]</strong> [root@linux ~]# <strong>nc -l -p [port]</strong> 參數： -l ：作為監聽之用，亦即開啟一個 port 來監聽用戶的連線； -p ：開啟的這個 port number  範例一：連接本地端的 port 25 查閱相關訊息 [root@linux ~]# <strong>nc localhost 25</strong> localhost.localdomain [127.0.0.1] 25 (smtp) open 220 pc.dm.tsai ESMTP Postfix <strong>ehlo localhost</strong> 250-pc.dm.tsai 250-PIPELINING 250-SIZE 40000000 250-ETRN <strong>quit</strong> 221 Bye</pre></td></tr></tbody></table>這個最簡單的功能與 telnet 幾乎一樣吧！可以去檢查某個服務啦！不過，更神奇的在後面， 我們可以建立兩個連線來傳訊喔！舉個例子來說，我們先在 client 端的地方啟動一個 port 來進行傾聽：<br /><table fck__showtableborders"="" style="border-collapse: collapse; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; "><tbody><tr><td style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><pre>範例二：啟動一個 port 來監聽使用者的連線要求 [root@linux ~]# <strong>nc -l -p 20000</strong> # 啟動一個 port 20000  在主機上，如果此時使用 netstat -tlnp  # 就可以看到系統上多出來一個 port 20000 在傾聽使用者的連線喔！</pre></td></tr></tbody></table>然後在主機端的地方，也利用 nc 來連線到用戶端，並且輸入一些指令看看喔！<br /><table fck__showtableborders"="" style="border-collapse: collapse; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; "><tbody><tr><td style="word-wrap: break-word; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><pre>[root@linux ~]# <strong>nc localhost 20000</strong>    &lt;==這裡可以開始輸入字串了！</pre></td></tr></tbody></table>此時，在主機端我們可以打入一些字，你會發現在 client 端會同時出現你輸入的字眼吶！ 如果你同時給予一些額外的參數，例如利用標準輸入與輸出 (stdout, stdin) 的話， 那麼就可以透過這個連線來作很多事情了！ 當然 nc 的功能不只如此，你還可以發現很多的用途喔！ 請自行到您主機內的 /usr/share/doc/nc-1.10/scripts 目錄下看看這些 script ，有幫助的吶！ 不過，如果你需要額外的編譯出含有 GAPING_SECURITY_HOLE 功能， 以使兩端</div></div><div id="appShareUrl" style="word-wrap: break-word; font-size: 12px; color: #999999; margin-top: 10px; border-top-width: 1px; border-top-style: solid; border-top-color: #f4f4f4; font-family: arial; background-color: #f4f8fb; clear: both; ">来自:&nbsp;<a href="http://hi.baidu.com/june2june/blog/item/84a66865ea77acf8f73654ea.html" target="_blank" style="color: #9a9a9a; text-decoration: none; ">http://hi.baidu.com/june2june/blog/item/84a66865ea77acf8f73654ea.html</a></div></div></div></div><img src ="http://www.blogjava.net/Todd/aggbug/369460.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Todd/" target="_blank">Todd</a> 2012-02-06 10:38 <a href="http://www.blogjava.net/Todd/archive/2012/02/06/369460.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mysql root 密码</title><link>http://www.blogjava.net/Todd/archive/2011/12/13/366196.html</link><dc:creator>Todd</dc:creator><author>Todd</author><pubDate>Mon, 12 Dec 2011 19:18:00 GMT</pubDate><guid>http://www.blogjava.net/Todd/archive/2011/12/13/366196.html</guid><wfw:comment>http://www.blogjava.net/Todd/comments/366196.html</wfw:comment><comments>http://www.blogjava.net/Todd/archive/2011/12/13/366196.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Todd/comments/commentRss/366196.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Todd/services/trackbacks/366196.html</trackback:ping><description><![CDATA[mysql&gt;SET PASSWORD FOR 'root'@'localhost' = PASSWORD('rootpwd'); <img src ="http://www.blogjava.net/Todd/aggbug/366196.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Todd/" target="_blank">Todd</a> 2011-12-13 03:18 <a href="http://www.blogjava.net/Todd/archive/2011/12/13/366196.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>java heap space， PermGen space 错误 使用jvisualvm监测设置合理值</title><link>http://www.blogjava.net/Todd/archive/2011/10/18/361543.html</link><dc:creator>Todd</dc:creator><author>Todd</author><pubDate>Tue, 18 Oct 2011 14:16:00 GMT</pubDate><guid>http://www.blogjava.net/Todd/archive/2011/10/18/361543.html</guid><wfw:comment>http://www.blogjava.net/Todd/comments/361543.html</wfw:comment><comments>http://www.blogjava.net/Todd/archive/2011/10/18/361543.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/Todd/comments/commentRss/361543.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Todd/services/trackbacks/361543.html</trackback:ping><description><![CDATA[使用myeclipse启动tomcat 报java heap space ，PermGen space 错误，分别为 heap内存不足，PermGen内存不足<br />需加大 tomcat启动项参数 Xmx 和&nbsp;XX:MaxPermSize<br />PermGen是指内存的永久保存区域，它用于存放class和 method 对象，以及String 对象<br />（sun原文：permanent generation is the area of the heap where class and method objects are stored. If an application loads a very large number of classes, then the size of the permanent generation might need to be increased using the -XX:MaxPermSize option. 
<div>Interned java.lang.String objects are also stored in the permanent generation. The java.lang.String class maintains a pool of strings. When the intern method is invoked, the method checks the pool to see if an equal string is already in the pool. If there is, then the intern method returns it; otherwise it adds the string to the pool. In more precise terms, the java.lang.String.intern method is used to obtain the canonical representation of the string; the result is a reference to the same class instance that would be returned if that string appeared as a literal. If an application interns a huge number of strings, the permanent generation might need to be increased from its default setting. </div>
<div>When this kind of error occurs, the text String.intern or ClassLoader.defineClass might appear near the top of the stack trace that is printed. </div>
<div>The jmap -permgen command prints statistics for the objects in the permanent generation, including information about internalized String instances. See 2.6.4 Getting Information on the Permanent Generation.</div>）<br />PermGen又是一个特殊内存区域：Classloader 加载的东东是不能回收的，它们放在PermGen中<br />（tomcat原文：Why does the memory usage increase when I redeploy a web application? Because the Classloader (and the Class objects it loaded) cannot be recycled. They are stored in the permanent heap generation by the JVM, and when you redepoy a new class loader is created, which loads another copy of all these classes. This can cause OufOfMemoryErrors eventually.）<br /><br />回到我的问题来，打开%java_home%bin\jvisualvm.exe&nbsp; (jdk6以上有)<br />查看tomcat的内存情况，点击tomcat标签下monitor , 当used heap&nbsp;= max heap&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; used PermGen = max PermGen 时tomcat还在启动中，一会就报错；<br />由于此前已经将myeclipse中server-&gt;tomcat-&gt;tomcatx.x-&gt;jdk的参数设置成-Xms64m -Xmx512m -XX:MaxPermSize=80m<br />但是monitor 画面中max heap为 256M<br />点击overview标签,发现jvm参数如下：<br />-Xms64m<br />-Xmx512m<br />-XX:MaxPermSize=80m<br />-Xms64m<br />-Xmx256m<br /><br />显然tomcat使用了最后的设置-Xms64m -Xmx256m；这个是在myeclipse的属性-》java-&gt;installed jres 中的vm启动参数里，双击默认启用的jre，把参数去掉或者设置成-Xms64m -Xmx512m<br />再回到server-&gt;tomcat-&gt;tomcatx.x-&gt;jdk中把-XX:MaxPermSize=80m修改为-XX:MaxPermSize=128m<br />保存后再启动tomcat，ok<br /><br />另外，使用jvisualvm持续监测tomcat内存情况发现heap区域的内存使用会在一个高峰后稳定降低，内存被回收了；<br />而PermGen区域的内存则是不断增加到达一个峰值后就不再增加，但之后此区的内存没有被回收，验证了上面的说法；<br /><br />多说两句：java的动态加载衍生出诸多框架，在空间上也暴露出问题，反射在时间上也存在效率问题：下面是组测试数据：<br />
<p>Java version 1.6.0_13<br />Java HotSpot(TM) Client VM<br />11.3-b02<br />Sun Microsystems Inc.</p>
<p>Direct access using member field:<br />&nbsp;47 125 47 46 46<br />&nbsp;average time = 66 ms.<br />Reference access to member field:<br />&nbsp;109 109 110 94 109<br />&nbsp;average time = 106 ms.<br />Reflection access to member field:<br />&nbsp;13094 12984 13063 13062 13094<br />&nbsp;average time = 13051 ms.</p>
<p>Java version 1.6.0_13<br />Java HotSpot(TM) Client VM<br />11.3-b02<br />Sun Microsystems Inc.</p>
<p>Direct call using member field:<br />&nbsp;47 31 109 109 31<br />&nbsp;average time = 70 ms.<br />Direct call using passed value:<br />&nbsp;16 16 16 31 15<br />&nbsp;average time = 20 ms.<br />Call to object using member field:<br />&nbsp;46 47 47 47 32<br />&nbsp;average time = 43 ms.<br />Call to object using passed value:<br />&nbsp;15 16 31 16 16<br />&nbsp;average time = 20 ms.<br />Reflection call using member field:<br />&nbsp;812 782 844 844 844<br />&nbsp;average time = 829 ms.<br />Reflection call using passed value:<br />&nbsp;938 953 954 1031 953<br />&nbsp;average time = 973 ms.</p>
<p>Java version 1.6.0_13<br />Java HotSpot(TM) Client VM<br />11.3-b02<br />Sun Microsystems Inc.</p>
<p>Direct Object creation:<br />&nbsp;62 47 78 32 93<br />&nbsp;average time = 63 ms.<br />Reflection Object creation:<br />&nbsp;125 94 94 109 187<br />&nbsp;average time = 121 ms.<br />Direct byte[8] creation:<br />&nbsp;125 187 94 172 94<br />&nbsp;average time = 137 ms.<br />Reflection byte[8] creation:<br />&nbsp;266 171 187 188 219<br />&nbsp;average time = 191 ms.<br />Direct byte[64] creation:<br />&nbsp;250 172 156 125 203<br />&nbsp;average time = 164 ms.<br />Reflection byte[64] creation:<br />&nbsp;281 219 203 203 219<br />&nbsp;average time = 211 ms.</p>华丽的上层需要坚实的底层基础<br /><br /><a href="http://wiki.apache.org/tomcat/FAQ/Deployment">http://wiki.apache.org/tomcat/FAQ/Deployment</a><br /><a href="http://download.oracle.com/javase/7/docs/webnotes/tsg/TSG-VM/html/memleaks.html#gbyuu">http://download.oracle.com/javase/7/docs/webnotes/tsg/TSG-VM/html/memleaks.html#gbyuu</a><br /><br /><img src ="http://www.blogjava.net/Todd/aggbug/361543.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Todd/" target="_blank">Todd</a> 2011-10-18 22:16 <a href="http://www.blogjava.net/Todd/archive/2011/10/18/361543.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>java反射效率测试 jdk6</title><link>http://www.blogjava.net/Todd/archive/2011/09/22/359221.html</link><dc:creator>Todd</dc:creator><author>Todd</author><pubDate>Wed, 21 Sep 2011 23:18:00 GMT</pubDate><guid>http://www.blogjava.net/Todd/archive/2011/09/22/359221.html</guid><wfw:comment>http://www.blogjava.net/Todd/comments/359221.html</wfw:comment><comments>http://www.blogjava.net/Todd/archive/2011/09/22/359221.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Todd/comments/commentRss/359221.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Todd/services/trackbacks/359221.html</trackback:ping><description><![CDATA[<div><p>Java version 1.6.0_13<br /> Java HotSpot(TM) Client VM<br /> 11.3-b02<br /> Sun Microsystems Inc.</p> <p>Direct access using member field:<br /> &nbsp;47 125 47 46 46<br /> &nbsp;average time = 66 ms.<br /> Reference access to member field:<br /> &nbsp;109 109 110 94 109<br /> &nbsp;average time = 106 ms.<br /> Reflection access to member field:<br /> &nbsp;13094 12984 13063 13062 13094<br /> &nbsp;average time = 13051 ms.</p> <p>Java version 1.6.0_13<br /> Java HotSpot(TM) Client VM<br /> 11.3-b02<br /> Sun Microsystems Inc.</p> <p>Direct call using member field:<br /> &nbsp;47 31 109 109 31<br /> &nbsp;average time = 70 ms.<br /> Direct call using passed value:<br /> &nbsp;16 16 16 31 15<br /> &nbsp;average time = 20 ms.<br /> Call to object using member field:<br /> &nbsp;46 47 47 47 32<br /> &nbsp;average time = 43 ms.<br /> Call to object using passed value:<br /> &nbsp;15 16 31 16 16<br /> &nbsp;average time = 20 ms.<br /> Reflection call using member field:<br /> &nbsp;812 782 844 844 844<br /> &nbsp;average time = 829 ms.<br /> Reflection call using passed value:<br /> &nbsp;938 953 954 1031 953<br /> &nbsp;average time = 973 ms.</p> <p>Java version 1.6.0_13<br /> Java HotSpot(TM) Client VM<br /> 11.3-b02<br /> Sun Microsystems Inc.</p> <p>Direct Object creation:<br /> &nbsp;62 47 78 32 93<br /> &nbsp;average time = 63 ms.<br /> Reflection Object creation:<br /> &nbsp;125 94 94 109 187<br /> &nbsp;average time = 121 ms.<br /> Direct byte[8] creation:<br /> &nbsp;125 187 94 172 94<br /> &nbsp;average time = 137 ms.<br /> Reflection byte[8] creation:<br /> &nbsp;266 171 187 188 219<br /> &nbsp;average time = 191 ms.<br /> Direct byte[64] creation:<br /> &nbsp;250 172 156 125 203<br /> &nbsp;average time = 164 ms.<br /> Reflection byte[64] creation:<br /> &nbsp;281 219 203 203 219<br /> &nbsp;average time = 211 ms.</p> <p>&nbsp;</p></div><img src ="http://www.blogjava.net/Todd/aggbug/359221.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Todd/" target="_blank">Todd</a> 2011-09-22 07:18 <a href="http://www.blogjava.net/Todd/archive/2011/09/22/359221.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>