??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲大尺度无码无码专线一区,好看的亚洲黄色经典,亚洲AV无码专区在线观看成人http://www.tkk7.com/czihong/zh-cnSun, 11 May 2025 15:56:12 GMTSun, 11 May 2025 15:56:12 GMT60SPARK环境搭徏-WINDOWS版本http://www.tkk7.com/czihong/articles/409866.htmlChan ChenChan ChenFri, 14 Feb 2014 08:21:00 GMThttp://www.tkk7.com/czihong/articles/409866.htmlhttp://www.tkk7.com/czihong/comments/409866.htmlhttp://www.tkk7.com/czihong/articles/409866.html#Feedback0http://www.tkk7.com/czihong/comments/commentRss/409866.htmlhttp://www.tkk7.com/czihong/services/trackbacks/409866.htmlSpark环境搭徏-WIndows版本

q段旉在看Scala语言斚w的资料,接触CSparkQ于是昨天下午在公司Q把Spark的环境搭v来了。安装的时候陪C一个问题,在网上没有找到解x案,于是自己查了一下原因。现在做一下笔记?br />
1. spark的下载文件可以在官方扑ֈQ地址Qhttp://spark.incubator.apache.org/downloads.html Q这ơ装的是截至目前为止Q最新的版本Q?.9

2. 下蝲完以后,直接解压到指定的路径Q例如,dQ?programs

3. 安装scalaQƈ制定Scala_Home路径Qscala安装h看官|?br />
4. 按照Spark官方的安装指南,在解压的目录下,q行

sbt/sbt package

命o可以?br />
但是q是针对linux和OS Xpȝ的,在windows下运行这条命令,会报错:

not a valid command

q个问题是因为,spark知道的sbt脚本无法在windows下运行,只要在网上下载一个windows版本的sbtQ然后将里面的文件拷贝到Spark目录下的sbt Qhttp://www.scala-sbt.org/Q,然后在运行命令,安装׃成功?br />
 
试试spark-shell
 1 scala> val textFile = sc.textFile("README.md")
 2 14/02/14 16:38:12 INFO MemoryStore: ensureFreeSpace(35480) called with curMem=177376, maxMem=308713881
 3 14/02/14 16:38:12 INFO MemoryStore: Block broadcast_5 stored as values to memory (estimated size 34.6 KB, free 294.2 MB)
 4 
 5 textFile: org.apache.spark.rdd.RDD[String] = MappedRDD[16] at textFile at <console>:12
 6 
 7 scala> textFile.count
 8 14/02/14 16:38:14 INFO FileInputFormat: Total input paths to process : 1
 9 14/02/14 16:38:14 INFO SparkContext: Starting job: count at <console>:15
10 14/02/14 16:38:14 INFO DAGScheduler: Got job 7 (count at <console>:15) with 1 output partitions (allowLocal=false)
11 14/02/14 16:38:14 INFO DAGScheduler: Final stage: Stage 7 (count at <console>:15)
12 14/02/14 16:38:14 INFO DAGScheduler: Parents of final stage: List()
13 14/02/14 16:38:14 INFO DAGScheduler: Missing parents: List()
14 14/02/14 16:38:14 INFO DAGScheduler: Submitting Stage 7 (MappedRDD[16] at textFile at <console>:12), which has no missin
15 g parents
16 14/02/14 16:38:14 INFO DAGScheduler: Submitting 1 missing tasks from Stage 7 (MappedRDD[16] at textFile at <console>:12)
17 
18 14/02/14 16:38:14 INFO TaskSchedulerImpl: Adding task set 7.0 with 1 tasks
19 14/02/14 16:38:14 INFO TaskSetManager: Starting task 7.0:0 as TID 5 on executor localhost: localhost (PROCESS_LOCAL)
20 14/02/14 16:38:14 INFO TaskSetManager: Serialized task 7.0:0 as 1560 bytes in 1 ms
21 14/02/14 16:38:14 INFO Executor: Running task ID 5
22 14/02/14 16:38:14 INFO BlockManager: Found block broadcast_5 locally
23 14/02/14 16:38:14 INFO HadoopRDD: Input split: file:/D:/program/spark-0.9.0-incubating/README.md:0+4491
24 14/02/14 16:38:14 INFO Executor: Serialized size of result for 5 is 563
25 14/02/14 16:38:14 INFO Executor: Sending result for 5 directly to driver
26 14/02/14 16:38:14 INFO Executor: Finished task ID 5
27 14/02/14 16:38:14 INFO TaskSetManager: Finished TID 5 in 6 ms on localhost (progress: 0/1)
28 14/02/14 16:38:14 INFO DAGScheduler: Completed ResultTask(70)
29 14/02/14 16:38:14 INFO TaskSchedulerImpl: Remove TaskSet 7.0 from pool
30 14/02/14 16:38:14 INFO DAGScheduler: Stage 7 (count at <console>:15) finished in 0.009 s
31 14/02/14 16:38:14 INFO SparkContext: Job finished: count at <console>:15, took 0.012329265 s
32 res10: Long = 119
33 
34 scala> textFile.first
35 14/02/14 16:38:24 INFO SparkContext: Starting job: first at <console>:15
36 14/02/14 16:38:24 INFO DAGScheduler: Got job 8 (first at <console>:15) with 1 output partitions (allowLocal=true)
37 14/02/14 16:38:24 INFO DAGScheduler: Final stage: Stage 8 (first at <console>:15)
38 14/02/14 16:38:24 INFO DAGScheduler: Parents of final stage: List()
39 14/02/14 16:38:24 INFO DAGScheduler: Missing parents: List()
40 14/02/14 16:38:24 INFO DAGScheduler: Computing the requested partition locally
41 14/02/14 16:38:24 INFO HadoopRDD: Input split: file:/D:/program/spark-0.9.0-incubating/README.md:0+4491
42 14/02/14 16:38:24 INFO SparkContext: Job finished: first at <console>:15, took 0.002671379 s
43 res11: String = # Apache Spark
44 
45 scala> val linesWithSpark = textFile.filter(line => line.contains("Spark"))
46 linesWithSpark: org.apache.spark.rdd.RDD[String] = FilteredRDD[17] at filter at <console>:14
47 
48 scala> textFile.filter(line=> line.contains("spark")).count
49 14/02/14 16:38:37 INFO SparkContext: Starting job: count at <console>:15
50 14/02/14 16:38:37 INFO DAGScheduler: Got job 9 (count at <console>:15) with 1 output partitions (allowLocal=false)
51 14/02/14 16:38:37 INFO DAGScheduler: Final stage: Stage 9 (count at <console>:15)
52 14/02/14 16:38:37 INFO DAGScheduler: Parents of final stage: List()
53 14/02/14 16:38:37 INFO DAGScheduler: Missing parents: List()
54 14/02/14 16:38:37 INFO DAGScheduler: Submitting Stage 9 (FilteredRDD[18] at filter at <console>:15), which has no missin
55 g parents
56 14/02/14 16:38:37 INFO DAGScheduler: Submitting 1 missing tasks from Stage 9 (FilteredRDD[18] at filter at <console>:15)
57 
58 14/02/14 16:38:37 INFO TaskSchedulerImpl: Adding task set 9.0 with 1 tasks
59 14/02/14 16:38:37 INFO TaskSetManager: Starting task 9.0:0 as TID 6 on executor localhost: localhost (PROCESS_LOCAL)
60 14/02/14 16:38:37 INFO TaskSetManager: Serialized task 9.0:0 as 1642 bytes in 0 ms
61 14/02/14 16:38:37 INFO Executor: Running task ID 6
62 14/02/14 16:38:37 INFO BlockManager: Found block broadcast_5 locally
63 14/02/14 16:38:37 INFO HadoopRDD: Input split: file:/D:/program/spark-0.9.0-incubating/README.md:0+4491
64 14/02/14 16:38:37 INFO Executor: Serialized size of result for 6 is 563
65 14/02/14 16:38:37 INFO Executor: Sending result for 6 directly to driver
66 14/02/14 16:38:37 INFO Executor: Finished task ID 6
67 14/02/14 16:38:37 INFO TaskSetManager: Finished TID 6 in 10 ms on localhost (progress: 0/1)
68 14/02/14 16:38:37 INFO DAGScheduler: Completed ResultTask(90)
69 14/02/14 16:38:37 INFO TaskSchedulerImpl: Remove TaskSet 9.0 from pool
70 14/02/14 16:38:37 INFO DAGScheduler: Stage 9 (count at <console>:15) finished in 0.010 s
71 14/02/14 16:38:37 INFO SparkContext: Job finished: count at <console>:15, took 0.020335125 s
72 res12: Long = 7

另外Spark官网提供了入门的四段视频Q但是国内被墙了Q无法观看youtubeQ我把这四段视频攑ֈ了土豆网Q大家可以看看?br />
Spark Screencast 1 – 搭徏Spark环境

Spark Screencast 2 – Spark文总览

Spark Screencast 3 – 转换和缓?/a>

Spark Screencast 4 – Scala独立d

