你真他妈的矫情

昨天晚上看了集《神秘博士》。剧情是说有座在宇宙中航行的城市,建立在一头被束缚住的星鲸背上。最后面临两个选择

  • 继续残忍地控制星鲸让其生不如死
  • 释放星鲸让城市毁灭

的确不是个轻松的选择。博士选择了一,但是他不想星鲸受苦,就决定杀死星鲸的大脑,使其成为植物鲸同时保护城市。

最后的结局是女主角大爱无疆,毅然释放了星鲸。然后星鲸竟然也大爱无疆了一下,没有抛弃城市,城市幸存了,人们欢歌笑语。

多么操蛋的剧情的啊。编剧你既然制造了一个难题就自己去面对它,选择它,并承担后果,别脑筋急转弯似的来个大团圆。搞的自己像是个童话世界的人权卫士。

现实是残酷的。昨天和舅舅讨论食人问题,冰天雪地就你我2个人,我先死了,你会不会吃掉我的尸体?舅舅说不知道。我说,你没死我就陪你一起死,你死掉了我就吃掉你,毫不犹豫,不带一点负罪感。就像三体里的乔伊娜。

战略特勤组 Unthinkable就个不错的思想实验,你要不要搞死几个无辜的孩子去拯救世界?女主角你矫情是吧?你人权卫士是吧?你代表大众价值观是吧?好,那大家别搞了,让原子弹爆炸去吧。

我若是Unthinkable剧中人物,定扇女主角一嘴巴子,你真他妈的矫情。然后,喝着咖啡等着被原子弹炸死。蛋定地。

 

 

 

Error: Init: SSLPassPhraseDialog builtin is not supported on Win32

在配置apache SSL证书时碰到Error: Init: SSLPassPhraseDialog builtin is not supported on Win32错误。原因如下:

I get the error message, “Error: Init: SSLPassPhraseDialog builtin is not supported on Win32″ when starting my website using Apache.
Problem I get the error message, “Error: Init: SSLPassPhraseDialog builtin is not supported on Win32″ when starting my website using Apache.

Resolution

This error occurs when a password is entered to encrypt the private key file (<filename>.key).  Apache on Windows doesn’t support private keys that are encrypted.  This password may have been set while creating the CSR.

    1. First, make a copy and backup your private key file. This file should have an extension of “.key”.
    1. Start OpenSSL and use the following command to remove the passphrase from the private key.  Change <filename1> to the name of your current private key.  Choose a new name for <filename2>.
      openssl rsa -in <filename1>.key -out <filename2>.key

Note:

       <filename2> will be your new private key file that does not contain a passphrase.
    1.  Move the new private key (<filename2>) to the same path as to where the original private key was located.
    1. Open your httpd.conf file and verify that the directive called “SSLCertificateKeyFile” points to the newly uploaded private key (<filename2>).
  1. Locate the directive “SSLPassPhraseDialog” and put a ‘#’ in front of it to comment out that line.

If this doesn’t appear to work for you, then you may need to create a new certificate.  This will require another CSR.  To ensure that no passphrase is entered in during the CSR generation phase, please use our OpenSSL Command Tool on our PKI Widgets website.

高性能网站建设指南-规则13-配置ETag

ETag类似下载文件的MD5校验码。浏览器可以通过提交ETag来让服务器判断浏览器的缓存是否过期。听起来不错。

问题是
问题是,ETag是根据某一算法生成的一个字符串,在集群条件下,相同的文件放在不同的服务器可能会有不同的ETag,这会导致缓存失效。而且浏览器发送条件request的时候,会同时包括If-None-Matche和If-Modified-Since,前者(ETag)的优先级更高。而且会导致代理缓存的失效。

  • 集群条件下的无意义200响应
  • 代理缓存失效,本来应该2个304,现在成了2个200.
怎么办?
凉拌,显示是不够的。二选一吧。
  1. 不用ETag
  2. 移除inode,用大小和时间戳作为ETag。
选择1,是明智的。你也可以选择2,问题是。。。用大小和时间戳生成ETag,不是和Last-Modified重复了吗?所以,还是选择1吧。
Apache和IIS都把ETag视为一个性能问题。所以,干掉ETag吧,你不会后悔的。

