-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrss.xml
More file actions
205 lines (179 loc) · 11.5 KB
/
Copy pathrss.xml
File metadata and controls
205 lines (179 loc) · 11.5 KB
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
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>scriptExplorer</title>
<description>scriptExplorer</description>
<atom:link href="http://scriptExplorer.me/rss.xml" rel="self" type="application/rss+xml" />
<link>http://scriptExplorer.me</link>
<lastBuildDate>Thu, 01 Jan 2015 00:32:13 +0800</lastBuildDate>
<pubDate>Thu, 01 Jan 2015 00:32:13 +0800</pubDate>
<ttl>1800</ttl>
<item>
<title>web服务端架构</title>
<description><p>在过去的几年里, 我所在的团队做了几个比较大的web项目, 累积了一些web架构经验总结于此, 本文偏向于的宏观设计.</p>
<p>如图:</p>
<p><img src="http://7sbrtd.com1.z0.glb.clouddn.com/blog_web_architectures.png" alt="" /></p>
<ul>
<li>
<p><a href="http://zh.wikipedia.org/wiki/CDN">CDN</a> 和 <a href="http://zh.wikipedia.org/wiki/%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86">Reverse Proxy</a> 一样,都是对内容进行缓存. 不同之处在于CDN部署在网络提供商机房, 而反向代理部署在网站中心机房.
常用的反向代理软件有: <a href="http://nginx.org/">nginx</a> <a href="http://haproxy.com/">haproxy</a> <a href="http://httpd.apache.org/">apache</a> <a href="http://www.squid-cache.org/">squid</a> 我们可以配合 <a href="http://www.keepalived.org/">keepalived</a> 实现高可用.
反向代理 我们使用的是 <a href="http://haproxy.com/">haproxy</a></p>
</li>
<li>
<p>Load Balancing 是指多台服务器提供相同服务,为了提高系统 Availability
常用软件有: <a href="http://haproxy.com/">haproxy</a> <a href="http://www.f5.com.cn/">F5</a> <a href="http://nginx.org/">nginx</a> <a href="http://www.linuxvirtualserver.org/">LVS</a>
我们团队使用 <a href="http://haproxy.com/">haproxy</a> 和 <a href="http://www.linuxvirtualserver.org/">LVS</a></p>
</li>
<li>
<p>Web Server 就是我们的网站了, 一般使用 <a href="http://nginx.org/">nginx</a> <a href="http://httpd.apache.org/">apache</a> <a href="http://tomcat.apache.org/">tomcat</a> <a href="http://www.eclipse.org/jetty/">jetty</a> <a href="resin.caucho.com/">resin</a></p>
</li>
<li>
<p>Service Server 基于Micro services理念,将不同的功能\服务分割开, 构造成高内聚低偶尔的独立模块.便于维护提高扩展力.</p>
</li>
<li>
<p>File System 文件系统,一般系统常用的有<a href="http://zh.wikipedia.org/wiki/RAID">RAID</a> <a href="http://hadoop.apache.org/">Hadoop Fs</a> <a href="http://code.taobao.com">TFS</a></p>
</li>
<li>
<p>RDBMS 关系型数据库 一般使用 <a href="http://mysql.com">Msql</a> <a href="http://www.oracle.com">Oracle</a> <a href="http://www.postgresql.org/">PostgreSQL</a></p>
</li>
<li>
<p>NoSQL 源自互联网的技术手段, 一般都有更好的伸缩性, 我们一般使用 <a href="http://www.mongodb.org">MongoDB</a> <a href="http://couchdb.apache.org/">CouchDB</a> <a href="http://www.hbase.org/">HBase</a> <a href="http://cassandra.apache.org/">Cassandra</a> <a href="http://neo4j.com/">Neo4j</a></p>
</li>
<li>
<p>Cache Server 缓存服务器一般使用 <a href="http://www.memcached.org">Memcached</a> <a href="http://www.redis.io/">Redis</a></p>
</li>
<li>
<p>Search Server 搜索服务器我们一般使用 <a href="http://lucene.apache.org/solr/">Lucene/Solr</a> <a href="http://www.elasticsearch.org/">ElasticSearch</a> <a href="http://sphinxsearch.com/">Sphinx</a></p>
</li>
<li>
<p>Computing Server 一般都会使用MapReduce策略</p>
</li>
</ul>
<h2>Web架构</h2>
<p>在设计一个web项目的架构时,我一般从以下几个方面去考虑。</p>
<h4>横向分层</h4>
<table>
<thead>
<tr>
<th>分层架构</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>视图层</td>
<td>页面展示</td>
</tr>
<tr>
<td>应用层</td>
<td>业务逻辑</td>
</tr>
<tr>
<td>服务层</td>
<td>模块封装</td>
</tr>
<tr>
<td>数据层</td>
<td>数据访问</td>
</tr>
</tbody>
</table>
<h3>纵向分割</h3>
<p>也就是我们常说的Micro services (cell/set架构), 原理是将一个大型系统拆分为N个小型系统。
每个系统通过接口进行通讯.好处是高内聚低偶尔,提高扩展能力.</p>
<h3>分布式</h3>
<p>这里的分布式主要是指 Sharding, 分布式的好处就是提高了服务器的 scale out能力, 而其关键点就是 stateless。
07年我在做股票平台时,当时 使用了tomcat的集群节点广播复制(jboss的配对复制等session状态复制策略情况也类似) 刚开始效果还不错, 后来发现主要问题是 session复制成本太高, 系统不能通过增加更多的机器来达到良好的水平伸缩,因为集群节点间session的 通信会随着节点的增多而开销增大. 因此想要得到更好的系统伸缩性, 就要保证系统的无状态性.
如果做到系统的无状态性呢?
构建passport 服务, 统一用户状态管理.</p>
<h3>集群</h3>
<p>集群主要指的是 Replication. 提高系统的并发能力和 Available能力。</p>
<h3>缓存</h3>
<p>一般来讲当读写比例在2:1以上,我们才会考虑去缓存。
#### 页面缓存
一般静态资源(JS, css, image, html) 会缓存到 CDN 和 反向代理服务器上, 减小WebServer压力.</p>
<h4>数据缓存</h4>
<p>将数据缓存到 本地缓存/分布式缓存 服务器上,以减小数据库压力。</p>
<h3>异步</h3>
<p>业务处理使用pub/sub模式, 可加快服务器响应速度。
请求处理使用pub/sub模式, 可以控制并发峰值。</p>
<h3>自动化</h3>
<p>测试自动化,发布自动化,自动化监控报警, 自动化失效恢复。</p>
<h3>安全</h3>
<p>XSS攻击, 注入攻击, CSRF 攻击, 用户信息加密, 传输加密, 反垃圾信息。</p>
<h3>Other</h3>
<p>我们可以参考一些指标来衡量数据架构,看看是否满足高并发低延迟的目标。</p>
<table>
<thead>
<tr>
<th>操作</th>
<th style="text-align: left">时间</th>
</tr>
</thead>
<tbody>
<tr>
<td>打开一个网站</td>
<td style="text-align: left">3s内算正常</td>
</tr>
<tr>
<td>RDBMS使用索引查询一条记录</td>
<td style="text-align: left">15 ms</td>
</tr>
<tr>
<td>机械硬盘一次寻址定位</td>
<td style="text-align: left">8~10ms</td>
</tr>
<tr>
<td>机械硬盘顺序读取1MB</td>
<td style="text-align: left">20~25ms</td>
</tr>
<tr>
<td>SSD顺序读取1MB</td>
<td style="text-align: left">0.6ms</td>
</tr>
<tr>
<td>Redis读取一个数据</td>
<td style="text-align: left">0.5ms</td>
</tr>
<tr>
<td>LocalCache读取一个数据</td>
<td style="text-align: left">15微秒</td>
</tr>
<tr>
<td>Java native invoke method</td>
<td style="text-align: left">5 微秒</td>
</tr>
</tbody>
</table>
<p>更多请移步: <a href="https://github.com/scriptExplorer/CodingBetter/blob/master/LatencyNumbers.md">LatencyNumbers</a></p>
</description>
<link>http://scriptExplorer.me/2014/12/31/web-server-architectures</link>
<guid>http://scriptExplorer.me/2014/12/31/web-server-architectures</guid>
<pubDate>Wed, 31 Dec 2014 00:00:00 +0800</pubDate>
</item>
<item>
<title>Hello World!</title>
<description><p>Hello World!</p>
<script src="https://gist.github.com/scriptExplorer/2371e8b83c9254ed77f2.js"></script>
<div class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="k">def</span> <span class="nf">foo</span>
<span class="nb">puts</span> <span class="s1">&#39;foo&#39;</span>
<span class="k">end</span></code></pre></div>
<div><pre class="prettyprint lang-c#"><code>public class Hello {
public static void Main() {
Console.WriteLine(&quot;Hello, World! This is a super long line to test the functionality of pygments code highlighting.&quot;);
}
}</code></pre></div>
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><code class="language-javascript" data-lang="javascript">1
2
3</code></pre></div></td><td class="code"><div class="highlight"><pre><span class="kd">function</span> <span class="nx">myFunction</span><span class="p">()</span> <span class="p">{</span>
<span class="nx">alert</span><span class="p">(</span><span class="s2">&quot;Hello World!&quot;</span><span class="p">);</span>
<span class="p">}</span>
</pre></div>
</td></tr></table>
</description>
<link>http://scriptExplorer.me/2013/05/20/hello-world</link>
<guid>http://scriptExplorer.me/2013/05/20/hello-world</guid>
<pubDate>Mon, 20 May 2013 00:00:00 +0800</pubDate>
</item>
</channel>
</rss>