Chan Chen 2014-02-14 16:21 发表评论
]]>
top命o的Load average 含义及性能参考基?/title><link>http://www.tkk7.com/czihong/articles/399670.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Thu, 23 May 2013 09:47:00 GMT</pubDate><guid>http://www.tkk7.com/czihong/articles/399670.html</guid><wfw:comment>http://www.tkk7.com/czihong/comments/399670.html</wfw:comment><comments>http://www.tkk7.com/czihong/articles/399670.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/czihong/comments/commentRss/399670.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/czihong/services/trackbacks/399670.html</trackback:ping><description><![CDATA[<div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"><pre style="word-wrap: break-word; margin-top: 0px; margin-bottom: 0px; padding: 0px;"><code style="word-wrap: break-word;">$ uptime<br style="word-wrap: break-word;" />11:12:26 up 3:44, 4 users, load average: 0.38, 0.31, 0.19<br style="word-wrap: break-word;" /></code></pre><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px;">pȝq_负蝲被定义ؓ在特定时间间隔内q行队列中的q_q程树。如果一个进E满以下条件则其就会位于运行队列中Q?/p><ul style="word-wrap: break-word; margin: 0px; padding: 0px; list-style: none;"><li style="word-wrap: break-word; margin: 0px; padding: 0px; list-style: disc outside;">它没有在{待I/O操作的结?/li><li style="word-wrap: break-word; margin: 0px; padding: 0px; list-style: disc outside;">它没有主动进入等待状?也就是没有调?wait')</li><li style="word-wrap: break-word; margin: 0px; padding: 0px; list-style: disc outside;">没有被停?例如Q等待终?</li></ul><p style="word-wrap: break-word; margin-right: 0px; margin-left: 0px; padding: 0px;">上面的输出,load average后面分别?分钟?分钟?5分钟的负载情c数据是每隔5U钟查一ơ活跃的q程敎ͼ然后Ҏq个数值算出来的。如果这个数除以CPU 的数目,l果高于5的时候就表明pȝ在超负荷q{了?/p></div><br style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;" /><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;"> </div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">LinuxpȝLoad average负蝲详细解释   我们知道判断一个系l的负蝲可以使用topQuptime{命令去查看Q它分别记录了一分钟、五分钟、以及十五分钟的pȝq_负蝲</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  例如我的某台服务器:</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  $ uptime</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  09:50:21 up 200 days, 15:07, 1 user, load average: 0.27, 0.33, 0.37</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  大部分的人都认ؓq个数字小好Q其实有很多兌的提CZ息,今天看到q个好文Q应该可以给大家说清楚很多问题,转一下:</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  原文链接Q?nbsp;<a style="word-wrap: break-word; text-decoration: none; color: #565656;">http://blog.scoutapp.com/articles/2009/07/31/understanding-load-averages</a></div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  你可能对?Linux 的负载均|load averagesQ已有了充分的了解。负载均值在 uptime 或?top 命o中可以看刎ͼ它们可能会显C成q个样子Q?/div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  load average: 0.09, 0.05, 0.01</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  很多Zq样理解负蝲均|三个数分别代表不同时间段的系l^均负载(一分钟、五 分钟、以及十五分钟)Q它们的数字当然是越越好。数字越高,说明服务器的负蝲?大,q也可能是服务器出现某种问题的信受?/div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  而事实不完全如此Q是什么因素构成了负蝲均值的大小Q以及如何区分它们目前的状况?“?#8221;q是“p糕”Q什么时候应该注意哪些不正常的数|</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  回答q些问题之前Q首先需要了解下q些数D后的些知识。我们先用最单的例子说明Q?一台只配备一块单核处理器的服务器?/div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  行Rq桥</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  一只单核的处理器可以Ş象得比喻成一条单车道。设想下Q你现在需要收取这条道路的q桥 ?— 忙于处理那些要q桥的R辆。你首先当然需要了解些信息Q例如R辆的载重、以?q有多少车辆正在{待q桥。如果前面没有R辆在{待Q那么你可以告诉后面的司机通过?如果车辆众多Q那么需要告知他们可能需要稍{一会?/div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  因此Q需要些特定的代可C目前的车流情况Q例如:</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  0.00 表示目前桥面上没有Q何的车流?实际上这U情况与 0.00 ?1.00 之间是相同的Q总而言之很通畅Q过往的R辆可以丝毫不用等待的通过?/div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  1.00 表示刚好是在q桥的承受范围内?q种情况不算p糕Q只是R会有些堵,不过q种情况可能会造成交通越来越慢?/div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  过 1.00Q那么说明这座桥已经出负荷Q交通严重的拥堵?那么情况有多p糕Q?例如 2.00 的情况说明R已l超Z桥所能承受的一倍,那么有多余q桥一倍的车辆正在焦急的{待?.00 的话情况更不妙了,说明q桥基本上已经快承受不了,q有出桥负载两倍多的R辆正在等待?/div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  上面的情况和处理器的负蝲情况非常怼。一辆汽车的q桥旉好比是处理器处理某U程 的实际时间。Unix pȝ定义的进E运行时长ؓ所有处理器内核的处理时间加上线E?在队列中{待的时间?/div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  和收q桥费的理员一P你当然希望你的汽车(操作Q不会被焦急的{待。所以,理想状?下,都希望负载^均值小?1.00 。当然不排除部分峰g过 1.00Q但长此以往保持q?个状态,p明会有问题,q时候你应该会很焦急?/div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  “所以你说的理想负荷?1.00 Q?#8221;</div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  嗯,q种情况其实q不完全正确。负?1.00 说明pȝ已经没有剩余的资源了。在实际情况?Q有l验的系l管理员都会这条线划在 0.70Q?/div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  “需要进行调查法?#8221;Q?如果长期你的pȝ负蝲?0.70 上下Q那么你需要在事情变得更糟p之前,׃旉了解其原因?/div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  “现在p修复法则”Q?.00 ?如果你的服务器系l负载长期徘徊于 1.00Q那么就应该马上解决q个问题。否则,你将半夜接到你上司的电话Q这可不是g令h愉快的事情?/div><div style="word-wrap: break-word; color: #666666; font-family: 宋体, Arial; font-size: 12px; line-height: 26px; background-color: #ffffff;">  “凌晨三点半锻Dn体法?#8221;Q?.00?如果你的服务器负载超q了 5.00 q个数字Q那么你失M的睡眠,q得在会议中说明q情况发生的原因QM千万不要让它发生?/div><img src ="http://www.tkk7.com/czihong/aggbug/399670.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/czihong/" target="_blank">Chan Chen</a> 2013-05-23 17:47 <a href="http://www.tkk7.com/czihong/articles/399670.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java CyclicBarrier介绍http://www.tkk7.com/czihong/articles/399587.htmlChan ChenChan ChenWed, 22 May 2013 01:57:00 GMThttp://www.tkk7.com/czihong/articles/399587.htmlhttp://www.tkk7.com/czihong/comments/399587.htmlhttp://www.tkk7.com/czihong/articles/399587.html#Feedback0http://www.tkk7.com/czihong/comments/commentRss/399587.htmlhttp://www.tkk7.com/czihong/services/trackbacks/399587.htmlRefer to: http://my.oschina.net/redhouse/blog/60739

CyclicBarrier 
(周期障碍)cd以帮助同步,它允怸l线E等待整个线E组到达公共屏障炏VCyclicBarrier 是用整型变量构造的Q其定l中的线E数。当一个线E到辑ֱ障时Q通过调用 CyclicBarrier.await()Q,它会被阻塞,直到所有线E都到达屏障Q然后在该点允许所有线El执行。与CountDownLatch不同的是QCyclicBarrier 所有公qE都到达后,可以l箋执行下一个目标点Q而CountDownLatchW一ơ到达指定点后,也就是记数器减制Ӟ无法再ơ执行下一目标工作。下面主要演义CyclicBarrier 的用法:

package com.test;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.concurrent.BrokenBarrierException;

import java.util.concurrent.CyclicBarrier;

import java.util.concurrent.ExecutorService;

import java.util.concurrent.Executors;

public class TestCyclicBarrier {

private static int[] timeWalk = { 5, 8, 15, 15, 10 };  // 徒步需要的旉

private static int[] timeSelf = { 1, 3, 4, 4, 5 };           // 自驾?/span>

private static int[] timeBus = { 2, 4, 6, 6, 7 };           // 旅游大巴

static String now() {

            SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");

            return sdf.format(new Date()) + ": ";

}

static class Tour implements Runnable {

            private   int[]     times;

            private   CyclicBarrier    barrier;

            private   String   tourName;

public Tour(CyclicBarrier barrier, String tourName, int[] times) {

            this.times = times;

            this.tourName = tourName;

            this.barrier = barrier;

}

public void run() {

        try {

                 Thread.sleep(times[0] * 1000);

                  System.out.println(now() + tourName + " 合肥");

                  barrier.await();

                  Thread.sleep(times[1] * 1000);

                  System.out.println(now() + tourName + " 南京");

                   barrier.await();

                  Thread.sleep(times[4] * 1000);

                   System.out.println(now() + tourName + " 上v");

                   barrier.await();

                   System.out.println(tourName + "飞机 合肥");

         } catch (InterruptedException e) {

                   e.printStackTrace();

          } catch (BrokenBarrierException e) {

                    e.printStackTrace();

          }

    }

}

 

public static void main(String[] args) {

              CyclicBarrier barrier = new CyclicBarrier(3);

               ExecutorService exec = Executors.newFixedThreadPool(3);

               exec.submit(new Tour(barrier, "徒步", timeWalk));

               exec.submit(new Tour(barrier, "自驾", timeSelf));

               exec.submit(new Tour(barrier, "大巴", timeBus));

              exec.shutdown();

  }

}