高性能网站建设指南-规则11-避免重定向

3XX系列的response code

  • 300 Multiple Choices
  • 301 Moved Permancently (参考:extjs.com
  • 302 Moved Temporarily
  • 303 See Other
  • 304 Not Modified
  • 305 Use Proxy
  • 307 Temporary Redirect
其他redirect的方法
  • <meta http-equiv=”refresh” content=”0; url=http://www.google.com”>
  • javascript重写document.location
不过看了以下的文章后,你会觉得这两种方法真是糟糕透了。因为后退按钮不能用了。
不建议使用重定向是因为这增加了HTTP请求和性能开销
有趣的是,重定向在流量分析中起到很大的作用。
  • 跟踪内部流量
  • 跟踪出站流量
    这就是几乎所有的SNS网站的外链都是sns.com/?go=www.google.com这样形式的原因。
 重定向的另外一个重要作用是:美化URL
避免重定向的方法:
使用Alias,mod_rewrite,DirectorySlash

高性能网站建设指南-规则10-精简JavaScript

其实这只是规则1的一个子集。

至于why要精简/压缩JS,不需要啰嗦。我们来看看how to. 以下的maven配置演示了如何在package一个war的时候压缩js。

<plugin>
	<groupId>net.alchim31.maven</groupId>
	<artifactId>yuicompressor-maven-plugin</artifactId>
	<executions>
		<execution>
			<goals>
				<goal>compress</goal>
			</goals>
		</execution>
	</executions>
	<configuration>
		<nosuffix>true</nosuffix>
		<aggregations>
			<aggregation>
				<!-- remove files after aggregation (default: false) <removeIncluded>true</removeIncluded> -->
				<!-- insert new line after each concatenation (default: false) -->
				<insertNewLine>true</insertNewLine>
				<output>${project.build.directory}/${project.build.finalName}/static/js/all.js</output>
				<!-- files to include, path relative to output's directory or absolute
					path -->
				<!--inputDir>base directory for non absolute includes, default to
					parent dir of output</inputDir -->
				<includes>
					<include>**/jquery.min.js</include>
					<include>**/XXX.js</include>
				</includes>
				<!-- files to exclude, path relative to output's directory <excludes>
					<exclude>**/*.pack.js</exclude> <exclude>**/compressed.css</exclude> </excludes> -->
			</aggregation>
		</aggregations>
	</configuration>
</plugin>

高性能网站建设指南-规则9-减少DNS查找

DNS查找一般需要20~120ms.

DNS的查找结果可以被缓存起来,在ISP或者局域网的缓存服务器上。在客户端也会被缓存。

对于服务器来说,DNS查找返回的TTL向客户端标识了此次查找的结果可以有效(缓存)多久。但是浏览器通常忽视TTL并设置自己的时间限制,HTTP中的Keep-Alive可以同时覆盖TTL和浏览器的设置,因为alive的tcp连接没有必要DNS。

然后balabalabala

总之,要减少DNS查找。

高性能网站建设指南-规则8-使用外部JavaScript和CSS

内联比外置快?
Steve大叔说内联要快一点,他说的没错,不过那是10年前。参考我之前做的测试。至少就Steve自己提供的例子,还是外置的快(732ms VS 1180ms)。原因是拆分JS后可以同步下载。

代码分离
所以,我们更加有理由使用外部的js和CSS。最大的好处是利于维护,做到数据,显示,行为的代码分离。

其他
“加载后下载”,“动态内联”。不表,就这样吧。

高性能网站建设指南-规则7-避免CSS表达式

这个规则是指不要在CSS中使用expression()。理由是调用过度频繁,书中提供了几个解决方案,不过,不用关心。这个东西是IE搞出来的怪胎,微软自己也不好意思了,从IE8开始后续版本已经默认不支持CSS表达式。所以,没什么好说的,忘记它吧。如果有兴趣,可以用IE7及以下版本打开这个页面玩死IE。
http://stevesouders.com/hpws/expression-counter.php