forked from soulteary/forever-coolshell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20.html
executable file
·391 lines (367 loc) · 43.7 KB
/
20.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
<!DOCTYPE html><!--[if IE 8]>
<html id="ie8" dir="ltr" lang="zh-CN"
prefix="og: https://ogp.me/ns#" >
<![endif]--><!--[if !(IE 8) ]><!--><html dir="ltr" lang="zh-CN" prefix="og: https://ogp.me/ns#"><!--<![endif]--><head><meta charset="UTF-8"/><title>酷壳 – CoolShell.cn - Part 20</title><link rel="stylesheet" type="text/css" href="/assets/all.min.css"/><link rel="shortcut icon" href="/assets/favicon.png"/></head>
<body class="home blog paged paged-20 group-blog">
<div id="page" class="hfeed site">
<header id="masthead" role="banner">
<div id="cc_spacer"></div>
<div class="site-header">
<div class="site-branding">
<a class="home-link" href="/" title="酷 壳 – CoolShell" rel="home">
<h1 class="site-title">酷 壳 – CoolShell</h1>
<h2 class="site-description">享受编程和技术所带来的快乐 – Coding Your Ambition</h2>
</a>
</div>
</div>
</header>
<div class="container">
<div class="row">
</div>
</div>
<div id="content" class="site-content">
<div class="container">
<div class="row">
<div id="primary" class="content-area col-md-12" style="margin-top: 40px;">
<main id="main" class="site-main" role="main">
<article id="post-6639" class="post-content post-6639 post type-post status-publish format-standard hentry category-proglanguage category-story tag-hack tag-programmer tag-programming-language tag-sql tag-58">
<header class="entry-header">
<span class="screen-reader-text">千万别惹程序员</span>
<h2 class="entry-title">
<a href="/articles/6639.html" rel="bookmark">千万别惹程序员</a>
</h2>
<div class="entry-meta">
<h5 class="entry-date"><i class="fa fa-calendar-o"></i> <a href="/articles/6639.html" title="07:54" rel="bookmark"><time class="entry-date" datetime="2012-02-21T07:54:57+08:00" pubdate="">2012年02月21日 </time></a><span class="byline"><span class="sep"></span><i class="fa fa-user"></i>
<span class="author vcard"><a class="url fn n" href="/haoel" title="View all posts by 陈皓" rel="author">陈皓</a></span></span> <i class="fa fa-comments-o"></i><span class="screen-reader-text">评论 </span> <a href="/articles/6639.html#comments" class="comments-link">95 条评论</a> <i class="fa fa-users" style="margin-left:10px;"></i> 78,165 人阅读</h5>
</div>
</header>
<div class="entry-content">
<p>酷壳好久没有发娱乐性质的技术文章了,搞得气氛有点严肃了,考虑到程序员们都是比较严肃和容易较真的类书呆子的群体,所以,需要更新一个有娱乐性质的文章了。正好最近看到了两个比较有趣的图,在新浪微博上都得到了比较不错的反响,因此,更新到酷壳上来。</p>
<h4>如果编程语言是一种刀</h4>
<p>下面这个图是把编程语言看做是一种刀,那么会是什么样的。这个图我个人感觉很有意思。</p>
<p><img decoding="async" class="aligncenter size-full wp-image-6642" title="programming language" src="/uploads/2012/02/programming-language.jpg" alt="" width="400" height="450" srcset="" sizes="(max-width: 400px) 100vw, 400px"/></p>
<p>对于这个图,最好不要解释,意会就好。不过,我却有点想不解风情,忍不住想解释一下。</p>
<p> <a href="/articles/6639.html#more-6639" class="more-link">…</a></p><a href="/articles/6639.html#more-6639" class="more-link">
</a><p class="read-more"><a href="/articles/6639.html#more-6639" class="more-link"></a><a class="btn btn-default" href="/articles/6639.html"> 阅读全文<span class="screen-reader-text"> Read More</span></a></p>
<p></p>
<div id="post-ratings-6639-loading" class="post-ratings-loading"><img src="https://coolshell.cn/wp-content/plugins/wp-postratings/images/loading.gif" width="16" height="16" class="post-ratings-image"/>Loading...</div>
</div>
<footer class="entry-footer">
</footer>
</article>
<article id="post-6548" class="post-content post-6548 post type-post status-publish format-standard hentry category-cplusplus category-itnews category-techarticle category-proglanguage tag-c tag-performance">
<header class="entry-header">
<span class="screen-reader-text">Why C++ ? 王者归来</span>
<h2 class="entry-title">
<a href="/articles/6548.html" rel="bookmark">Why C++ ? 王者归来</a>
</h2>
<div class="entry-meta">
<h5 class="entry-date"><i class="fa fa-calendar-o"></i> <a href="/articles/6548.html" title="08:22" rel="bookmark"><time class="entry-date" datetime="2012-02-02T08:22:57+08:00" pubdate="">2012年02月02日 </time></a><span class="byline"><span class="sep"></span><i class="fa fa-user"></i>
<span class="author vcard"><a class="url fn n" href="/haoel" title="View all posts by 陈皓" rel="author">陈皓</a></span></span> <i class="fa fa-comments-o"></i><span class="screen-reader-text">评论 </span> <a href="/articles/6548.html#comments" class="comments-link">145 条评论</a> <i class="fa fa-users" style="margin-left:10px;"></i> 108,838 人阅读</h5>
</div>
</header>
<div class="entry-content">
<p>因为又有人邀请我去Quora的C2C网站去回答问题去了,这回是 关于 <a href="http://weibo.com/n/laiyonghao">@laiyonghao</a> 的这篇有点争议的博文《2012 不宜进入的三个技术点》ActionScript,Thread 和 C++,<a href="http://blog.csdn.net/lanphaday/article/details/7223385" target="_blank"> C++争议的争议最大</a>。(要我说,.NET比C++更需要慎重进入,呵)。我就在这里回复一下这个问题吧。</p>
<p>正好我一个月前看到一个视频,这个演讲视频还比较著名,这个演讲者是<em>Exceptional C++ </em>和 <em>C++ Coding Standards</em> 的作者,还是ISO C++ 委员会的Chair,C++/CLI首席架构师,还是Microsoft的软件架构师,他叫<a href="http://herbsutter.com/" target="_blank">Herb Sutter</a>,他的这个演讲视频是 <a href="http://cppandbeyond.com/" target="_blank">C++ and Beyond 2011</a>上的一次公开演讲,题目是——<a href="http://channel9.msdn.com/posts/C-and-Beyond-2011-Herb-Sutter-Why-C" target="_blank">Why C++</a>? (如果你觉得那里的视频比较慢,你可以看<a href="http://v.youku.com/v_show/id_XMzA5OTIwODIw.html" target="_blank">优酷上的视频</a>)(英文听力好的同学可以看一样,因为都没有中文字幕)</p>
<p>我觉得这篇文章就足够可以说明很多问题了,所以,我把Herb的演讲幻灯片截了几页放到这里,并做上一些注释,算是一个演讲内容摘要吧。</p>
<p>1) 为什么C++?因为 Performance per $,也就是说performance 就是钱,这个分成三个方面,</p>
<ul>
<li>耗电,芯片的耗电量,移动设备的耗电量,家用电脑的耗电量都和钱有关系。</li>
<li>资源,家用电脑和移动设备上的处理器资源有限,因为要让一般消费者买的起。</li>
<li>体验,在更小的设备上会有更好的体验,有更好的体验就可以挣更多的钱。</li>
</ul>
<p>移动设备上的耗电量相信用过智能手机的人都知道吧,Android手机的耗电量实在是太大了。就算是iPhone在开启Wifi和3G的情况下耗电量也很快。</p>
<p><img decoding="async" loading="lazy" class="aligncenter size-full wp-image-6550" title="" src="/uploads/2012/02/WhyCPP.01.jpg" alt="" width="566" height="319" srcset=""/></p>
<p> <a href="/articles/6548.html#more-6548" class="more-link">…</a></p><a href="/articles/6548.html#more-6548" class="more-link">
</a><p class="read-more"><a href="/articles/6548.html#more-6548" class="more-link"></a><a class="btn btn-default" href="/articles/6548.html"> 阅读全文<span class="screen-reader-text"> Read More</span></a></p>
<p></p>
<div id="post-ratings-6548-loading" class="post-ratings-loading"><img src="https://coolshell.cn/wp-content/plugins/wp-postratings/images/loading.gif" width="16" height="16" class="post-ratings-image"/>Loading...</div>
</div>
<footer class="entry-footer">
</footer>
</article>
<article id="post-6526" class="post-content post-6526 post type-post status-publish format-standard hentry category-misc category-career tag-programmer tag-58">
<header class="entry-header">
<span class="screen-reader-text">软件开发的“三重门”</span>
<h2 class="entry-title">
<a href="/articles/6526.html" rel="bookmark">软件开发的“三重门”</a>
</h2>
<div class="entry-meta">
<h5 class="entry-date"><i class="fa fa-calendar-o"></i> <a href="/articles/6526.html" title="11:00" rel="bookmark"><time class="entry-date" datetime="2012-01-30T11:00:50+08:00" pubdate="">2012年01月30日 </time></a><span class="byline"><span class="sep"></span><i class="fa fa-user"></i>
<span class="author vcard"><a class="url fn n" href="/haoel" title="View all posts by 陈皓" rel="author">陈皓</a></span></span> <i class="fa fa-comments-o"></i><span class="screen-reader-text">评论 </span> <a href="/articles/6526.html#comments" class="comments-link">115 条评论</a> <i class="fa fa-users" style="margin-left:10px;"></i> 78,431 人阅读</h5>
</div>
</header>
<div class="entry-content">
<p>自从上次写了“<a title="程序员技术练级攻略" href="/articles/4990.html" target="_blank">程序员技术练级攻略</a>” 以来,就觉得似乎还有很多东西没有谈到,但当时没有继续思考了。而春节前有人问我,是做底层技术,还是做业务。这问题让我思考了很多,不由自主地回顾了一 下我这十多年的软件开发经历,并顺着整理分类了一下自己解决过的若干问题,还发散想了很多,经过了一个春节假期的发酵,产生了下面这篇文章。</p>
<h4>前言</h4>
<p>这篇文章必然是通过我的个人经历来写的。所以,我先说说个人经历吧。我的经历基本分成三个阶段。</p>
<p><strong>第一阶段:</strong>我 刚毕业时在家乡的某银行工作,做些银行的业务系统,还搞些网络,电子邮件系统,OA什么的,因为大四的时候在老师的公司里实习,银行里的人际关系太复杂, 而且技术都包给了产商,所以在银行的每一天都觉得不能适应里面的工作环境。两年后离职,单位分的房也不要了,直接去了上海,在上海呆了两年,本来想做互联 网的,但是泡沫来了,最终去了一家做系统集成的国企公司还是继续做银行业务。这四年来,主要解决的都是一些业务上的问题,银行里的会计业务,OA业务,国 际业务,中间对公业务都非常地复杂,而且因为当时的软件开发相当的不规范,所以基本上是在一种比较混乱的状态下度过的,而银行方面又很强势,所以,这段时 间主要是做业务。所以,技术上主要是积累了如何使用那些技术。C+/Java, Windows编程,Unix编程,网络编程主要是这段时间学的,看了太多的书(我大学课程里没有C++和Java,也没有Windows/Unix和网 络编程,所以,只能拼命地看书和自学)。</p>
<p><strong>第二阶段:</strong>然后,我来了北京,到了一家做分布式计算系统的公 司,整天和一个高性能技术高可用性的企业级的集群式的软件产品打交道(这家公司去年被IBM收购了),在这家公司把Windows/Unix和网络编程有 了更深入的了解,对我长进比较大的是明白了怎么做一个性能高,可用性高的集群式的系统,天天和底层打交道,干了4年多。然后去了一家金融信息公司,这家金 融公司主要做全球的金融信息数据处理,而我主要还是做核心数据发布系统的性能调优的项目,金融数据的实时性要求的高,数据量非常地大,高可用性要求得高, 得想尽一切办法省网络带宽,增加系统性能,还要保持高的可用性,不当机,不丢包。又干了4年多,入职的时候从国外接过来两个系统,其性能单机每秒可处理 120K message,我走的时候,我和团队把其优化到了每秒1.4M messages 的吞吐,另一个系统,从接手时的100k message/s优化到了500k message/s。这八年多的时候,全是在和这些高计算高性能的项目打交量,几乎没有什么业务,都是纯技术,积累到了很多和性能有关的高并发高计算系统 架构级的知识。</p>
<p> <a href="/articles/6526.html#more-6526" class="more-link">…</a></p><a href="/articles/6526.html#more-6526" class="more-link">
</a><p class="read-more"><a href="/articles/6526.html#more-6526" class="more-link"></a><a class="btn btn-default" href="/articles/6526.html"> 阅读全文<span class="screen-reader-text"> Read More</span></a></p>
<p></p>
<div id="post-ratings-6526-loading" class="post-ratings-loading"><img src="https://coolshell.cn/wp-content/plugins/wp-postratings/images/loading.gif" width="16" height="16" class="post-ratings-image"/>Loading...</div>
</div>
<footer class="entry-footer">
</footer>
</article>
<article id="post-6470" class="post-content post-6470 post type-post status-publish format-standard hentry category-misc category-progdesign category-602 tag-12306-cn tag-design tag-ecomm tag-performance">
<header class="entry-header">
<span class="screen-reader-text">由12306.cn谈谈网站性能技术</span>
<h2 class="entry-title">
<a href="/articles/6470.html" rel="bookmark">由12306.cn谈谈网站性能技术</a>
</h2>
<div class="entry-meta">
<h5 class="entry-date"><i class="fa fa-calendar-o"></i> <a href="/articles/6470.html" title="08:20" rel="bookmark"><time class="entry-date" datetime="2012-01-16T08:20:22+08:00" pubdate="">2012年01月16日 </time></a><span class="byline"><span class="sep"></span><i class="fa fa-user"></i>
<span class="author vcard"><a class="url fn n" href="/haoel" title="View all posts by 陈皓" rel="author">陈皓</a></span></span> <i class="fa fa-comments-o"></i><span class="screen-reader-text">评论 </span> <a href="/articles/6470.html#comments" class="comments-link">369 条评论</a> <i class="fa fa-users" style="margin-left:10px;"></i> 298,701 人阅读</h5>
</div>
</header>
<div class="entry-content">
<p>12306.cn网站挂了,被全国人民骂了。我这两天也在思考这个事,我想以这个事来粗略地和大家讨论一下网站性能的问题。因为仓促,而且完全基于本人有限的经验和了解,所以,如果有什么问题还请大家一起讨论和指正。(这又是一篇长文,只讨论性能问题,不讨论那些UI,用户体验,或是是否把支付和购票下单环节分开的功能性的东西)</p>
<h4>业务</h4>
<p>任何技术都离不开业务需求,所以,要说明性能问题,首先还是想先说说业务问题。</p>
<ul>
<li><strong>其一</strong>,<strong>有人可能把这个东西和QQ或是网游相比</strong>。但我觉得这两者是不一样的,网游和QQ在线或是登录时访问的更多的是用户自己的数据,而订票系统访问的是中心的票量数据,这是不一样的。不要觉得网游或是QQ能行你就以为这是一样的。网游和QQ 的后端负载相对于电子商务的系统还是简单。</li>
</ul>
<ul>
<li><strong>其二</strong>,<strong>有人说春节期间订火车的这个事好像网站的秒杀活动</strong>。的确很相似,但是如果你的思考不在表面的话,你会发现这也有些不一样。火车票这个事,一方面会伴随着大量的查询操作,更BT的是下单的时候需要对数据库很多的一致性的操作,一方面是从起点到终点各个分段票的一致性,另一方面,买的人路线、车次、时间选择有很多,会不停地改变下单方式。而秒杀,直接杀就好了,没有那么多查询和一致性的问题。另外,关于秒杀,完全可以做成只接受前N个用户的请求(完全不操作后端的任何数据, 仅仅只是对用户的下单操作log),这种业务,只需要在内存cache中放好可秒杀的数量,还可以把数据分布开来放,100商品,10台服务器一台放10个,无需在当时操作任何数据库。可以订单数够后,停止秒杀,然后批量写数据库。而且秒杀的商品不多。火车票这个不是像秒杀那么简单的,春运时间,几乎所有的票都是热门票,而且几乎是全国人民都来了,而且还有转车业务,多条线的库存都要做事务操作,你想想吧,这有多难。(淘宝的双十一也就3百万用户,而火车票瞬时有千万级别甚至是亿级别的)(<strong>更新:2014年1月11日</strong>:来了淘宝后,对淘宝的系统有了解,淘宝的秒杀活动,本质上是用输验证码并在CDN上把用户直接过滤掉了,比如:1千万个用户过滤了只剩2万个用户,这样数据库就顶得住了)</li>
</ul>
<ul>
<li><strong>其三</strong>,<strong>有人拿这个系统和奥运会的票务系统比较</strong>。我觉得还是不一样。虽然奥运会的票务系统当年也一上线就废了。但是奥运会用的是抽奖的方式,也就是说不存在先来先得的抢的方式,而且,是事后抽奖,事前只需要收信息,事前不需要保证数据一致性,没有锁,很容易水平扩展。</li>
</ul>
<ul>
<li><strong>其四</strong>,<strong>订票系统应该和电子商务的订单系统很相似</strong>,都是需要对库存进行:1)占住库存,2)支付(可选),3)扣除库存的操作。这个是需要有一致性的检查的,也就是在并发时需要对数据加锁的。B2C的电商基本上都会把这个事干成异步的,也就是说,你下的订单并不是马上处理的,而是延时处理的,只有成功处理了,系统才会给你一封确认邮件说是订单成功。我相信有很多朋友都收到认单不成功的邮件。<strong>这就是说,数据一致性在并发下是一个瓶颈</strong>。</li>
</ul>
<p> <a href="/articles/6470.html#more-6470" class="more-link">…</a></p><a href="/articles/6470.html#more-6470" class="more-link">
</a><p class="read-more"><a href="/articles/6470.html#more-6470" class="more-link"></a><a class="btn btn-default" href="/articles/6470.html"> 阅读全文<span class="screen-reader-text"> Read More</span></a></p>
<p></p>
<div id="post-ratings-6470-loading" class="post-ratings-loading"><img src="https://coolshell.cn/wp-content/plugins/wp-postratings/images/loading.gif" width="16" height="16" class="post-ratings-image"/>Loading...</div>
</div>
<footer class="entry-footer">
</footer>
</article>
<article id="post-6441" class="post-content post-6441 post type-post status-publish format-standard hentry category-webdev category-proglanguage tag-ecmascript tag-javascript tag-oop">
<header class="entry-header">
<span class="screen-reader-text">Javascript 面向对象编程</span>
<h2 class="entry-title">
<a href="/articles/6441.html" rel="bookmark">Javascript 面向对象编程</a>
</h2>
<div class="entry-meta">
<h5 class="entry-date"><i class="fa fa-calendar-o"></i> <a href="/articles/6441.html" title="08:16" rel="bookmark"><time class="entry-date" datetime="2012-01-09T08:16:27+08:00" pubdate="">2012年01月09日 </time></a><span class="byline"><span class="sep"></span><i class="fa fa-user"></i>
<span class="author vcard"><a class="url fn n" href="/haoel" title="View all posts by 陈皓" rel="author">陈皓</a></span></span> <i class="fa fa-comments-o"></i><span class="screen-reader-text">评论 </span> <a href="/articles/6441.html#comments" class="comments-link">108 条评论</a> <i class="fa fa-users" style="margin-left:10px;"></i> 94,684 人阅读</h5>
</div>
</header>
<div class="entry-content">
<p>Javascript是一个类C的语言,他的面向对象的东西相对于C++/Java比较奇怪,但是其的确相当的强大,在 <a href="http://www.cnblogs.com/weidagang2046/" target="_blank">Todd 同学</a>的“<a title="对象的消息模型" href="/articles/5202.html" rel="bookmark" target="_blank">对象的消息模型</a>”一文中我们已经可以看到一些端倪了。这两天有个前同事总在问我Javascript面向对象的东西,所以,索性写篇文章让他看去吧,这里这篇文章主要想从一个整体的角度来说明一下Javascript的面向对象的编程。(<strong>成文比较仓促,应该有不准确或是有误的地方,请大家批评指正</strong>)</p>
<p>另,这篇文章主要基于 <a href="http://www.ecma-international.org/publications/standards/Ecma-262.htm" target="_blank">ECMAScript 5</a>, 旨在介绍新技术。关于兼容性的东西,请看最后一节。</p>
<h4>初探</h4>
<p>我们知道Javascript中的变量定义基本如下:</p>
<pre data-enlighter-language="js" class="EnlighterJSRAW">var name = 'Chen Hao';;
var email = 'haoel(@)hotmail.com';
var website = 'https://coolshell.cn';</pre>
<p>如果要用对象来写的话,就是下面这个样子:</p>
<pre data-enlighter-language="js" class="EnlighterJSRAW">var chenhao = {
name :'Chen Hao',
email : 'haoel(@)hotmail.com',
website : 'https://coolshell.cn'
};</pre>
<p>于是,我就可以这样访问:</p>
<pre data-enlighter-language="js" class="EnlighterJSRAW">//以成员的方式
chenhao.name;
chenhao.email;
chenhao.website;
//以hash map的方式
chenhao["name"];
chenhao["email"];
chenhao["website"];
</pre>
<p>关于函数,我们知道Javascript的函数是这样的:</p>
<p> <a href="/articles/6441.html#more-6441" class="more-link">…</a></p><a href="/articles/6441.html#more-6441" class="more-link">
</a><p class="read-more"><a href="/articles/6441.html#more-6441" class="more-link"></a><a class="btn btn-default" href="/articles/6441.html"> 阅读全文<span class="screen-reader-text"> Read More</span></a></p>
<p></p>
<div id="post-ratings-6441-loading" class="post-ratings-loading"><img src="https://coolshell.cn/wp-content/plugins/wp-postratings/images/loading.gif" width="16" height="16" class="post-ratings-image"/>Loading...</div>
</div>
<footer class="entry-footer">
</footer>
</article>
<article id="post-6424" class="post-content post-6424 post type-post status-publish format-standard hentry category-itnews category-netsecurity tag-hash tag-java tag-318">
<header class="entry-header">
<span class="screen-reader-text">Hash Collision DoS 问题</span>
<h2 class="entry-title">
<a href="/articles/6424.html" rel="bookmark">Hash Collision DoS 问题</a>
</h2>
<div class="entry-meta">
<h5 class="entry-date"><i class="fa fa-calendar-o"></i> <a href="/articles/6424.html" title="08:36" rel="bookmark"><time class="entry-date" datetime="2012-01-06T08:36:05+08:00" pubdate="">2012年01月06日 </time></a><span class="byline"><span class="sep"></span><i class="fa fa-user"></i>
<span class="author vcard"><a class="url fn n" href="/haoel" title="View all posts by 陈皓" rel="author">陈皓</a></span></span> <i class="fa fa-comments-o"></i><span class="screen-reader-text">评论 </span> <a href="/articles/6424.html#comments" class="comments-link">119 条评论</a> <i class="fa fa-users" style="margin-left:10px;"></i> 60,907 人阅读</h5>
</div>
</header>
<div class="entry-content">
<p>最近,除了国内明文密码的安全事件,还有一个事是比较大的,那就是 Hash Collision DoS (Hash碰撞的拒绝式服务攻击),有恶意的人会通过这个安全弱点会让你的服务器运行巨慢无比。<strong>这个安全弱点利用了各语言的Hash算法的“非随机性”可以制造出N多的value不一样,但是key一样数据,然后让你的Hash表成为一张单向链表,而导致你的整个网站或是程序的运行性能以级数下降(可以很轻松的让你的CPU升到100%)</strong>。目前,这个问题出现于<a href="http://www.java.com/">Java</a>, <a href="http://jruby.org/">JRuby</a>, <a href="http://www.php.net/">PHP</a>, <a href="https://python.org/">Python</a>, <a href="http://rubini.us/">Rubinius</a>, <a href="http://www.ruby-lang.org/">Ruby</a>这些语言中,主要:</p>
<ul>
<li><a href="http://www.java.com">Java</a>, 所有版本</li>
<li><a href="http://jruby.org/">JRuby</a> <= 1.6.5 (目前fix在 1.6.5.1)</li>
<li><a href="http://www.php.net/">PHP</a> <= 5.3.8, <= 5.4.0RC3 (目前fix在 5.3.9, 5.4.0RC4)</li>
<li><a href="https://python.org/">Python</a>, all versions</li>
<li><a href="http://rubini.us/">Rubinius</a>, all versions</li>
<li><a href="http://www.ruby-lang.org/">Ruby</a> <= 1.8.7-p356 (目前fix在 1.8.7-p357, 1.9.x)</li>
<li><a href="http://geronimo.apache.org/">Apache Geronimo</a>, 所有版本</li>
<li><a href="http://tomcat.apache.org/">Apache Tomcat</a> <= 5.5.34, <= 6.0.34, <= 7.0.22 (目前fix在 5.5.35, 6.0.35, 7.0.23)</li>
<li><a href="http://glassfish.java.net/">Oracle Glassfish</a> <= 3.1.1 (目前fix在mainline)</li>
<li><a href="http://www.eclipse.org/jetty/">Jetty</a>, 所有版本</li>
<li><a href="http://plone.org/">Plone</a>, 所有版本</li>
<li><a href="http://rack.rubyforge.org/">Rack</a> <= 1.3.5, <= 1.2.4, <= 1.1.2 (目前fix 在 1.4.0, 1.3.6, 1.2.5, 1.1.3)</li>
<li><a href="https://code.google.com/p/v8/">V8 JavaScript Engine</a>, 所有版本</li>
<li>ASP.NET 没有打MS11-100补丁</li>
</ul>
<p>注意,Perl没有这个问题,因为Perl在N年前就fix了这个问题了。关于这个列表的更新,请参看 <a href="http://www.ocert.org/advisories/ocert-2011-003.html" target="_blank">oCERT的2011-003报告</a>,比较坑爹的是,这个问题早在2003 年就在论文《<a href="http://www.cs.rice.edu/~scrosby/hash/CrosbyWallach_UsenixSec2003.pdf" target="_blank">通过算法复杂性进行拒绝式服务攻击</a>》中被报告了,但是好像没有引起注意,尤其是Java。</p>
<h4>弱点攻击解释</h4>
<p>你可以会觉得这个问题没有什么大不了的,因为黑客是看不到hash算法的,如果你这么认为,那么你就错了,这说明对Web编程的了解还不足够底层。</p>
<p> <a href="/articles/6424.html#more-6424" class="more-link">…</a></p><a href="/articles/6424.html#more-6424" class="more-link">
</a><p class="read-more"><a href="/articles/6424.html#more-6424" class="more-link"></a><a class="btn btn-default" href="/articles/6424.html"> 阅读全文<span class="screen-reader-text"> Read More</span></a></p>
<p></p>
<div id="post-ratings-6424-loading" class="post-ratings-loading"><img src="https://coolshell.cn/wp-content/plugins/wp-postratings/images/loading.gif" width="16" height="16" class="post-ratings-image"/>Loading...</div>
</div>
<footer class="entry-footer">
</footer>
</article>
<article id="post-6335" class="post-content post-6335 post type-post status-publish format-standard hentry category-javadev category-proglanguage tag-classloader tag-getresource tag-getresourceasstream tag-java tag-resin">
<header class="entry-header">
<span class="screen-reader-text">Resin服务器getResource揭秘</span>
<h2 class="entry-title">
<a href="/articles/6335.html" rel="bookmark">Resin服务器getResource揭秘</a>
</h2>
<div class="entry-meta">
<h5 class="entry-date"><i class="fa fa-calendar-o"></i> <a href="/articles/6335.html" title="08:28" rel="bookmark"><time class="entry-date" datetime="2012-01-05T08:28:59+08:00" pubdate="">2012年01月05日 </time></a><span class="byline"><span class="sep"></span><i class="fa fa-user"></i>
<span class="author vcard"><a class="url fn n" href="/articles/author/liuxiaori" title="View all posts by liuxiaori" rel="author">liuxiaori</a></span></span> <i class="fa fa-comments-o"></i><span class="screen-reader-text">评论 </span> <a href="/articles/6335.html#comments" class="comments-link">14 条评论</a> <i class="fa fa-users" style="margin-left:10px;"></i> 11,675 人阅读</h5>
</div>
</header>
<div class="entry-content">
<p><strong>(<span style="color: #cc0000;">感谢网友 liuxiaori 继续分享其经历</span>)这样的详细的图文并茂的文章让我很佩服!</strong></p>
<h4>前言</h4>
<p>接上文“<a title="由一个问题到 Resin ClassLoader 的学习" href="/articles/6112.html" target="_blank">由一个问题到Resin ClassLoader的学习</a>”,本文将以this.getClass().getResource(“/”).getPath()和this.getClass().getResourceAsStream(“/a.txt”)为例,一步步解析加载的过程。</p>
<h4>调试环境</h4>
<ol>
<li>下载resin3.0.23的源码(<a href="http://www.caucho.com/download/resin-3.0.23-src.zip">http://www.caucho.com/download/resin-3.0.23-src.zip</a>)。</li>
<li>部署到myeclipse中,有错误,本人忽略了。Resin可运行。</li>
<li>将EhCacheTestAnnotation部署到resin3.0.23中。</li>
<li>调试this.getClass().getResource(“/”).getPath()。</li>
</ol>
<p>问题来了,无论如何也模拟不出来<compiling-loader>所造成的影响,一直输出:/D:/work_other/project/resin-3.0.23/bin/ 。无奈之下,采用了这种方式:使用两个eclipse,一个使用发布版本的,部署EhCacheTestAnnotation进行调试;另外一个部署resin3.0.23源码,调试到哪里对照看源码。</p>
<h4>开始</h4>
<h5>1) this.getClass().getResource(“/”).getPath()</h5>
<p>本次调试涉及的所有类加载器为:</p>
<blockquote><p>EnvironmentClassLoader$24156236[web-app:http://localhost:8787/EhCacheTestAnnotation]</p>
<p>EnvironmentClassLoader$7806641[host:http://localhost:8787]</p>
<p>EnvironmentClassLoader$22459270[servlet-server:]</p>
<p><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f487819ada999d8797dab895819a979c9186d0b58484b798958787b89b95909186b4c3c6c1cd9095">[email protected]</a></p>
<p><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c8bbbda6e6a5a1bbabe684a9bda6aba0adbaec8db0bc8ba4a9bbbb84a7a9acadba88f9fef1fbf8adfa">[email protected]</a></p></blockquote>
<p>首先进入Class的getResource(String name)方法,如下图:</p>
<p> <a href="/articles/6335.html#more-6335" class="more-link">…</a></p><a href="/articles/6335.html#more-6335" class="more-link">
</a><p class="read-more"><a href="/articles/6335.html#more-6335" class="more-link"></a><a class="btn btn-default" href="/articles/6335.html"> 阅读全文<span class="screen-reader-text"> Read More</span></a></p>
<p></p>
<div id="post-ratings-6335-loading" class="post-ratings-loading"><img src="https://coolshell.cn/wp-content/plugins/wp-postratings/images/loading.gif" width="16" height="16" class="post-ratings-image"/>Loading...</div>
</div>
<footer class="entry-footer">
</footer>
</article>
<article id="post-6346" class="post-content post-6346 post type-post status-publish format-standard hentry category-misc category-career tag-programmer tag-58">
<header class="entry-header">
<span class="screen-reader-text">程序员因为女孩而美丽!</span>
<h2 class="entry-title">
<a href="/articles/6346.html" rel="bookmark">程序员因为女孩而美丽!</a>
</h2>
<div class="entry-meta">
<h5 class="entry-date"><i class="fa fa-calendar-o"></i> <a href="/articles/6346.html" title="08:29" rel="bookmark"><time class="entry-date" datetime="2012-01-04T08:29:08+08:00" pubdate="">2012年01月04日 </time></a><span class="byline"><span class="sep"></span><i class="fa fa-user"></i>
<span class="author vcard"><a class="url fn n" href="/haoel" title="View all posts by 陈皓" rel="author">陈皓</a></span></span> <i class="fa fa-comments-o"></i><span class="screen-reader-text">评论 </span> <a href="/articles/6346.html#comments" class="comments-link">118 条评论</a> <i class="fa fa-users" style="margin-left:10px;"></i> 82,556 人阅读</h5>
</div>
</header>
<div class="entry-content">
<p><span style="color: #cc0000;"><strong>女程序员是程序员里美丽的风景线,我希望这些女程序员的经历能让我们</strong><strong>在这个“重男轻女”的社会中可以给女程员有更多平等的机会和条件,以及相应的尊重</strong><strong>。</strong><strong>因为,她们其中不乏优秀的程序员,而且在心态、态度和努力上还强过很多男性程序员,很多东西都值得我们大家</strong><strong>向她们学习</strong></span>。</p>
<p>这篇文章的来由是因为Eva在“<a title="三个事和三个问题" href="/articles/6142.html" target="_blank">三个事和三个问题</a>”的评论里<a href="/articles/6142.html/comment-page-1#comment-113406" target="_blank">问我女孩子是否能做技术</a>,她说她的很多师兄都告诉他不要做技术,所以,她有些不坚定了。我的回复是告诉了她我工作经历中的两个技术很牛的女孩,并且我从她们身上学到了多技术。但是,后面有一些人回复说我误导了别人。所以,我在<a href="http://weibo.com/1401880315/xE597iX6J" target="_blank">新浪微博</a>和<a href="https://twitter.com/#!/haoel/status/151856699387547649" target="_blank">twitter</a>上征集女程序员的故事和想法。我一共收到了19封邮件,其中有17封邮件来自女程序员。其中有一个已经发布了(<a title="一个女程序员的故事" href="/articles/6312.html" target="_blank">一个女程序员的故事</a>),其中的一些观点已经在网上传播,并得到了大家的刮目和称赞。但这并不是特例,因为下面的这些故事中,还有很多令人刮目相看的东西。</p>
<p><strong>说明</strong>:先说明一下,这篇文章并不想讨论女孩子是不是适合做技术,这不值得讨论,因为,在“<a title="一个女程序员的故事" href="/articles/6312.html" target="_blank">一个女程序员的故事</a>”中我们已经知道,态度和努力才是原因,而不是性别。这里,也只是想告诉那些有“性别歧视”、“看不起女程序员”、“骄傲自大”的男程序员们,那些女程序员不为所知的一面。<strong>我把几乎所有的故事都列在这篇文章里了,我觉得我不用再多说什么了,这些故事组成的风景线,可以让你充分地了解女程序员</strong>。</p>
<figure id="attachment_6378" aria-describedby="caption-attachment-6378" style="width: 337px" class="wp-caption aligncenter"><img decoding="async" loading="lazy" class=" wp-image-6378 " title="Ada Lovelace 世界第一个程序员" src="/uploads/2012/01/481px-Ada_Lovelace_1838.jpg" alt="Ada Lovelace 世界第一个程序员" width="337" height="419" srcset="" sizes="(max-width: 337px) 100vw, 337px"/><figcaption id="caption-attachment-6378" class="wp-caption-text">Ada Lovelace 世界第一个程序员</figcaption></figure>
<p>在看到那些故事之前,我们需要了解这样的现实——</p>
<p> <a href="/articles/6346.html#more-6346" class="more-link">…</a></p><a href="/articles/6346.html#more-6346" class="more-link">
</a><p class="read-more"><a href="/articles/6346.html#more-6346" class="more-link"></a><a class="btn btn-default" href="/articles/6346.html"> 阅读全文<span class="screen-reader-text"> Read More</span></a></p>
<p></p>
<div id="post-ratings-6346-loading" class="post-ratings-loading"><img src="https://coolshell.cn/wp-content/plugins/wp-postratings/images/loading.gif" width="16" height="16" class="post-ratings-image"/>Loading...</div>
</div>
<footer class="entry-footer">
</footer>
</article>
<article id="post-6312" class="post-content post-6312 post type-post status-publish format-standard hentry category-career category-story tag-programmer tag-58">
<header class="entry-header">
<span class="screen-reader-text">一个女程序员的故事</span>
<h2 class="entry-title">
<a href="/articles/6312.html" rel="bookmark">一个女程序员的故事</a>
</h2>
<div class="entry-meta">
<h5 class="entry-date"><i class="fa fa-calendar-o"></i> <a href="/articles/6312.html" title="10:25" rel="bookmark"><time class="entry-date" datetime="2011-12-30T10:25:02+08:00" pubdate="">2011年12月30日 </time></a><span class="byline"><span class="sep"></span><i class="fa fa-user"></i>
<span class="author vcard"><a class="url fn n" href="/haoel" title="View all posts by 陈皓" rel="author">陈皓</a></span></span> <i class="fa fa-comments-o"></i><span class="screen-reader-text">评论 </span> <a href="/articles/6312.html#comments" class="comments-link">220 条评论</a> <i class="fa fa-users" style="margin-left:10px;"></i> 123,320 人阅读</h5>
</div>
</header>
<div class="entry-content">
<p>因为有人在<a href="/articles/6142.html/comment-page-3#comment-113607" target="_blank">酷壳里评论</a>里说我给一个女程序员的建议不靠谱,我不服,因为我的工作经历中的一些女程序员都很不错,比那些男程序员都强,所以,我在<a href="http://weibo.com/1401880315/xE597iX6J" target="_blank">新浪微博</a>和<a href="https://twitter.com/#!/haoel/status/151856699387547649" target="_blank">twitter</a>上征集女程序员的故事和想法,这两天来,我收到了好几封邮件,让我很感动。其中,有一个故事让我回味很久,在脑海里挥之不去,可能是因为她的经历和我很相似,她的想法和我很有共鸣。</p>
<p>本来,我想通过收到的这些故事然后编辑成一篇关于女程序员的文章,但是我觉得这个故事已经足够好了,任何的编辑都是对这个故事的不尊重,所以,我原封不动,一字不改地把这个故事转到这里。我把一些我认为精彩的地方加了粗。</p>
<p>当然,我还是会再写一篇关于女程序员的文章,酷壳2011年底的最后篇文章和2012年的第一篇文章都是给女程序员的,因为,我为你们骄傲!</p>
<p style="padding-left: 30px;"><span style="color: #000000;">从哪里说起呢,我的程序员之路。有些话只是自己心里想的很明白,还从没说过。希望你有耐心看完,因为我的故事不精彩,也算不上奋斗史。我的文笔和叙事能力也很差。</span></p>
<p style="padding-left: 30px;"><span style="color: #000000;">高中报志愿的时候坚定的报了计算机技术及应用,当时对计算机的认识只是机房里的苹果机,和老师教的用basic 输出一个正方形之类的。 我当时觉得我对计算机一无所知,我想了解他,就选择了这个专业,当然当时程序员的收入也是可观的。 :)</span></p>
<p style="padding-left: 30px;"><span style="color: #000000;">大学四年下来,我的成绩不好,基础也不好,没拿过奖学金。大学的课程很多不喜欢,我不知道为什么计算机系还要学高等物理,和马列毛邓。这是题外话。说实在的,很多课上的我一头雾水。毕业后找工作不满意,我直接去读了软件工程(考研的专业课成绩没到线)。两年制,一年上课,一年实习。我想给自己的履历上增加一些至少能给我面试机会的经历。(我仔细思考过我成绩不好的原因,心里因素是主要的,高中在重点中学,我不能接受自己不是尖子生的事实,总在想自己为什么这么差,以至于这样的心情影响了我很多年,一直到工作后的几年)</span></p>
<p> <a href="/articles/6312.html#more-6312" class="more-link">…</a></p><a href="/articles/6312.html#more-6312" class="more-link">
</a><p class="read-more"><a href="/articles/6312.html#more-6312" class="more-link"></a><a class="btn btn-default" href="/articles/6312.html"> 阅读全文<span class="screen-reader-text"> Read More</span></a></p>
<p></p>
<div id="post-ratings-6312-loading" class="post-ratings-loading"><img src="https://coolshell.cn/wp-content/plugins/wp-postratings/images/loading.gif" width="16" height="16" class="post-ratings-image"/>Loading...</div>
</div>
<footer class="entry-footer">
</footer>
</article>
<article id="post-6112" class="post-content post-6112 post type-post status-publish format-standard hentry category-javadev tag-classloader tag-getresource tag-getresourceasstream tag-java tag-resin">
<header class="entry-header">
<span class="screen-reader-text">由一个问题到 Resin ClassLoader 的学习</span>
<h2 class="entry-title">
<a href="/articles/6112.html" rel="bookmark">由一个问题到 Resin ClassLoader 的学习</a>
</h2>
<div class="entry-meta">
<h5 class="entry-date"><i class="fa fa-calendar-o"></i> <a href="/articles/6112.html" title="12:22" rel="bookmark"><time class="entry-date" datetime="2011-12-28T12:22:55+08:00" pubdate="">2011年12月28日 </time></a><span class="byline"><span class="sep"></span><i class="fa fa-user"></i>
<span class="author vcard"><a class="url fn n" href="/articles/author/liuxiaori" title="View all posts by liuxiaori" rel="author">liuxiaori</a></span></span> <i class="fa fa-comments-o"></i><span class="screen-reader-text">评论 </span> <a href="/articles/6112.html#comments" class="comments-link">30 条评论</a> <i class="fa fa-users" style="margin-left:10px;"></i> 19,581 人阅读</h5>
</div>
</header>
<div class="entry-content">
<p><strong>(<span style="color: #cc0000;">感谢网友 liuxiaori 分享其经历</span>)<br/>
</strong></p>
<h4>背景</h4>
<p>某日临近下班,一个同事欲取任何类中获取项目绝对路径,不通过Request方式获取,可是始终获取不到预想的路径。于是晚上回家google了一下,误以为是System.getProperty(“java.class.path”)-未实际进行测试,早上来和同事沟通,提出了使用这个内置方法,结果人家早已验证过,该方法是打印出CLASSPATH环境变量的值。</p>
<p>于是乎,继续google,找到了Class的getResource与getResourceAsStream两个方法。这两个方法会委托给ClassLoader对应的同名方法。以为这样就可以搞定(实际上确实可以搞定),但验证过程中却发生了奇怪的事情。</p>
<p>软件环境:Windows XP、Resin 3、Tomcat6.0、Myeclipse、JDK1.5</p>
<h4>发展</h4>
<p>我的验证思路是这样的:</p>
<ol>
<li>定义一个Servlet,然后在该Servlet中调用Path类的getPath方法,getPath方法返回工程classpath的绝对路径,显示在jsp中。</li>
<li>另外在Path类中,通过Class的getResourceAsStream读取当前工程classpath路径中的a.txt文件,写入到getResource路径下的b.txt。</li>
</ol>
<p>由于时间匆忙,代码没有好好去组织。大致能看出上述两个功能,很简单不做解释。</p>
<p> <a href="/articles/6112.html#more-6112" class="more-link">…</a></p><a href="/articles/6112.html#more-6112" class="more-link">
</a><p class="read-more"><a href="/articles/6112.html#more-6112" class="more-link"></a><a class="btn btn-default" href="/articles/6112.html"> 阅读全文<span class="screen-reader-text"> Read More</span></a></p>
<p></p>
<div id="post-ratings-6112-loading" class="post-ratings-loading"><img src="https://coolshell.cn/wp-content/plugins/wp-postratings/images/loading.gif" width="16" height="16" class="post-ratings-image"/>Loading...</div>
</div>
<footer class="entry-footer">
</footer>
</article>
<nav class="navigation posts-navigation" role="navigation">
<h2 class="screen-reader-text">Posts navigation</h2>
<div class="nav-links">
<div class="row">
<div class="wp-pagenavi" role="navigation">
<span class="pages">第 20 / 74 页</span><a class="first" aria-label="First Page" href="/">« 首页</a><a class="previouspostslink" rel="prev" aria-label="上一页" href="/page/19.html">«</a><span class="extend">...</span><a class="smaller page" title="第 10 页" href="/page/10.html">10</a><span class="extend">...</span><a class="page smaller" title="第 16 页" href="/page/16.html">16</a><a class="page smaller" title="第 17 页" href="/page/17.html">17</a><a class="page smaller" title="第 18 页" href="/page/18.html">18</a><a class="page smaller" title="第 19 页" href="/page/19.html">19</a><span aria-current="page" class="current">20</span><a class="page larger" title="第 21 页" href="/page/21.html">21</a><a class="page larger" title="第 22 页" href="/page/22.html">22</a><a class="page larger" title="第 23 页" href="/page/23.html">23</a><a class="page larger" title="第 24 页" href="/page/24.html">24</a><a class="page larger" title="第 25 页" href="/page/25.html">25</a><span class="extend">...</span><a class="larger page" title="第 40 页" href="/page/40.html">40</a><a class="larger page" title="第 50 页" href="/page/50.html">50</a><a class="larger page" title="第 60 页" href="/page/60.html">60</a><a class="larger page" title="第 70 页" href="/page/70.html">70</a><span class="extend">...</span><a class="nextpostslink" rel="next" aria-label="下一页" href="/page/21.html">»</a><a class="last" aria-label="Last Page" href="/page/74.html">末页 »</a>
</div>
</div>
</div>
</nav>
</main>
</div>
</div>
</div>
</div>
</div>
</body></html>