最后执行结果如下:

16:24:35: 自驾 合肥

16:24:36: 大巴 合肥

16:24:39: 徒步 合肥


16:24:42: 自驾 南京

16:24:43: 大巴 南京

16:24:47: 徒步 南京


16:24:52: 自驾 上v

16:24:54: 大巴 上v

16:24:57: 徒步 上v


徒步飞机 合肥

自驾飞机 合肥

大巴飞机 合肥



Chan Chen 2013-05-22 09:57 发表评论
]]>
IE6的连接数限制问题http://www.tkk7.com/czihong/articles/399561.htmlChan ChenChan ChenTue, 21 May 2013 07:19:00 GMThttp://www.tkk7.com/czihong/articles/399561.htmlhttp://www.tkk7.com/czihong/comments/399561.htmlhttp://www.tkk7.com/czihong/articles/399561.html#Feedback0http://www.tkk7.com/czihong/comments/commentRss/399561.htmlhttp://www.tkk7.com/czihong/services/trackbacks/399561.html先描qC下问题: 
有一个管理Job的UIQ选中一些Job可以RunQ每ơ只能启动一个。还有一个UI通过Timer定时发Ajaxh服务端,查询q显CJob的运行状况(q度Q?nbsp;

奇怪的问题出现了: 
1Q在FireFox和IE8q行正常Q貌似正常,E后再解释)。其他浏览器未测试?nbsp;
2QIE6,7及更早版本,Timer无法到多于1个的Jobq行?nbsp;

先检查了一遍代码,Timer的控制没有问题。不行就使用Fiddler吧。刚好是IE的问题?nbsp;

观察HTTP发现一个现象,q行Job的HTTPg没有成功Q因为Body?1Q之后是每隔一U的Timer发v的HTTP。如果再启动一个JobQ发现Timer停止了!Q?nbsp;

{待W一个Jobq行成功之后QTimer又恢复了Q重新发送AjaxhQ!Q?nbsp;

g是运行Job的请求阻塞了Q实际上该请求长旉没有q回Q因行Job需要几分钟甚至更多旉Q?nbsp;

为啥不用DWR3.0的Push技术?后来跟同事讨论明白,q不q是把Timer从客L转移C服务端?nbsp;

记v来了Q俺好像读DWR源代码的时候(当时对如何实现推非常感兴)Q见q一D代码分析Browser的类型和q接敎ͼ有的情况q抛Z异常?nbsp;

明白了,肯定是IE6有连接数限制问题Q后来得知,默认情况下,它不支持同时过2个连接。哈哈。这对了?nbsp;

RunJob占用了一个(几分钟不{)Q?nbsp;
Timer占用了一个(很短暂)?nbsp;

刚好2个?nbsp;
Java代码  收藏代码
  1. public class BrowserDetect  
  2. {  
  3.     /** 
  4.      * How many connections can this browser open simultaneously? 
  5.      * @param request The request so we can get at the user-agent header 
  6.      * @return The number of connections that we think this browser can take 
  7.      */  
  8.     public static int getConnectionLimit(HttpServletRequest request)  
  9.     {  
  10.         if (atLeast(request, UserAgent.IE, 8))  
  11.         {  
  12.             return 6;  
  13.         }  
  14.         if (atLeast(request, UserAgent.Firefox, 3))  
  15.         {  
  16.             return 6;  
  17.         }  
  18.         else if (atLeast(request, UserAgent.AppleWebKit, 8))  
  19.         {  
  20.             return 4;  
  21.         }  
  22.         else if (atLeast(request, UserAgent.Opera, 9))  
  23.         {  
  24.             return 4;  
  25.         }  
  26.         else  
  27.         {  
  28.             return 2;  
  29.         }  
  30.     }  
  31. //....  
  32. }  


接下来就是查资料做试验,验证该问题是否正。通过在注册表讄Internet Settings参数Q实C更多q接。例?0个?nbsp;

但是Job可能很多Q不可能无限制增加连接数Q所以RunJob不应长期占用q接Q它应该把Job插入队列q立卌回?nbsp;

x问题的源头终于找CQFiddler又帮了大忙?nbsp;

L代码是了解技术运作细节的最好方法,此外q能学到好的~程习惯?/span>

Chan Chen 2013-05-21 15:19 发表评论
]]>
Java 枚D7常见U用?/title><link>http://www.tkk7.com/czihong/articles/399319.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Wed, 15 May 2013 11:57:00 GMT</pubDate><guid>http://www.tkk7.com/czihong/articles/399319.html</guid><wfw:comment>http://www.tkk7.com/czihong/comments/399319.html</wfw:comment><comments>http://www.tkk7.com/czihong/articles/399319.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/czihong/comments/commentRss/399319.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/czihong/services/trackbacks/399319.html</trackback:ping><description><![CDATA[<p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">DK1.5引入了新的类?#8212;—枚D。在 <span style="font-family: 'Times New Roman';">Java</span> 中它虽然个“?#8221;功能Q却l我的开发带来了“?#8221;方便?/p><h2>用法一Q常?/h2><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">?span style="font-family: 'Times New Roman';">JDK1.5</span> 之前Q我们定义常量都是: <span style="font-family: 'Times New Roman';">public static fianl....</span> 。现在好了,有了枚DQ可以把相关的常量分l到一个枚丄型里Q而且枚D提供了比帔R更多的方法?/p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"> </p><div class="zfxj3f9" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码  <a href="" title="收藏q段代码" style="color: black;"><img src="http://softbeta.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">public</span> <span style="color: #7f0055;">enum</span> Color {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">  RED, GREEN, BLANK, YELLOW  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}  </li></ol></div> <h2>用法二:switch</h2><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">JDK1.6之前的switch语句只支持int,char,enumcdQ用枚举,能让我们的代码可L更强?/p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"> </p><div class="3h9ftnj" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码  <a href="" title="收藏q段代码" style="color: black;"><img src="http://softbeta.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">enum</span> Signal {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    GREEN, YELLOW, RED  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">public</span> <span style="color: #7f0055;">class</span> TrafficLight {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    Signal color = Signal.RED;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #7f0055;">public</span> <span style="color: #7f0055;">void</span> change() {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        <span style="color: #7f0055;">switch</span> (color) {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        <span style="color: #7f0055;">case</span> RED:  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">            color = Signal.GREEN;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">            <span style="color: #7f0055;">break</span>;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        <span style="color: #7f0055;">case</span> YELLOW:  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">            color = Signal.RED;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">            <span style="color: #7f0055;">break</span>;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        <span style="color: #7f0055;">case</span> GREEN:  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">            color = Signal.YELLOW;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">            <span style="color: #7f0055;">break</span>;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        }  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    }  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}  </li></ol></div> <h2>用法三:向枚举中d新方?/h2><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">如果打算自定义自qҎQ那么必denum实例序列的最后添加一个分受而且 <span style="font-family: 'Courier New';">Java</span> 要求必须先定?nbsp;<span style="font-family: 'Courier New';">enum</span>实例?/p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"> </p><div class="199pbrh" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码  <a href="" title="收藏q段代码" style="color: black;"><img src="http://softbeta.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">public</span> <span style="color: #7f0055;">enum</span> Color {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    RED("U色", <span style="color: #c00000;">1</span>), GREEN("l色", <span style="color: #c00000;">2</span>), BLANK("白色", <span style="color: #c00000;">3</span>), YELLO("黄色", <span style="color: #c00000;">4</span>);  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="width: auto; border-width: 0px;">// 成员变量</span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #7f0055;">private</span> String name;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #7f0055;">private</span> <span style="color: #7f0055;">int</span> index;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="width: auto; border-width: 0px;">// 构造方?/span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #7f0055;">private</span> Color(String name, <span style="color: #7f0055;">int</span> index) {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        <span style="color: #7f0055;">this</span>.name = name;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        <span style="color: #7f0055;">this</span>.index = index;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    }  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="width: auto; border-width: 0px;">// 普通方?/span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #7f0055;">public</span> <span style="color: #7f0055;">static</span> String getName(<span style="color: #7f0055;">int</span> index) {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        <span style="color: #7f0055;">for</span> (Color c : Color.values()) {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">            <span style="color: #7f0055;">if</span> (c.getIndex() == index) {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">                <span style="color: #7f0055;">return</span> c.name;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">            }  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        }  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        <span style="color: #7f0055;">return</span> <span style="color: #7f0055;">null</span>;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    }  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="width: auto; border-width: 0px;">// get set Ҏ</span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #7f0055;">public</span> String getName() {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        <span style="color: #7f0055;">return</span> name;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    }  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #7f0055;">public</span> <span style="color: #7f0055;">void</span> setName(String name) {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        <span style="color: #7f0055;">this</span>.name = name;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    }  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #7f0055;">public</span> <span style="color: #7f0055;">int</span> getIndex() {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        <span style="color: #7f0055;">return</span> index;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    }  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #7f0055;">public</span> <span style="color: #7f0055;">void</span> setIndex(<span style="color: #7f0055;">int</span> index) {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        <span style="color: #7f0055;">this</span>.index = index;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    }  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}  </li></ol></div> <h2>用法四:覆盖枚D的方?/h2><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">下面l出一个toString()Ҏ覆盖的例子?/p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"> </p><div class="bp3r99l" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码  <a href="" title="收藏q段代码" style="color: black;"><img src="http://softbeta.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">public</span> <span style="color: #7f0055;">enum</span> Color {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    RED("U色", <span style="color: #c00000;">1</span>), GREEN("l色", <span style="color: #c00000;">2</span>), BLANK("白色", <span style="color: #c00000;">3</span>), YELLO("黄色", <span style="color: #c00000;">4</span>);  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="width: auto; border-width: 0px;">// 成员变量</span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #7f0055;">private</span> String name;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #7f0055;">private</span> <span style="color: #7f0055;">int</span> index;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="width: auto; border-width: 0px;">// 构造方?/span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #7f0055;">private</span> Color(String name, <span style="color: #7f0055;">int</span> index) {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        <span style="color: #7f0055;">this</span>.name = name;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        <span style="color: #7f0055;">this</span>.index = index;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    }  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="width: auto; border-width: 0px;">//覆盖Ҏ</span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #646464;">@Override</span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #7f0055;">public</span> String toString() {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        <span style="color: #7f0055;">return</span> <span style="color: #7f0055;">this</span>.index+"_"+<span style="color: #7f0055;">this</span>.name;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    }  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}  </li></ol></div> <h2>用法五:实现接口</h2><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">所有的枚D都承自java.lang.EnumcR由?span style="font-family: 'Courier New';">Java</span> 不支持多l承Q所以枚丑֯象不能再l承其他cR?/p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"> </p><div class="1hj9hjx" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码  <a href="" title="收藏q段代码" style="color: black;"><img src="http://softbeta.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">public</span> <span style="color: #7f0055;">interface</span> Behaviour {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #7f0055;">void</span> print();  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    String getInfo();  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">public</span> <span style="color: #7f0055;">enum</span> Color <span style="color: #7f0055;">implements</span> Behaviour{  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    RED("U色", <span style="color: #c00000;">1</span>), GREEN("l色", <span style="color: #c00000;">2</span>), BLANK("白色", <span style="color: #c00000;">3</span>), YELLO("黄色", <span style="color: #c00000;">4</span>);  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="width: auto; border-width: 0px;">// 成员变量</span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #7f0055;">private</span> String name;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #7f0055;">private</span> <span style="color: #7f0055;">int</span> index;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="width: auto; border-width: 0px;">// 构造方?/span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #7f0055;">private</span> Color(String name, <span style="color: #7f0055;">int</span> index) {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        <span style="color: #7f0055;">this</span>.name = name;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        <span style="color: #7f0055;">this</span>.index = index;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    }  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="width: auto; border-width: 0px;">//接口Ҏ</span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #646464;">@Override</span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #7f0055;">public</span> String getInfo() {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        <span style="color: #7f0055;">return</span> <span style="color: #7f0055;">this</span>.name;  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    }  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="width: auto; border-width: 0px;">//接口Ҏ</span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #646464;">@Override</span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #7f0055;">public</span> <span style="color: #7f0055;">void</span> print() {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        System.out.println(<span style="color: #7f0055;">this</span>.index+":"+<span style="color: #7f0055;">this</span>.name);  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    }  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}  </li></ol></div> <h2>用法六:使用接口l织枚D</h2><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"> </p><div class="zj9p39l" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #ffffff; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Java代码  <a href="" title="收藏q段代码" style="color: black;"><img src="http://softbeta.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">public</span> <span style="color: #7f0055;">interface</span> Food {  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #7f0055;">enum</span> Coffee <span style="color: #7f0055;">implements</span> Food{  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        BLACK_COFFEE,DECAF_COFFEE,LATTE,CAPPUCCINO  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    }  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    <span style="color: #7f0055;">enum</span> Dessert <span style="color: #7f0055;">implements</span> Food{  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">        FRUIT, CAKE, GELATO  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">    }  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">}  </li></ol></div> <h2>用法七:关于枚D集合的?/h2><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">java.util.EnumSet和java.util.EnumMap是两个枚N合。EnumSet保证集合中的元素不重复;EnumMap中的key是enumcdQ而value则可以是Lcd。关于这个两个集合的使用׃在这里赘qͼ可以参考JDK文?/p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;">关于枚D的实现细节和原理请参考:</p><img src ="http://www.tkk7.com/czihong/aggbug/399319.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/czihong/" target="_blank">Chan Chen</a> 2013-05-15 19:57 <a href="http://www.tkk7.com/czihong/articles/399319.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Curl命o使用整理http://www.tkk7.com/czihong/articles/399038.htmlChan ChenChan ChenThu, 09 May 2013 03:52:00 GMThttp://www.tkk7.com/czihong/articles/399038.htmlhttp://www.tkk7.com/czihong/comments/399038.htmlhttp://www.tkk7.com/czihong/articles/399038.html#Feedback0http://www.tkk7.com/czihong/comments/commentRss/399038.htmlhttp://www.tkk7.com/czihong/services/trackbacks/399038.html

Refer to: http://www.cnblogs.com/wangkangluo1/archive/2012/04/17/2453975.html

可以看作命o行浏览器

1、开启gziph
curl -I http://www.sina.com.cn/ -H Accept-Encoding:gzip,defalte

2、监控网늚响应旉
curl -o /dev/null -s -w "time_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n" "http://www.kklinux.com"

3. 监控站点可用?/strong>
curl -o /dev/null -s -w %{http_code} "http://www.kklinux.com"

4、以http1.0协议hQ默认ؓhttp1.1Q?/strong> 
curl -0 .............. 
      1Q读取网?nbsp;
  $ curl linuxidc.com">http://www.linuxidc.com 
  2Q保存网?nbsp;
  $ curl http://www.linuxidc.com > page.html $ curl -o page.html http://www.linuxidc.com 
  3Q用的proxy服务器及其端口:-x 
  $ curl -x 123.45.67.89Q?080 -o page.html http://www.linuxidc.com 
  4Q用cookie来记录session信息 
  $ curl -x 123.45.67.89Q?080 -o page.html -D cookie0001.txt http://www.linuxidc.com 
optionQ?-D 是把http的response里面的cookie信息存到一个特别的文g中去Q这P当页面被存到page.html的同Ӟcookie信息也被存到了cookie0001.txt里面?nbsp;
    5Q那么,下一ơ访问的时候,如何l箋使用上次留下的cookie信息呢? 
  使用option来把上次的cookie信息q加到http request里面去:-b 
  $ curl -x 123.45.67.89Q?080 -o page1.html -D cookie0002.txt -b cookie0001.txt http://www.linuxidc.com 

6Q浏览器信息~~~~ 
随意指定自己q次讉K所宣称的自q览器信息: -A
curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.yahoo.com 
q样Q服务器端接到访问的要求Q会认ؓ你是一个运行在Windows 2000上的IE6.0Q嘿嘿嘿Q其实也怽用的是苹果机呢! 
?Mozilla/4.73 [en] (X11; U; Linux 2.2; 15 i686"则可以告诉对方你是一台PC上跑着的LinuxQ用的是Netscape 4.73Q呵呵呵 

7Q?br style="margin: 0px; padding: 0px;" />另外一个服务器端常用的限制ҎQ就是检查http讉K的referer。比如你先访问首,再访问里面所指定的下载页Q这W二ơ访问的referer地址是W一ơ访问成功后的页面地 
址。这P服务器端只要发现对下载页面某ơ访问的referer地址?是首늚地址Q就可以断定那是个盗q了~~~~~ 
讨厌讨厌~~~我就是要盗连~~~~~Q!
q好curll我们提供了讑֮referer的optionQ?-e
curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -e "mail.yahoo.com" -o page.html -D cookie0001.txt http://www.yahoo.com 
q样Q就可以骗对方的服务器,你是从mail.yahoo.com点击某个链接q来的了Q呵呵呵 

8Qcurl 下蝲文g 
刚才讲过了,下蝲面C个文仉Q可以?-o Q下载文件也是一栗?/span>
比如Q?nbsp;curl -o 1.jpg http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG
q里教大家一个新的optionQ?-O
大写的OQ这么用Q?nbsp;curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG
q样Q就可以按照服务器上的文件名Q自动存在本CQ?nbsp;
再来一个更好用的?/span>
如果screen1.JPG以外q有screen2.JPG、screen3.JPG?...、screen10.JPG需要下载,难不成还要让我们写一个script来完成这些操作?
不干Q?/span>
在curl里面Q这么写可以了Q?/span>
curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen[1-10].JPG 
呵呵呵,厉害吧?Q~~~ 
9Q?/span>
再来Q我们l讲解下载!
curl -O http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG 
q样产生的下载,是
~zzh/001.JPG
~zzh/002.JPG
...
~zzh/201.JPG
~nick/001.JPG
~nick/002.JPG
...
~nick/201.JPG 
够方便的了吧Q哈哈哈 
咦?高兴得太早了?/span>
׃zzh/nick下的文g名都?01Q?02...Q?01Q下载下来的文g重名Q后面的把前面的文g都给覆盖掉了~~~ 
没关p,我们q有更狠的!
curl -o #2_#1.jpg http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG 
--q是.....自定义文件名的下载?
--对头Q呵呵! 
#1是变量,指的是{zzh,nick}q部分,W一ơ取值zzhQ第二次取值nick
#2代表的变量,则是W二D可变部?--[001-201]Q取g001逐一加到201
q样Q自定义出来下蝲下来的文件名Q就变成了这P
原来Q?~zzh/001.JPG ---> 下蝲后: 001-zzh.JPG
原来Q?~nick/001.JPG ---> 下蝲后: 001-nick.JPG 
q样一来,׃怕文仉名啦Q呵?nbsp;

9Q?/span>
l箋讲下?/span>
我们qx在windowsq_上,flashgetq样的工具可以帮我们分块q行下蝲Q还可以断线l传?/span>
curl在这些方面也不输l谁Q嘿?nbsp;
比如我们下蝲screen1.JPG中,H然掉线了,我们可以这样开始箋?/span>
curl -c -O http://cgi2.tky.3wb.ne.jp/~zzh/screen1.JPG 
当然Q你不要拿个flashget下蝲了一半的文g来糊弄我~~~~别的下蝲软g的半截文件可不一定能用哦~~~ 
分块下蝲Q我们用这个option可以了Q?-r
举例说明
比如我们有一个http://cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 要下载(赵老师的电话朗?:D Q?/span>
我们可以用q样的命令:
curl -r 0-10240 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &\
curl -r 10241-20480 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &\
curl -r 20481-40960 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &\
curl -r 40961- -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 
q样可以分块下载啦?/span>
不过你需要自己把q些破碎的文件合qv?/span>
如果你用UNIX或苹果,?cat zhao.part* > zhao.mp3可?/span>
如果用的是WindowsQ用copy /b 来解军_Q呵?nbsp;
上面讲的都是http协议的下载,其实ftp也一样可以用?/span>
用法嘛,
curl -u name:passwd ftp://ip:port/path/file
或者大家熟悉的
curl ftp://name:passwd@ip:port/path/file 
  
10)上传的option?-T 
比如我们向ftp传一个文Ӟ curl -T localfile -u name:passwd ftp://upload_site:port/path/ 
当然Q向http服务器上传文件也可以
比如 curl -T localfile http://cgi2.tky.3web.ne.jp/~zzh/abc.cgi
注意Q这时候,使用的协议是HTTP的PUT method 
刚才说到PUTQ嘿嘿,自然让老服惌v来了其他几种methosq没讲呢Q?/span>
GET和POST都不能忘哦?nbsp;
http提交一个表单,比较常用的是POST模式和GET模式 
GET模式什么option都不用,只需要把变量写在url里面可以了
比如Q?br style="margin: 0px; padding: 0px;" />curl http://www.yahoo.com/login.cgi?user=nickwolfe&password=12345 
而POST模式的option则是 -d 
比如Q?span style="margin: 0px; padding: 0px; line-height: 1.5; color: #ff6600;">curl -d "user=nickwolfe&password=12345" http://www.yahoo.com/login.cgi

q当于向这个站点发Zơ登陆申请~~~~~ 
到底该用GET模式q是POST模式Q要看对面服务器的程序设定?nbsp;
一炚w要注意的是,POST模式下的文g上的文g上传Q比?/span>
<form method="POST" enctype="multipar/form-data" action="http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi">
<input type=file name=upload>
<input type=submit name=nick value="go">
</form>
q样一个HTTP表单Q我们要用curlq行模拟Q就该是q样的语法:
curl -F upload=@localfile -F nick=go http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi 
|罗嗦嗦讲了q么多,其实curlq有很多很多技巧和用法
比如 https的时候用本地证书,可以这?/span>
curl -E localcert.pem https://remote_server 
再比如,你还可以用curl通过dict协议L字典~~~~~
curl dict://dict.org/d:computer 

今天Z查所有刺猬主Z所有域名是否有备案Q在使用wget不爽的情况下Q找Ccurlq个命o行流量器命oQ发现其对post的调用还是蛮好的Q特别有利于Ҏ交信息及?nbsp;
更参数进行较验.对于我想几十万域名到miibeian.gov.cnq行验证是否有备案信息非常有用.发现q篇文章很不错,特ؓ转脓Q?nbsp;
我的目标Q?/span>
curl -d "cxfs=1&ym=xieyy.cn" http://www.miibeian.gov.cn/baxx_cx_servlet 
在出来的信息中进行过滤,提取备案号信息,q设|一个标识位Q将域名Q备案号及标识位入库 

用curl命oQpost提交带空格的数据 
今天偶然遇到一个情况,我想用curld一个网,无意间发现要post的数据里带空根{比如用户名?abcdef"Q密码ؓ"abc def"Q其中有一个空|按照我以前的方式提交Q?nbsp;
curl -D cookie -d "username=abcdef&password=abc def" http://login.xxx.com/提示dp|?nbsp;

于是查看curl手册man curl。找刎ͼ 
d/--data (HTTP) Sends the speci?ed data in a POST request to the HTTP server, in a way that can emulate as if a user has ?lled in a HTML form and pressed the 
submit button. Note that the data is sent exactly as speci?ed with no extra processing (with all newlines cut off). The data is expected to be "url-encoded". 
This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare to -F/--form. If this option is used 
more than once on the same command line, the data pieces speci?ed will be merged together with a separating &-letter. Thus, using ’-d name=daniel -d 
skill=lousy’ would generate a post chunk that looks like ’name=daniel&skill=lousy’. 
于是改用Q?nbsp;
curl -D cookie -d "username=abcdef" -d "password=abc efg" http://login.xxx.com/q样p成功d了?nbsp;

(责Q~辑Q飘飞的?
 

Curl是Linux下一个很强大的http命o行工P其功能十分强大?/span>

1) 二话不说Q先从这里开始吧Q?/p>

$ curl http://www.linuxidc.com

回R之后Qwww.linuxidc.com 的htmlq里哗啦地昄在屏q上?nbsp;   ~

2) 嗯,要想把读q来面存下来,是不是要q样呢?

$ curl http://www.linuxidc.com > page.html

当然可以Q但不用q么ȝ的!

用curl的内|option好Q存下http的结果,用这个option: -o

$ curl -o page.html http://www.linuxidc.com

q样Q你可以看到屏q上出现一个下载页面进度指C。等q展?00%Q自然就 OK?/p>

3) 什么什么?Q访问不刎ͼ肯定是你的proxy没有讑֮了?/p>

使用curl的时候,用这个option可以指定http讉K所使用的proxy服务器及其端口: -x

$ curl -x 123.45.67.89:1080 -o page.html http://www.linuxidc.com

4) 讉K有些|站的时候比较讨厌,他用cookie来记录session信息?/p>

像IE/NNq样的浏览器Q当然可以轻易处理cookie信息Q但我们的curl呢?.....

我们来学习这个option: -D <— q个是把http的response里面的cookie信息存到一个特别的文g中去

$ curl -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxidc.com

q样Q当面被存到page.html的同Ӟcookie信息也被存到了cookie0001.txt里面?/p>

5Q那么,下一ơ访问的时候,如何l箋使用上次留下的cookie信息呢?要知道,很多|站都是靠监视你的cookie信息Q来判断你是不是不按规矩讉K他们的网站的?/p>

q次我们使用q个option来把上次的cookie信息q加到http request里面去: -b

$ curl -x 123.45.67.89:1080 -o page1.html -D cookie0002.txt -b cookie0001.txt http://www.linuxidc.com

q样Q我们就可以几乎模拟所有的IE操作Q去讉K|页了!

6Q稍微等{?nbsp;   ~我好像忘C么了    ~

对了Q是览器信?/p>

有些讨厌的网站总要我们使用某些特定的浏览器去访问他们,有时候更q分的是Q还要用某些特定的版本    NNDQ哪里有旉Z它去找这些怪异的浏览器呢!Q?/p>

好在curll我们提供了一个有用的optionQ可以让我们随意指定自己q次讉K所宣称的自q览器信息: -A

$ curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxidc.com

q样Q服务器端接到访问的要求Q会认ؓ你是一个运行在Windows 2000上的 IE6.0Q嘿嘿嘿Q其实也怽用的是苹果机呢!

?Mozilla/4.73 [en] (X11; U; Linux 2.2; 15 i686"则可以告诉对方你是一?PC上跑着的LinuxQ用的是Netscape 4.73Q呵呵呵

7Q另外一个服务器端常用的限制ҎQ就是检查http讉K的referer。比如你先访问首,再访问里面所指定的下载页Q这W二ơ访问的 referer地址是W一ơ访问成功后的页面地址。这P服务器端只要发现对下载页面某ơ访问的referer地址不是首页的地址Q就可以断定那是个盗 q了    ~

讨厌讨厌 ~我就是要盗连    ~Q!

q好curll我们提供了讑֮referer的optionQ?-e

$ curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -e "mail.linuxidc.com" -o page.html -D cookie0001.txt http://www.linuxidc.com

q样Q就可以骗对方的服务器,你是从mail.linuxidc.com点击某个链接q来的了Q呵呵呵

8Q写着写着发现漏掉什么重要的东西了!——- 利用curl 下蝲文g

刚才讲过了,下蝲面C个文仉Q可以?-o Q下载文件也是一栗比如,

$ curl -o 1.jpg http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG

q里教大家一个新的optionQ?-O 大写的OQ这么用Q?/p>

$ curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG

q样Q就可以按照服务器上的文件名Q自动存在本CQ?/p>

再来一个更好用的?/p>

如果screen1.JPG以外q有screen2.JPG、screen3.JPG?...、screen10.JPG需要下载,难不成还要让我们写一个script来完成这些操作?

不干Q?/p>

在curl里面Q这么写可以了Q?/p>

$ curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen[1-10].JPG

呵呵呵,厉害吧?Q?~

9Q再来,我们l箋讲解下蝲Q?/p>

$ curl -O http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG

q样产生的下载,是

~zzh/001.JPG

~zzh/002.JPG

...

~zzh/201.JPG

~nick/001.JPG

~nick/002.JPG

...

~nick/201.JPG

够方便的了吧Q哈哈哈

咦?高兴得太早了?/p>

׃zzh/nick下的文g名都?01Q?02...Q?01Q下载下来的文g重名Q后面的把前面的文g都给覆盖掉了 ~

没关p,我们q有更狠的!

$ curl -o #2_#1.jpg http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG

—q是.....自定义文件名的下载? —对头Q呵呵!

q样Q自定义出来下蝲下来的文件名Q就变成了这P原来Q?~zzh/001.JPG —-> 下蝲后: 001-zzh.JPG 原来Q?~nick/001.JPG —-> 下蝲后: 001-nick.JPG

q样一来,׃怕文仉名啦Q呵?/p>

?/p>

Chan Chen 2013-05-09 11:52 发表评论
]]>
Java Web Application q程调试http://www.tkk7.com/czihong/articles/398812.htmlChan ChenChan ChenSun, 05 May 2013 08:49:00 GMThttp://www.tkk7.com/czihong/articles/398812.htmlhttp://www.tkk7.com/czihong/comments/398812.htmlhttp://www.tkk7.com/czihong/articles/398812.html#Feedback0http://www.tkk7.com/czihong/comments/commentRss/398812.htmlhttp://www.tkk7.com/czihong/services/trackbacks/398812.html最q在开发java web application的时候,因ؓ很多原因Q无法对自己开发的目在本地进行调试,常常需要进行远E调试,之前一直通过打logger的方式进行,每次都要重新部vQ相当的痛苦Q今天下午研I了以下Q如果进行远E调试?br />
开发的web application是部|在tomcat上面的,那么问题p{化ؓ如何调试tomcat。其实调试tomcatQ本质上是调试JVM。JVM的强大,从J2SE1.4.2开始,实CJPDA QJava Platform Debug ArchitectureQ?br />
tomcat默认情况下,是没有启用jpda的,如果要启用,需要传入参?br />-Xdebug -Xrunjdwp:transport=dt_socket, address=8000,server=y,suspend=y

那么问题是这些参数如何在tomcat启动的用传入呢Q这是时候,需要了解tomcat的启动脚本,在TOMCAT_HOME/bin

目录下,有三个脚本catalina.sh, startup.sh, ?shutdown.sh。如果查看startup.sh和shutdown.shQ都是通过catalina.sh来启动的。脚本如下:

EXECUTABLE=catalina.sh

exec "$PRGDIR"/"$EXECUTABLE" start "$@"
于是Q我们可以查看下catalina.sh的脚本是如何实现的?br />
#   JPDA_TRANSPORT  (Optional) JPDA transport used when the "jpda start"
#                   command is executed. The default is "dt_socket".
#
#   JPDA_ADDRESS    (Optional) Java runtime options used when the "jpda start"
#                   command is executed. The default is 8000.
#
#   JPDA_SUSPEND    (Optional) Java runtime options used when the "jpda start"
#                   command is executed. Specifies whether JVM should suspend
#                   execution immediately after startup. Default is "n".
#
#   JPDA_OPTS       (Optional) Java runtime options used when the "jpda start"
#                   command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS,
#                   and JPDA_SUSPEND are ignored. Thus, all required jpda
#                   options MUST be specified. The default is:
#
#                   -agentlib:jdwp=transport=$JPDA_TRANSPORT,
#                       address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND

if [ "$1" = "jpda" ] ; then
  if [ -z "$JPDA_TRANSPORT" ]; then
    JPDA_TRANSPORT="dt_socket"
  fi  
  if [ -z "$JPDA_ADDRESS" ]; then
    JPDA_ADDRESS="8000"
  fi  
  if [ -z "$JPDA_SUSPEND" ]; then
    JPDA_SUSPEND="n"
  fi  
  if [ -z "$JPDA_OPTS" ]; then
    JPDA_OPTS="-agentlib:jdwp=transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND"
  fi  
  CATALINA_OPTS="$CATALINA_OPTS $JPDA_OPTS"
  shift
fi

通过q个代码Q我们可以看出,其实要启动jpda, 最主要的是要对JPDA_SUSPEND的D行设|,由N改ؓY?br />
借鉴start.sh的启动,在linux下,我们可以自己创徏一个jpda.sh的脚本,用来启动开启debug模式的tomcatQ具体脚本如下,黑体Z攚w分?br />
os400=false
darwin=false
case "`uname`" in
CYGWIN*) cygwin=true;;
OS400*) os400=true;;
Darwin*) darwin=true;;
esac

# resolve links - $0 may be a softlink
PRG="$0"

while [ -h "$PRG" ] ; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done
 
PRGDIR=`dirname "$PRG"`
EXECUTABLE=catalina.sh

# Check that target executable exists
if $os400; then
  # -x will Only work on the os400 if the files are: 
  # 1. owned by the user
  # 2. owned by the PRIMARY group of the user
  # this will not work if the user belongs in secondary groups
  eval
else
  if [ ! -x "$PRGDIR"/"$EXECUTABLE" ]; then
    echo "Cannot find $PRGDIR/$EXECUTABLE"
    echo "The file is absent or does not have execute permission"
    echo "This file is needed to run this program"
    exit 1
  fi
fi 

export JPDA_SUSPEND=y

exec "$PRGDIR"/"$EXECUTABLE" jpda start "$@"

 

在Eclipse中远E调试Tomcat

首先Tomcat 5.5.26的源代码分ؓcontainer connectors jasper servletapi build五个目Q导入到Eclipse中。启动相关的代码主要在container中,׃它ؓ当前目Q打开”Debug Configurations“对话框?/p>

然后创徏一?#8221;Remote Java Application“QConnection Type选择”Standard (Socket Attach)“QHost填写localhostQTomcat所在的L地址Q,Port填写8000。最后点?#8221;Apply“保存?/p>

Eclipse的Debug Configurations对话框中配置q程调试

 

首先保已经执行了jpda.batQTomcat正在{待调试器连接;然后执行上述的Debug ConfigurationQEclipse可以连上Tomcat?/p>

 

Tomcat的启动是从Bootstrap的mainҎ开始,我在W一行代码处讄了断点,Tomcat的启动就停在了这一行:

 

断点调试Tomcat的启动过E? width=

 

接着Q让Tomcatl箋执行Q我们可以看刎ͼ控制台输Z启动信息?/p>

Tomcat在JPDA模式下l启? width=



Chan Chen 2013-05-05 16:49 发表评论
]]>
spring mvc singleton的验?/title><link>http://www.tkk7.com/czihong/articles/398806.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Sun, 05 May 2013 05:49:00 GMT</pubDate><guid>http://www.tkk7.com/czihong/articles/398806.html</guid><wfw:comment>http://www.tkk7.com/czihong/comments/398806.html</wfw:comment><comments>http://www.tkk7.com/czihong/articles/398806.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/czihong/comments/commentRss/398806.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/czihong/services/trackbacks/398806.html</trackback:ping><description><![CDATA[用了Spring MVC有一个多月了Q之前虽然有接触q一些,但是一直没有在实际工作中用。今天和同事聊vQ谈到Spring MVC中的Controller是单例实现的Q于是就写了一D代码验证一些?br /><br />1. 如果是单例的Q那么在ControllercM的实例变量应该是׃n的,如果不共享,则说明不是单例?br />直接代码Q?br /><div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->@Controller<br /><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">class</span> DemoAction {<br /><br />    <span style="color: #0000FF; ">private</span> <span style="color: #0000FF; ">int</span>  i = 0;<br /><br />    @RequestMapping(value = "/singleton")<br />    @ResponseBody<br />    <span style="color: #0000FF; ">public</span> String singleton(HttpServletRequest request, HttpServletResponse response) <span style="color: #0000FF; ">throws</span> InterruptedException {<br />        <span style="color: #0000FF; ">int</span> addInt = Integer.parseInt(request.getParameter("int"));<br />        i = i + addInt;<br />        <span style="color: #0000FF; ">return</span> String.valueOf(i);<br />    }<br />}</div><br />分别三次hQ?localhostQ?080/projectname/singletonQint=5<br />得到的返回结果如下?br />W一ơ: i=5<br />W二ơ: i=10<br />W三ơ: i=15<br /><br />重结果可以得知,i的状态是׃n的,因此Controller是单例的?br /><br />-------------------------------------------------------------------------------------------------------------------------<br />2. 如果是单例,那么多个U程h同一个ControllercM的同一个方法,U程是否会堵塞?<br />验证代码如下Q?br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->    @RequestMapping(value = "/switcher")<br />    @ResponseBody<br />    <span style="color: #0000FF; ">public</span> String switcher(HttpServletRequest request, HttpServletResponse response)<br />            <span style="color: #0000FF; ">throws</span> InterruptedException {<br />        String switcher = request.getParameter("switcher");<br />        <span style="color: #0000FF; ">if</span> (switcher.equals("on")) {<br />            Thread.currentThread().sleep(10000);<br />            <span style="color: #0000FF; ">return</span> "switch on";<br />        } <span style="color: #0000FF; ">else</span> {<br />            <span style="color: #0000FF; ">return</span> switcher;<br />        }<br />    }</div><br />验证ҎQ?br />分别发送两个请求,<br />W一个请求:localhostQ?080/projectname/singletonQswitcher=on<br />W二个请求:localhostQ?080/projectname/singletonQswitcher=everything<br /><br />验证l果Q?br />W一个请求发出去以后Q本地服务器{待10sQ然后返回结?#8220;switch on”,<br />在本地服务器{待的?0s当中Q第二期的请求,直接q回l果“everything”。说明之间的U程是不互相影响的?br />-------------------------------------------------------------------------------------------------------------------------<br />3.既然Controller是单例的Q那么Service是单例的吗?验证Ҏ和Controller的单例是一L?br />验证代码Q?br />Controller:<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><div style="display: inline-block;">@Controller<br /><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> DemoAction {<br /><br /><div>    @Resource</div><div>    private DemoService demoService;</div><br />    @RequestMapping(value = "/service")<br />    @ResponseBody<br />    <span style="color: #0000ff;">public</span> String service(HttpServletRequest request, HttpServletResponse response)<br />            <span style="color: #0000ff;">throws</span> InterruptedException {<br />        <span style="color: #0000ff;">int</span> result = demoService.addService(5);<br />        <span style="color: #0000ff;">return</span> String.valueOf(result);<br />    }<br />}</div>    </div>Service:<br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->@Service<br /><span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">class</span> DemoService {<br />    <span style="color: #0000FF; ">private</span> <span style="color: #0000FF; ">int</span> i = 0;<br />    <span style="color: #0000FF; ">public</span> <span style="color: #0000FF; ">int</span> addService(<span style="color: #0000FF; ">int</span> num){<br />        i = i + num;<br />        <span style="color: #0000FF; ">return</span> i;<br />    }<br />}</div><br />分别三次hQ?localhostQ?080/projectname/service<br />得到的返回结果如下?br />W一ơ: i=5<br />W二ơ: i=10<br />W三ơ: i=15<br /><br />重结果可以得知,i的状态是׃n的,因此Service默认是单例的?br />-------------------------------------------------------------------------------------------------------------------------<br />相同的验证方法,可以得出@Repository的DAO也是默认单例?br /><br /><br /><br /><br /><br /><img src ="http://www.tkk7.com/czihong/aggbug/398806.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/czihong/" target="_blank">Chan Chen</a> 2013-05-05 13:49 <a href="http://www.tkk7.com/czihong/articles/398806.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java MVC 比较http://www.tkk7.com/czihong/articles/398790.htmlChan ChenChan ChenSat, 04 May 2013 08:21:00 GMThttp://www.tkk7.com/czihong/articles/398790.htmlhttp://www.tkk7.com/czihong/comments/398790.htmlhttp://www.tkk7.com/czihong/articles/398790.html#Feedback0http://www.tkk7.com/czihong/comments/commentRss/398790.htmlhttp://www.tkk7.com/czihong/services/trackbacks/398790.html阅读全文

Chan Chen 2013-05-04 16:21 发表评论
]]>
计算500万PV/每天的网?/title><link>http://www.tkk7.com/czihong/articles/398789.html</link><dc:creator>Chan Chen</dc:creator><author>Chan Chen</author><pubDate>Sat, 04 May 2013 08:00:00 GMT</pubDate><guid>http://www.tkk7.com/czihong/articles/398789.html</guid><wfw:comment>http://www.tkk7.com/czihong/comments/398789.html</wfw:comment><comments>http://www.tkk7.com/czihong/articles/398789.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/czihong/comments/commentRss/398789.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/czihong/services/trackbacks/398789.html</trackback:ping><description><![CDATA[<p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;">Refer to: </span><a >http://elf8848.iteye.com/blog/967049</a><br /><span style="font-size: medium;">你想一个能承受500万PV/每天的网站吗Q?500万PV是什么概念?服务器每U要处理多少个请求才能应对?如果计算呢? <br /><br /><strong>PV是什么:</strong></span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;">PV是page view的简写。PV是指面的访问次敎ͼ?/span><span style="font-size: medium;">打开或刷?/span><span style="font-size: medium;">一ơ页面,q做一个pv?nbsp;<br /><br /><strong>计算模型Q?nbsp;</strong><br />每台服务器每U处理请求的数量=((80%*总PV?/(24时*60?60U?40%)) / 服务器数??br />其中关键的参数是80%?0%。表CZ天中?0%的请求发生在一天的40%的时间内?4时?0%?.6时Q有80%的请求发生一天的9.6个小时当中(很适合互联|的应用Q白天请求多Q晚上请求少Q?nbsp;<br /></span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"> </p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;"><strong>单计的l果Q?/strong><br />((80%*500?/(24时*60?60U?40%))/1 = 115.7个请?U?nbsp;<br />((80%*100?/(24时*60?60U?40%))/1 = 23.1个请?U?nbsp;<br /><br /><strong>初步l论Q?/strong> <br />现在我们在做压力试Ӟ有了标准,如果你的服务器一U能处理115.7个请求,可以承?00万PV/每天。如果你的服务器一U能处理23.1个请求,可以承?00万PV/每天</span><span style="font-size: medium;">?/span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"> </p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;"><strong>留余量Q?/strong></span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;">以上h数量</span><span style="font-size: medium;">?/span><span style="font-size: medium;">均匀的分布在白天?.6个小时中Q但实际情况q不会这么均匀的分布,会有高峰有低谗ؓ了应寚w峰时D,</span><span style="font-size: medium;">应该留一些余圎ͼ最也要x2倍,x3倍也不ؓq?/span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;">115.7个请?U?nbsp;*2?231.4</span><span style="font-size: medium;">个请?U?/span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;">115.7个请?U?nbsp;*3</span><span style="font-size: medium;">?/span><span style="font-size: medium;">=347.1</span><span style="font-size: medium;">个请?U?/span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;">23.1个请?U?nbsp;*2</span><span style="font-size: medium;">?/span><span style="font-size: medium;">=46.2</span><span style="font-size: medium;">个请?U?/span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;">23.1个请?U?nbsp;*3</span><span style="font-size: medium;">?/span><span style="font-size: medium;">=</span><span style="font-size: medium;">69.3</span><span style="font-size: medium;">个请?U?/span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"> </p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><strong style="font-size: medium;">最l结论:</strong></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;">如果你的服务器一U能处理</span><span style="font-size: medium;">231.4--</span><span style="font-size: medium;">347.1</span><span style="font-size: medium;">个请?U?/span><span style="font-size: medium;">Q就可以应对q_500万PV/每天?/span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;">如果你的服务器一U能处理</span><span style="font-size: medium;">46.2--</span><span style="font-size: medium;">69.3</span><span style="font-size: medium;">个请求,可?/span><span style="font-size: medium;">应对q_100万PV/每天</span><span style="font-size: medium;">?/span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"> </p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;"><strong>说明Q?/strong></span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;">q里说明每秒N个请求,是QPS。因为我兛_的是应用E序处理业务的能力?nbsp;</span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"> </p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;"><strong>实际l验Q?/strong></span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;">1、根据实际经验,采用两台常规配置的机架式服务器,配置是很常见的配|,例如一?核CPU+4G内存+服务器SAS盘</span><span style="font-size: medium;">?/span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;">2、个人武断的认ؓ在服务器CPU领域Intel的CPU要优于AMD</span><span style="font-size: medium;">的CPU</span><span style="font-size: medium;">Q有反对的就反对吧,我都说我武断了(L</span><a style="color: #108ac6; font-size: medium;">CPU性能比较</a><span style="font-size: medium;">Q,不要太相信AMD的广告,比较CPU性能单办法就是比hQ不要比频率与核心数Qh格相差不多的性能也相差不多?/span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;">3、硬盘的性能很重要,由其是数据库服务器。一般的服务器都?/span><span style="font-size: medium;">1.5万{的SAS盘Q高U一点的可以配SSD固态硬盘,性能会更好。最最最最重要的指标是“随机d性能”而不?#8220;序d性能”。(本例q是配置最常见?/span><span style="font-size: medium;">1.5万{的SAS盘?/span><span style="font-size: medium;">Q?/span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;">4、一台服务器跑Tomcatq行j2eeE序,一台服务器跑MySql数据?E序写的中等水^(q个真的不好量化)Q是</span><span style="font-size: medium;">论坛cd的应?L回帖,不太Ҏ做缓?也无法静态化)?/span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;">5、以上Yg情况下,是可以承?00万PV/每天的?已留有余量应对突然的讉K高峰)</span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"> </p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;"><strong>注意机房的网l带宽:</strong></span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;">有h说以上条件我都满了Q但实际性能q是达不到目标。这时请注意你对外的|络的带宽,在国内服务器便宜但带宽很贵,很可能你在机房是与大家共享一?00M的光U,实际每个人可分到2M左右带宽。再好一?M,再好一点双U机?0M独nQ这已经</span><span style="font-size: medium;">很贵</span><span style="font-size: medium;">了(北京hQ?/span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: small;"><span style="font-size: medium;">一天L量:每个面20k字节*100万个面/1024=19531M字节=19G字节Q?/span></span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: small;"><span style="font-size: medium;">19531M/9.6时=2034M/时=578K字节/s   如果h是均匀分布的,需?M</span></span><span style="font-size: small;">Q?/span><span style="font-size: medium;">640K字节</span><span style="font-size: medium;">Q?/span><span style="font-size: medium;">带宽Q?Mb=640KB 注意大小写,b是位QB是字节,差了8倍)</span><span style="font-size: medium;">Q但所有请求不可能是均匀分布的,当有高峰?M带宽一定不够,X2倍就?0M带宽?/span><span style="font-size: medium;">10M带宽</span><span style="font-size: medium;">基本可以满要求?/span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;">以上是假设每个页?0k字节Q基本不包含囄Q要?/span><span style="font-size: medium;">包含</span><span style="font-size: medium;">囄更大了Q?0M</span><span style="font-size: medium;">带宽</span><span style="font-size: medium;">也不能满求了。你自已计算吧?/span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;">Q全文完Q?/span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"> </p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"> </p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"> </p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;"><strong>附:性能试基本概念</strong><br />--------------------------------------------------------------------------------------- <br /><strong>基本概念Q?/strong> <br />ThroughputQ吞吐量Q:按照常规理解|络吞吐量表C在单位旉内通过|卡数据量之和,其中卛_括本机网卡发送出ȝ数据量也包括本机|卡接收到的数据量?一?00Mb(?的双工网卡,最大发送数据的速度?2.5M字节/s Q?/span> <span style="font-size: medium;">最大接收数据的速度?2.5M字节/sQ?/span> <span style="font-size: medium;">可以</span> <strong><span style="font-size: medium;">同时</span> <span style="font-size: medium;">收发</span> </strong><span style="font-size: medium;">数据?nbsp;</span><br /><span style="font-size: medium;">q发用户敎ͼ是同时执行操作的用户(U程??nbsp;<br />响应旉Q从h发出到收到响应花费的旉 ?/span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #ffffff;"><span style="font-size: medium;"><br />QPS </span><span style="font-size: medium;">- Queries Per Second  </span><span style="font-size: medium;">每秒处理的查询数Q如果是数据库,q当于dQ?br />TPS </span><span style="font-size: medium;">- Transactions Per Second  </span><span style="font-size: medium;">每秒处理的事务数(如果是数据库Q就相当于写入、修?<br />IOPSQ每U磁盘进行的I/O操作ơ数<br /><br />例如Ҏ个数据库试Q分开两次QPS与TPS?br />QPSQ读取)值L高于TPS(写、改)Qƈ且有倍率关系Q因为:<br />1、数据库Ҏ询可能有~存?br />2、机械硬盘或SSD盘的读是比写快?/span> <span style="font-size: medium;"><br />--------------------------------------------------------------------------------------- <br /><strong>JMeter试参数说明Q?/strong> <br /><br />LabelQ每一个测试单元的名字?nbsp;<br /><br />#SamplesQ表CZ个测试单元一共发Z多少个请求?nbsp;<br /><br />AverageQ^均响应时?#8212;—默认情况下是单个 Request 的^均响应时_当用了 Transaction Controller Ӟ也可以以Transaction 为单位显C^均响应时间。,不重要?nbsp;<br /><br />MedianQ中位数Q也是 50Q?用户的响应时_如果把响应时间从到大顺序排序,那么50Q的h的响应时间在q个范围之内。重要?nbsp;<br /><br />90% LineQ?0Q?用户的响应时_如果把响应时间从到大顺序排序,那么90Q的h的响应时间在q个范围之内?span style="color: #ff0000;">重要</span> ?nbsp;<br /><br />MinQ最响应时_不重要?nbsp;<br /><br />MaxQ最大响应时_出现几率只不q是千分之一甚至万分之一Q不重要?nbsp;<br /><br />Error%Q本ơ测试中出现错误的请求的数量 <br /><br />ThroughputQ吞吐量——默认情况下表C每U完成的h敎ͼRequest per SecondQ,当用了 Transaction Controller Ӟ也可以表C类?LoadRunner ?Transaction per Second ?nbsp;<br /><br />KB/SecQ每U从服务器端<span style="color: #ff0000;">接收</span> 到的数据?只是接收)Q相当于LoadRunner中的Throughput/Sec <br />--------------------------------------------------------------------------------------- <br /><strong>loadrunner试参数说明Q?/strong> <br /><br /><strong>响应旉Q?/strong> ?0%|如果把响应时间从到大顺序排序,那么90Q的h的响应时间在q个范围之内。重要?nbsp;<br /><br /><strong>每秒点击?/strong> Qhits per Second,每秒钟向服务器提交请求的数量?nbsp;<br /><br /><strong>TPSQ?/strong> Transaction per Second Q每U事务数Q一个事务是指一个客h向服务器发送请求然后服务器做出反应的过E?nbsp;<br /><br /><strong>ThroughputQ吞吐量Q:</strong> Loadrunner记录的Throughput是接收到服务器返回的所有字节数之和Q与本地发出的字节数无关?nbsp;<br /><br /><strong>Throughput/SecQ?/strong> 每秒的吞吐量?nbsp;<br /><br />对于BS架构的一般分?响应旉、点ȝ、吞吐量、TPSQ每U事务数Q?nbsp;<br />对于CS架构的一般分?TPSQ每U事务数Q?nbsp;</span></p><img src ="http://www.tkk7.com/czihong/aggbug/398789.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/czihong/" target="_blank">Chan Chen</a> 2013-05-04 16:00 <a href="http://www.tkk7.com/czihong/articles/398789.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>лǵվܻԴȤ</p> <a href="http://www.tkk7.com/" title="亚洲av成人片在线观看">亚洲av成人片在线观看</a> <div class="friend-links"> </div> </div> </footer> վ֩ģ壺 <a href="http://www611rr.com" target="_blank">Ļþۺ</a>| <a href="http://ymiwang.com" target="_blank">޷츾</a>| <a href="http://5gz0z.com" target="_blank">޾Ʒ״</a>| <a href="http://gdfcjzx.com" target="_blank">һӰ</a>| <a href="http://513net.com" target="_blank">޹˾þۺһ</a>| <a href="http://xsdin.com" target="_blank">޹˾þ</a>| <a href="http://www-993789.com" target="_blank">Ʒþ</a>| <a href="http://gyjinzheng.com" target="_blank">㽶þһ</a>| <a href="http://266hd.com" target="_blank">Ļձ</a>| <a href="http://www16am8.com" target="_blank">ŷƷ˯ɳ</a>| <a href="http://6777s.com" target="_blank">޳츾߳XXXXX</a>| <a href="http://yy1288.com" target="_blank">޷ŮһŶ</a>| <a href="http://yuntao360.com" target="_blank">avһ</a>| <a href="http://qq367.com" target="_blank">þۺɫhezyo</a>| <a href="http://tlyihong.com" target="_blank">gayƬgvվ</a>| <a href="http://bjycxy88.com" target="_blank">Ʒһ </a>| <a href="http://yijiazhiwei.com" target="_blank">߹ۿƵa</a>| <a href="http://777cc55.com" target="_blank">aëƬav</a>| <a href="http://fjwkjx.com" target="_blank">޹һƵ</a>| <a href="http://www96pg.com" target="_blank">˳վ߲vr</a>| <a href="http://wwwabxx.com" target="_blank">޳aƬ77777kkkk</a>| <a href="http://hbjinmaitang.com" target="_blank">޾Ʒ߹ۿ</a>| <a href="http://45-po.com" target="_blank">Aɻ߹ۿ</a>| <a href="http://tlyyt.com" target="_blank">޾Ʒ߹ۿ</a>| <a href="http://www398ph.com" target="_blank">Ʒ</a>| <a href="http://zhhy68.com" target="_blank">þһѲ</a>| <a href="http://chuadang.com" target="_blank">˾Ʒһ</a>| <a href="http://gdjiayou.com" target="_blank">޻ɫѵӰ</a>| <a href="http://www79909c.com" target="_blank">ƬaëƬ</a>| <a href="http://786087.com" target="_blank">պƷƵһ</a>| <a href="http://bdyls.com" target="_blank">VAۺVAVA</a>| <a href="http://kingleadsw.com" target="_blank">žžAVƬ</a>| <a href="http://by6215.com" target="_blank">һ߹ۿ</a>| <a href="http://otkaxap.com" target="_blank">鶹va߾ƷѲ</a>| <a href="http://zhuanjiao521.com" target="_blank">91ѹۿ߹ۿ</a>| <a href="http://4001120002.com" target="_blank">xxxxձ</a>| <a href="http://www999973.com" target="_blank">ѿƷ鶹</a>| <a href="http://8izh.com" target="_blank">Avۺɫרɫ</a>| <a href="http://goeqq.com" target="_blank">xxxx18</a>| <a href="http://51comcomcom.com" target="_blank">߳þѹۿ</a>| <a href="http://am3736.com" target="_blank">Ʒѹۿ</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>