<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>玉面飞龙的BLOG</title>
	<atom:link href="http://www.yumianfeilong.com/feed" rel="self" type="application/rss+xml" />
	<link>http://yumianfeilong.com</link>
	<description>Oracle,Finance,Communication,Family,Hobby</description>
	<pubDate>Fri, 03 Feb 2012 09:37:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
	<language>en</language>
			<item>
		<title>connection rate limiter feature</title>
		<link>http://yumianfeilong.com/html/2012/02/03/545.html</link>
		<comments>http://yumianfeilong.com/html/2012/02/03/545.html#comments</comments>
		<pubDate>Fri, 03 Feb 2012 09:37:41 +0000</pubDate>
		<dc:creator>yumianfeilong</dc:creator>
		
		<category><![CDATA[Boring]]></category>

		<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://yumianfeilong.com/?p=545</guid>
		<description><![CDATA[11g中Listener可以限制每秒能够成功建立的数据库连接数目，通过在listener.ora中设置如下2个参数，然后reload listener。可以用来防止Logon storm。
使用该参数需要注意参数INBOUND_CONNECT_TIMEOUT的设置，以避免发生过多的“ORA-12170: TNS:Connect timeout occurred”错误.

Connection Rate Limiter Parameters

The connection rate limiter  feature in the Oracle Net Listener enables a DBA to limit the number of  new connections handled by the listener. When this feature is enabled,  Oracle Net Listener imposes a user-specified maximum limit on the number  of new connections [...]]]></description>
			<content:encoded><![CDATA[<p>11g中Listener可以限制每秒能够成功建立的数据库连接数目，通过在listener.ora中设置如下2个参数，然后reload listener。可以用来防止<a href="http://www.oracle.com/technetwork/database/enterprise-edition/oraclenetservices-connectionratelim-133050.pdf">Logon storm</a>。</p>
<p>使用该参数需要注意参数INBOUND_CONNECT_TIMEOUT的设置，以避免发生过多的“ORA-12170: TNS:Connect timeout occurred”错误.</p>
<blockquote>
<h2 id="autoId8" class="sect1"><a href="http://docs.oracle.com/cd/E11882_01/network.112/e10835/listener.htm#i503196">Connection Rate Limiter Parameters</a></h2>
</blockquote>
<blockquote><p>The <a id="sthref612" name="sthref612"></a>connection rate limiter  feature in the Oracle Net Listener enables a DBA to limit the number of  new connections handled by the listener. When this feature is enabled,  Oracle Net Listener imposes a user-specified maximum limit on the number  of new connections handled by the listener every second.</p>
<p>Depending on the configuration, the rate can be applied to a collection of endpoints, or to a specific endpoint.</p>
<p>This feature is controlled through the following two <code>listener.ora</code> configuration parameters:</p>
<ul>
<li>
<p style="margin: 0pt;"><a href="http://docs.oracle.com/cd/E11882_01/network.112/e10835/listener.htm#BGBCAFCA">CONNECTION_RATE_<span class="italic">listener name</span></a></p>
</li>
<li>
<p style="margin: 0pt;"><a href="http://docs.oracle.com/cd/E11882_01/network.112/e10835/listener.htm#BGBFBIGD">RATE_LIMIT</a></p>
</li>
</ul>
<p><a id="BGBCAFCA" name="BGBCAFCA"></a></p>
<div class="sect2">
<h3 id="autoId9" class="sect2">CONNECTION_RATE_<span class="italic">listener name</span></h3>
<p class="subhead2"><a id="NETRF1482" name="NETRF1482"></a>Purpose</p>
<p><a id="sthref613" name="sthref613"></a><a id="sthref614" name="sthref614"></a>To  specify a global rate that is enforced across all listening endpoints  that are rate-limited. When this parameter is specified, it overrides  any endpoint-level numeric rate values that might be specified.</p>
<p class="subhead2"><a id="NETRF1483" name="NETRF1483"></a>Syntax</p>
<pre class="oac_no_warn">CONNECTION_RATE_<span class="italic">listener_name</span>=<span class="italic">number_of_connections_per_second</span></pre>
</div>
<p><a id="BGBFBIGD" name="BGBFBIGD"></a></p>
<h3 id="autoId10" class="sect2">RATE_LIMIT</h3>
<p class="subhead2"><a id="NETRF1484" name="NETRF1484"></a>Purpose</p>
<p><a id="sthref615" name="sthref615"></a><a id="sthref616" name="sthref616"></a>To indicate that a particular listening endpoint is rate limited. The parameter is specified in the <code>ADDRESS</code> section of the listener endpoint configuration.</p>
<p class="subhead2"><a id="NETRF1485" name="NETRF1485"></a>Syntax</p>
<pre class="oac_no_warn">LISTENER= (ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521)(RATE_LIMIT=yes))
)</pre>
<ul>
<li>When the <code>RATE_LIMIT</code> parameter is set to <code>yes</code>, the end-point is included in the enforcement of a listener-wide connection rate. This is used with the <code>CONNECTION_RATE_</code><code><span class="codeinlineitalic">listener_name</span></code> parameter.</li>
<li>When the <code>RATE_LIMIT</code> parameter is set to a value greater than <code>0</code>, the rate limit is enforced at that endpoint level.</li>
</ul>
<p class="subhead2"><a id="NETRF1486" name="NETRF1486"></a>Examples</p>
<p>The following examples use the <code>CONNECTION_RATE_</code><code><span class="codeinlineitalic">listener name</span></code> and <code>RATE_LIMIT</code> parameters.</p>
<p>Example 1</p>
<pre class="oac_no_warn">CONNECTION_RATE_LISTENER=10
LISTENER=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521)(RATE_LIMIT=yes))
(ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1522)(RATE_LIMIT=yes))
(ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1523))
)</pre>
<p>In the preceding example, the total number of new connections through  ports 1521 and 1522 is limited at 10 every second. Connections through  port 1523 are not limited and do not count towards the overall rate of  10 connections every second.</p>
<p>Example 2</p>
<pre class="oac_no_warn">LISTENER= (ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521)(RATE_LIMIT=5))
(ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1522)(RATE_LIMIT=10))
(ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1523))
)</pre>
<p>In the preceding example, the connection rates are enforced at the  endpoint level. A maximum of 5 connections are processed through port  1521 every second. The limit for connections through port 1522 is 10  every second. Connections through port 1523 are not limited.</p></blockquote>
<p>我在11gr2中测试，如上example 1的设置reload listener后能够起作用；example 2的设置reload &amp; restart listener后不起作用。</p>
]]></content:encoded>
			<wfw:commentRss>http://yumianfeilong.com/html/2012/02/03/545.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>DNS</title>
		<link>http://yumianfeilong.com/html/2012/01/18/544.html</link>
		<comments>http://yumianfeilong.com/html/2012/01/18/544.html#comments</comments>
		<pubDate>Wed, 18 Jan 2012 07:42:50 +0000</pubDate>
		<dc:creator>yumianfeilong</dc:creator>
		
		<category><![CDATA[Boring]]></category>

		<category><![CDATA[DNS]]></category>

		<guid isPermaLink="false">http://yumianfeilong.com/?p=544</guid>
		<description><![CDATA[在CAP理论中，DNS占据了AP(Availability &#38; partition).
按照数据库的思想来说，DNS可以说是分布式的，层次结构的，KEY-VALUE的，高可用的系统。
分布式和层次结构

网址www.yumianfeilong.com，其实就是www.yumianfeilong.com. (末尾有个&#8221;.&#8221;，表示root). &#8220;.&#8221;就是Root, &#8220;.com&#8221;就是TLD DNS， ”.com.yumianfeilong“是次级DNS. &#8220;www&#8221;可以说是该次级DNS内的一台server。
每个层次的DNS存储下一级DNS的地址。这样当要查找一个DNS对应的IP时候，可以查找root dns得到下一级DNS，再去下一级DNS递归查找。
分布式查询

DNS查询最常见的2种方式:Recursive queries:和Iterative (or nonrecursive) queries。如上为Recursive模式，表示为客户端的DNS解析完全由DNS resolve代劳，具体步骤如下：
1. A user types the URL http://www.example.com into a browser.
2. The browser sends a request for the IP address of www.example.com to its local
resolver (stub-resolver).
3. The stub-resolver queries the locally configured DNS Resolver for the IP
address of www.example.com.
4. The DNS Resolver [...]]]></description>
			<content:encoded><![CDATA[<p>在CAP理论中，DNS占据了AP(Availability &amp; partition).</p>
<p>按照数据库的思想来说，DNS可以说是分布式的，层次结构的，KEY-VALUE的，高可用的系统。</p>
<p><strong>分布式和层次结构</strong><br />
<img src="http://pic.yupoo.com/yumianfeilong/BG47HDTk/medish.jpg" alt="DNS的层次结构和分布式结构" /></p>
<p>网址www.yumianfeilong.com，其实就是<strong>www.yumianfeilong.com. </strong>(末尾有个&#8221;.&#8221;，表示root). &#8220;.&#8221;就是Root, &#8220;.com&#8221;就是TLD DNS， ”.com.yumianfeilong“是次级DNS. &#8220;www&#8221;可以说是该次级DNS内的一台server。</p>
<p>每个层次的DNS存储下一级DNS的地址。这样当要查找一个DNS对应的IP时候，可以查找root dns得到下一级DNS，再去下一级DNS递归查找。</p>
<p><strong>分布式查询</strong><br />
<img src="http://pic.yupoo.com/yumianfeilong/BG47MADn/medish.jpg" alt="DNS查询" /></p>
<p>DNS查询最常见的2种方式:Recursive queries:和Iterative (or nonrecursive) queries。如上为Recursive模式，表示为客户端的DNS解析完全由DNS resolve代劳，具体步骤如下：</p>
<blockquote><p>1. A user types the URL http://www.example.com into a browser.<br />
2. The browser sends a request for the IP address of www.example.com to its local<br />
resolver (stub-resolver).<br />
3. The stub-resolver queries the locally configured DNS Resolver for the IP<br />
address of www.example.com.<br />
4. The DNS Resolver looks up www.example.com in local tables (its cache), but it<br />
isn’t found.<br />
5. The DNS Resolver sends a query to a root-server for the IP (the A RR) of<br />
www.example.com.<br />
6. The root-server only supports iterative (nonrecursive) queries (see the<br />
upcoming section “Iterative (Nonrecursive) Queries”) and answers with a list of<br />
name servers that are authoritative for the next level in the domain name<br />
hierarchy, which in this case is the gTLD .com (this is called a referral).<br />
7. The DNS Resolver selects one of the authoritative gTLD servers received in the<br />
previous referral and sends it a query for the IP of www.example.com.<br />
8. The gTLD name server only supports iterative queries and answers with the<br />
authoritative name servers for the Second-Level Domain (SLD) example.com (a<br />
referral).<br />
9. The DNS Resolver selects one of the authoritative DNS servers for example.com<br />
from the previous referral and sends it a query for the IP (the A RR) of<br />
www.example.com.<br />
10. The zone file for example.com defines www.example.com as a CNAME record (an<br />
alias) for joe.example.com. The authoritative name server answers with the<br />
www.example.com CNAME RR and, in this case, the A RR for joe.example.com,<br />
which we will assume is 192.168.254.2.<br />
11. The DNS Resolver sends the response joe.example.com=192.168.254.2<br />
(together with the CNAME RR www=joe) to the original client stub-resolver.<br />
12. The stub-resolver sends www.example.com=192.168.254.2 to the user’s browser.<br />
13. The browser sends a request to 192.168.254.2 for the web page.</p></blockquote>
<p><strong>KEY-VALUE</strong></p>
<p>显而易见，查询域名，返回IP，也可以查询IP，返回域名（Reverse Mapping）。nslookup和dig都是常用的命令。</p>
<blockquote><p><strong>nslookup yumianfeilong.com.</strong></p>
<p>Non-authoritative answer:<br />
Name:   yumianfeilong.com<br />
Address: 69.163.181.118</p>
<p><strong>nslookup 69.163.181.118</strong></p>
<p>Non-authoritative answer:<br />
118.181.163.69.in-addr.arpa     name = apache2-bongo.yerevan.dreamhost.com.</p>
<p>Authoritative answers can be found from:<br />
181.163.69.in-addr.arpa nameserver = ns1.dreamhost.com.<br />
181.163.69.in-addr.arpa nameserver = ns3.dreamhost.com.<br />
181.163.69.in-addr.arpa nameserver = ns2.dreamhost.com.<br />
ns1.dreamhost.com       internet address = 66.33.206.206<br />
ns2.dreamhost.com       internet address = 208.96.10.221<br />
ns3.dreamhost.com       internet address = 66.33.216.216</p></blockquote>
<p><span id="more-544"></span><br />
其中DNS Reverse Mapping通过保留域名<strong>&#8220;IN-ADDR.ARPA.&#8221;</strong> (IPV4)实现。实现方式和查询某个域名的IP地址类似，也有Recursive 和non-Recursive 方式。<br />
<img src="http://pic.yupoo.com/yumianfeilong/BG47L8ri/medish.jpg" alt="" /></p>
<p>如下为Recursive方式查询IP地址192.168.250.15对应的域名。<br />
<img src="http://pic.yupoo.com/yumianfeilong/BG47NHaE/medish.jpg" alt="" /></p>
<p>reverse mappting的设计思路在某些应用设计中或许有借鉴意义。</p>
<p><strong>高可用性</strong></p>
<p>自然是复制，Master-Slave模式。 这也部分导致了难于实现<strong>实时一致性</strong>。在master上做了DNS改动后，需要一些时间Push到slave上和其他有cache过期DNS记录的DNS上。<br />
<img src="http://pic.yupoo.com/yumianfeilong/BG47OvMk/medish.jpg" alt="" /></p>
<p>内容参考<a href="http://book.douban.com/subject/2667243/"><span>Pro DNS and BIND</span></a></p>
]]></content:encoded>
			<wfw:commentRss>http://yumianfeilong.com/html/2012/01/18/544.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>每天学点经济学(2)</title>
		<link>http://yumianfeilong.com/html/2012/01/15/543.html</link>
		<comments>http://yumianfeilong.com/html/2012/01/15/543.html#comments</comments>
		<pubDate>Sun, 15 Jan 2012 13:16:18 +0000</pubDate>
		<dc:creator>yumianfeilong</dc:creator>
		
		<category><![CDATA[Favorites]]></category>

		<category><![CDATA[经济]]></category>

		<guid isPermaLink="false">http://yumianfeilong.com/?p=543</guid>
		<description><![CDATA[我想:貌似多知道点经济或者金融或者管理方面的概念，就可以多从中受益一样&#8211;比方说投资A股。唉。
你为什么总是原地踏步——内卷化效应
以前看过介绍日本一家专门做10分钟快速平价理发公司的文章，那个文章说凡是在该公司工作超过5年的理发师一律领N+3辞退(可以出去开分店但不让在原店面理发了)，以保证理发的质量，用学术语言来描述，就是为了避免内卷化的一种手段。
‘内卷化‛意指一个社会既无突变式的发展，也无渐进式的增长，长期以来，只是在一个层面上自我消耗和自我重复。大到一个社会，小至一个自我，一旦陷入内卷化状态，即似身陷泥沼，无力前进。
人们常说，信念决定命运。如果一个人认为自己这一生只能如此，那么命运基本上也就不会再有改变，生活就此充满自怨自艾；如果相信自己还能有一番作为，并付诸行动，那么便可能大有斩获。正像运动员所说的，‚拼搏不一定会得到，不拼搏一定会得不到。
走出职场的内卷化，要靠自身力量。这种力量来自于强烈的求知欲望和顽强的上进精神。只有充分发挥自身力量，才能突破自我、表现自我、超越自我，从而使得职业生涯呈现出一片勃勃生机。
税赋到底由谁承担——税赋归宿
提倡理性消费，别被商家促销广告打折女友所洗脑。争做理性人并且争取探索透明的信息。
在这里需要指出的一个原则是，只要消费，就会纳税，我们每一个消费者都是纳税人。到目前为止，我国共有22种税（包括增值税、消费税、营业税、企业所得税、个人所得税、资源税、房产税、城市维护建设税、城市房地产税、城镇土地使用税、土地增值税、耕地占用税、车辆购置税、车船税、契税、印花税、烟叶税、关税、船舶吨税等）。在这些名目繁多的税当中，有些是由个人上缴的，有些是由企业上缴的。
曾有一份研究报告指出，在我国，假如1袋1公斤的盐价格为2元，其中就包含大约0.29元的增值税和大约0.03元的城建税。而每瓶3元的啤酒包含大约0.44元的增值税、0.12元的消费税和0.06元的城建税。如果你花100元买了一件衣服，其中包含14.53元的增值税和1.45元的城建税。如果花l00元买一瓶化妆品，其中除14.53元的增值税外，还包含25.64元的消费税和4.02元的城建税。如果你吸烟，每包烟8元，其中大约4.70元是消费税、增值税和城建税。如果去餐馆吃饭，最后结账时不论多少，餐费的5.5%是营业税及城建税。你如果使用一次性木筷，还会包括些许消费税。你去理发店理发，同样，费用的5.5%是营业税及城建税……总之，一个人只要生活在社会中，只要有购买行为，就免不了交税。
少数服从多数‛的危险——阿罗不可能性定理
很多公司在招聘的时候，面试者往往会被群面。如果一个面试官否定了，就算其他所有的面试官都OK，这个应聘者也会被Pass。
阿罗不可能性定理的基本内容是：如果众多的社会成员有着不同的偏向，同时又要在多种方案之间作出选择，那么仅仅依靠民主制度，将不会得到让所有人都满意的结果。
在企业管理中，有时却会遇到一些特殊的情况，会发现‚投票决定‛并不适用。比如，五个年轻人合伙投资开了一家鲜花礼品店，各自的投资金额也大体相当。那么，他们对礼品店是如何管理的呢？由于他们当中没有‚大股东‛，按照股份比例决定话语权是不可能的。那么，在作出某项决策时，实行‚少数服从多数‛的原则举手来表决，可不可以呢？表面看来，这种方法是可行的，因为不会出现支持方和反对方人数相等的局面，最多也就是三比二。然而，这几个股东的实际做法却并非如此，恰恰相反，他们采取的是：‚所有决策，只要有一人反对，便不能通过‛。原来，在这时实行的是‚多数服从少数‛的原则——我们应该承认，他们的做法是一种智慧的体现。
作为企业，管理者的决策将直接影响企业的发展，如果此时采用投票办法，少数服从多数，将很可能使企业陷入巨大的风险。企业运作，关键是每一个环节都能顺利完成，这样才能达到最终的目的。试想，假设在其中至少有一个投资人不同意的情况下执行决策，这个反对者就成了鲜花店最危险的环节。不难想象，一个认为决策不可能成功的人，一个投反对票的人，在执行时的干劲、结果将会怎样。
以上3个概念和企业管理，个人职业发展，理财靠的更紧密先。
]]></description>
			<content:encoded><![CDATA[<p>我想:貌似多知道点经济或者金融或者管理方面的概念，就可以多从中受益一样&#8211;比方说投资A股。唉。</p>
<p><strong>你为什么总是原地踏步——内卷化效应</strong></p>
<p>以前看过介绍日本一家专门做10分钟快速平价理发公司的文章，那个文章说凡是在该公司工作超过5年的理发师一律领N+3辞退(可以出去开分店但不让在原店面理发了)，以保证理发的质量，用学术语言来描述，就是为了避免内卷化的一种手段。</p>
<blockquote><p>‘内卷化‛意指一个社会既无突变式的发展，也无渐进式的增长，长期以来，只是在一个层面上自我消耗和自我重复。大到一个社会，小至一个自我，一旦陷入内卷化状态，即似身陷泥沼，无力前进。</p>
<p>人们常说，信念决定命运。如果一个人认为自己这一生只能如此，那么命运基本上也就不会再有改变，生活就此充满自怨自艾；如果相信自己还能有一番作为，并付诸行动，那么便可能大有斩获。正像运动员所说的，‚拼搏不一定会得到，不拼搏一定会得不到。</p>
<p>走出职场的内卷化，要靠自身力量。这种力量来自于强烈的求知欲望和顽强的上进精神。只有充分发挥自身力量，才能突破自我、表现自我、超越自我，从而使得职业生涯呈现出一片勃勃生机。</p></blockquote>
<p><strong>税赋到底由谁承担——税赋归宿</strong></p>
<p>提倡理性消费，<strong>别被商家促销广告打折女友所洗脑</strong>。争做理性人并且争取探索透明的信息。</p>
<blockquote><p>在这里需要指出的一个原则是，只要消费，就会纳税，我们每一个消费者都是纳税人。到目前为止，我国共有22种税（包括增值税、消费税、营业税、企业所得税、个人所得税、资源税、房产税、城市维护建设税、城市房地产税、城镇土地使用税、土地增值税、耕地占用税、车辆购置税、车船税、契税、印花税、烟叶税、关税、船舶吨税等）。在这些名目繁多的税当中，有些是由个人上缴的，有些是由企业上缴的。</p>
<p>曾有一份研究报告指出，在我国，假如1袋1公斤的盐价格为2元，其中就包含大约0.29元的增值税和大约0.03元的城建税。而每瓶3元的啤酒包含大约0.44元的增值税、0.12元的消费税和0.06元的城建税。如果你花100元买了一件衣服，其中包含14.53元的增值税和1.45元的城建税。如果花l00元买一瓶化妆品，其中除14.53元的增值税外，还包含25.64元的消费税和4.02元的城建税。如果你吸烟，每包烟8元，其中大约4.70元是消费税、增值税和城建税。如果去餐馆吃饭，最后结账时不论多少，餐费的5.5%是营业税及城建税。你如果使用一次性木筷，还会包括些许消费税。你去理发店理发，同样，费用的5.5%是营业税及城建税……总之，一个人只要生活在社会中，只要有购买行为，就免不了交税。</p></blockquote>
<p><strong>少数服从多数‛的危险——阿罗不可能性定理</strong></p>
<p>很多公司在招聘的时候，面试者往往会被群面。如果一个面试官否定了，就算其他所有的面试官都OK，这个应聘者也会被Pass。<strong></strong></p>
<blockquote><p><strong>阿罗不可能性定理</strong>的基本内容是：如果众多的社会成员有着不同的偏向，同时又要在多种方案之间作出选择，那么仅仅依靠民主制度，将不会得到让所有人都满意的结果。</p>
<p>在企业管理中，有时却会遇到一些特殊的情况，会发现‚投票决定‛并不适用。比如，五个年轻人合伙投资开了一家鲜花礼品店，各自的投资金额也大体相当。那么，他们对礼品店是如何管理的呢？由于他们当中没有‚大股东‛，按照股份比例决定话语权是不可能的。那么，在作出某项决策时，实行‚少数服从多数‛的原则举手来表决，可不可以呢？表面看来，这种方法是可行的，因为不会出现支持方和反对方人数相等的局面，最多也就是三比二。然而，这几个股东的实际做法却并非如此，恰恰相反，他们采取的是：‚所有决策，只要有一人反对，便不能通过‛。原来，在这时实行的是‚多数服从少数‛的原则——我们应该承认，他们的做法是一种智慧的体现。</p>
<p>作为企业，管理者的决策将直接影响企业的发展，如果此时采用投票办法，少数服从多数，将很可能使企业陷入巨大的风险。企业运作，关键是每一个环节都能顺利完成，这样才能达到最终的目的。试想，假设在其中至少有一个投资人不同意的情况下执行决策，这个反对者就成了鲜花店最危险的环节。不难想象，一个认为决策不可能成功的人，一个投反对票的人，在执行时的干劲、结果将会怎样。</p></blockquote>
<p>以上3个概念和企业管理，个人职业发展，理财靠的更紧密先。</p>
]]></content:encoded>
			<wfw:commentRss>http://yumianfeilong.com/html/2012/01/15/543.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>一起来每天学点经济学（1）</title>
		<link>http://yumianfeilong.com/html/2012/01/10/542.html</link>
		<comments>http://yumianfeilong.com/html/2012/01/10/542.html#comments</comments>
		<pubDate>Tue, 10 Jan 2012 09:21:34 +0000</pubDate>
		<dc:creator>yumianfeilong</dc:creator>
		
		<category><![CDATA[Book]]></category>

		<category><![CDATA[economy]]></category>

		<category><![CDATA[经济学]]></category>

		<category><![CDATA[Kindle]]></category>

		<guid isPermaLink="false">http://yumianfeilong.com/?p=542</guid>
		<description><![CDATA[前几天花600买了个Kindle4，本来打算看些计算机相关的pdf，不过看Pdf明显6寸的屏幕太小，翻页看十分的累人，无法调整合适的字体(适应屏幕等)，目前为止，也就几天，死机1次，自动关机1次；推荐大家不要购买6寸的阅读器，要买就买大的，最好和A4纸一般大的那种。
概况“每天学点经济学” 中一些有意思的理论。
收入的差距是如何形成的——二八定律 &#8212; 这本书就符合该理论

二八定律‛存在于生活的方方面面，体现的是不平衡，差异化的问题。‚二八定律‛提醒我们去思索，怎样付出更少，既能获得个人成功，又能获得事业成功；怎样做得更少，既能享受幸福生活，又能实现生命价值。
在任何一组东西中，最重要的只占其中一小部分，约20%，其余80%尽管是多数，却是次要的
富人总是占少数，穷人总是占多数。他们两者的比例一般会保持在20：80左右。
20%的人占有80%的财富
两个人投入同样的8个小时，而产出的成果是绝对不一样的。员工工作了8小时获得的报酬是100元，而老板工作了8小时获得的报酬是1万元。
对一个企业来说，顾客中的约20%占有营业额的80%左右，而他们就是所谓的‚贵客‛。如果公司发现约20%的产品带来了约80%的利润，那么这家公司就应该集中精力予这些利润高的产品。
一本书约80%的价值，已经在约20%的页数中就已经阐明了，所以只要看完整部书的20%左右就可以了。当然这种看法不能适用于阅读所有的书籍，对有些书还是要从头到尾细细阅读的。
股市中有80%的投资者只想着怎么赚钱，仅有20%的投资者考虑到赔钱时的应变策略。但结果是只有那20%的投资者能长期赢利，而80%的投资者却常常赔钱。对于投资者来说，如果能吃透‚二八定律‛的精髓，把它应用于股市，赚钱就会变得很轻松。
你买，我也跟着买——示范效应
facebook?微博控？广告？买了kindle后悔了？物联网？大众点评网？
在日常生活中，我们常常会发现这种现象：当你的同事或者邻居买了某种商品，引得其他人羡慕的时候，你也会跟着购买这种商品。
由此可见，人们的消费行为不但受收入水平的影响，而且受其他人——主要是那些收入与其相近的人——消费行为的影响。这就是示范效应在起作用。
示范效应往往是双向的，这就是所谓‚坏‛榜样和‚好‛榜样所起的影响。从动态上看，示范效应最终会使少数成为主流。
消费者在认识和处理自己的收入与消费及其相互关系时，会和其他消费者相比较。例如，单位组织向贫困地区捐款，这对捐款的人来说当然是消费支出。有些人在这时不一定是看自己收入的高低，而是会先看看周围的人捐了多少。他们会根据自己的判断，觉得自己应该跟哪些人捐一样多。即使他的收入高点，他也不会多捐，他担心有出风头的嫌疑。即使他的收入较低，他也要向某一部分人看齐，甚至会‚打肿脸充胖子‛，他不愿意别人说他小气。从理论上讲，这里所表现的就是消费的示范效应。这就使我们看到消费者分成了许多群体，有许多消费者自觉不自觉地把自己算在一定的群体内，他的消费向这个群体内的其他人看齐。
在市场环境下，特别是在商品供应比较丰富的情况下，消费的示范效应表现得越来越明显，对市场供求关系起着比较大的影响，比如说有人看到别人的衣服漂亮，不管自己穿着好不好看，也要千方百计买一套穿在自己身上。‚名牌效应‛也是示范效应的典型现象，这完全可以解释为什么各种商家要不惜重金聘请‚明星‛做商品广告的缘故了。
在现代社会中，示范效应随时都左右着人们的经济生活，以及消费习惯。当消费者看到有些人因收入水平或消费习惯的变化而购买高档消费品时，尽管自己的收入没有变化，也可能仿效他人扩大自己的消费开支，或者在收入下降时也不愿减少自己的消费支出。示范效应甚至可以跨越国界，当某国居民接触到别国居民购买高档消费品时，他们可能会仿效别国居民从而改变自己的消费习惯。于是，消费的示范效应会造成低收入水平国家居民的消费需求远远超出他们正常的水平，从而导致储蓄不足和国际收支严重逆差等问题。
经济学研究的基石——经济学假设
假设永远不会成为现实的
理性经济人、资源稀缺、完全信息这三个基本的假设，为经济学的分析力、决策力提供了现实的前提条件和基础，因而我们在学习经济学的时候就必须了解这些假设
7年之痒 &#8212; 扩展的边际效用
同样，边际效用递减的原理广泛地存在于日常生活中
边际效用是一个经济学概念。物品都有用，人们消费物品后获得效用。每多消费一个单位量的物品，都能多获得一些额外效用，这些额外效用就叫做边际效用。边际效用在应用的过程中，有一个递减的作用，叫做边际效用递减。
比如说工作，为什么新人的干劲很大，而过几年大家都意志消沉、尽显沧桑了？这就是因为如果一个人在一段时间以内一直做同样的工作，那么工作带给他的新鲜感和满足度是一直边际递减的
还有在婚姻中，之所以会有喜新厌旧的说法，就是由于边际效用递减的缘故。。那么对于生性喜欢追求刺激的人来说这样的生活太没有挑战意义，那么婚姻中的他很有可能通过外在异性的获得来填充这种需求。所以，保持婚姻持久的最好方法就是保持婚姻的新鲜度，让感情常新。
从高处看外包
外包的方式在企业中应用最为广泛。外包将企业解放出来以更专注于核心业务。外包合作伙伴为企业带来知识，增加后备管理时间。在执行者专注于其特长业务时，为其改善产品的整体质量。
但是，在现实应用中，有些企业或人对外包产生了错误的认识。他们认为‚把不懂的业务全部包出去已经成为企业管理新思潮‛。这是一个非常普遍又危险的误区。对于企业，自身对包出去的业务，可以‚不专‛，但不能‚不懂‛。‚不专‛与，‚不懂‛是有很大区别的。。如果企业对外包出去的业务‚不懂‛，很容易就会丧失对业务的监控、管理和对结果的考核能力，最终所得到的结果就会与初衷背道而驰。‚不懂业务‛从另一个层面来说是指不具备和服务供应商的议价能力，如此一来又如何达成降低成本的目的呢？
众多的研究表明，服务发包商与服务供应商之间最为良好的关系，并不是简单的买卖关系，而是一种合作伙伴关系。一旦外包服务合同关系成立，随之就要确立外包项目的管理模式，要建立诸如项目管理的组织结构、职责界定、交流机制和交流渠道等一系列的内容。如果是长期项目，还要有不断总结改进的机制。这一系列的复杂情况决定了简单的买卖关系很难产生成功的服务外包结果
破窗效应
有点类似示范效应；不过这个是不好的示范效应。
有一家理发店的窗户玻璃破了一个角，由于生意非常红火，老板没有时间去修理它。有一天夜里，一个小男孩路过理发店，看见破了一个角的窗户，就拿起一块石头砸过去，大半截玻璃稀里哗啦地掉了下来。等老板追出来的时候，小男孩已经跑远了。老板想换掉玻璃，可由于马上要过节了，理发的人很多，他非常忙，根本没时间。那扇掉了大半截玻璃的窗户依旧破裂着。过了几天，老板正在里边忙碌着，突然听见‚啪‛的一声，那扇半截玻璃被完全打碎了。等老板追出来的时候，只看见了两个跑远了的孩子的背影。
不得已老板抽出时间装了一块新的玻璃。为了防止玻璃再被打碎，老板只要有时间就站在窗户后面，企图逮住打碎玻璃的小孩。可令他奇怪的是，此后再也没有小孩来打碎他的窗户玻璃了。
这个小故事反映了这样一个道理：如果有人打坏了一栋建筑上的一块玻璃，又没有及时修复，别人就可能受到某些暗示性的纵容，去打碎更多的玻璃。久而久之，这些窗户就给人造成一种无序的感觉，在这种麻木不仁的氛围中，就会出现更多破坏性的行为。这就是政治学家威尔逊和犯罪学家凯琳提出的‚破窗效应‛
对于违反公司程序或廉政规定的行为，有关组织没有进行严肃处理，没有引起员工的重视，从而使类似行为再次甚至多次重复发生
而在一个很干净的地方，人们会很不好意思扔垃圾，但是一旦地上有垃圾出现，人们就会毫不犹豫地随地乱扔垃圾，丝毫不觉得羞愧
在公交车站，如果大家都井然有序地排队上车，又有多少人会不顾众人的文明举动和鄙夷眼光而贸然插队？与这相反，车辆尚未停稳，猴急的人们你推我拥，争先恐后，后来的人如果想排队上车，恐怕也没有耐心了。这些都是‚破窗效应‛的表现。
在管理实践中，管理者必须高度警觉那些看起来是个别的、轻微的‚小过错‛，并坚持严格依法管理。‚千里之堤，溃于蚁穴。‛不及时修好第一扇被打碎玻璃的窗户，就可能会带来无法弥补的损失。而如果能及时修复，则效果会非常明显
消费PK节俭——节俭悖论
现在明显是内需不足，产能过剩
18世纪，荷兰的曼德维尔博士在《蜜蜂的寓言》一书中讲过一个有趣的故事。一群蜜蜂为了追求豪华的生活，大肆挥霍，结果这个蜂群很快兴旺发达起来。而后来，由于这群蜜蜂改变了习惯，放弃了奢侈的生活，崇尚节俭，结果却导致了整个蜜蜂群体的衰败。
蜜蜂的故事说的就是‚节俭的逻辑‛，在经济学上叫‚节俭悖论‛。在西方经济学说史上，经济学家凯恩斯从故事中却看到了刺激消费和增加总需求对经济发展的积极作用，受此启发，他进一步论证了节俭悖论。
根据凯恩斯的总需求决定国民收入的理论，节俭对于经济增长并没有什么好处。实际上，这里蕴涵着一个矛盾：公众越节俭，降低消费，增加储蓄，往往会导致社会收入的减少。因为，人们的收入通常有两种用途——消费和储蓄，而消费与储蓄成反方向变动，即消费增加储蓄就会减少，消费减少储蓄就会增加。所以，储蓄与国民收入呈现反方向变动，储蓄增加国民收入就减少，储蓄减少国民收入就增加。根据这种看法，增加消费减少储蓄会通过增加总需求而引起国民收入增加，就会促进经济繁荣；反之，就会导致经济萧条。由此可以得出一个蕴涵逻辑矛盾的推论：节制消费增加储蓄会增加个人财富，对个人是件好事，但由于会减少国民收入引起萧条，对整个国民经济发展却是件坏事。
节俭悖论告诉我们：节俭减少了支出，迫使厂家削减产量，解雇工人，从而减少了收入，最终减少了储蓄。储蓄为个人致富铺平了道路，然而如果整个国家加大储蓄，将使整个社会陷入萧条和贫困。也就是说，在资源没有得到充分运用、经济没有达到潜在产出的情况下，只有社会每个成员都尽可能多地消费，整个经济才能走出低谷，迈向更加充分就业、经济繁荣的阶段。
总之，我们要辩证地看待节俭和消费的问题。像本书开头案例中王先生的父亲和儿子，他们的观点都对，但又都不全对。这里关键是一个度的把握问题。节俭是中华民族的传统美德，但并不是不去消费；而
消费也不是奢侈地去浪费。我们要大力提倡理性消费，也要理直气壮地反对盲目消费。
]]></description>
			<content:encoded><![CDATA[<p>前几天花600买了个Kindle4，本来打算看些计算机相关的pdf，不过看Pdf明显6寸的屏幕太小，翻页看十分的累人，无法调整合适的字体(适应屏幕等)，目前为止，也就几天，死机1次，自动关机1次；推荐大家不要购买6寸的阅读器，要买就买大的，最好和A4纸一般大的那种。</p>
<p>概况<a href="http://book.douban.com/subject/3353137/">“每天学点经济学”</a> 中一些有意思的理论。</p>
<p><strong>收入的差距是如何形成的——二八定律 &#8212; 这本书就符合该理论<br />
</strong></p>
<p>二八定律‛存在于生活的方方面面，体现的是不平衡，差异化的问题。‚二八定律‛提醒我们去思索，怎样付出更少，既能获得个人成功，又能获得事业成功；怎样做得更少，既能享受幸福生活，又能实现生命价值。</p>
<blockquote><p>在任何一组东西中，最重要的只占其中一小部分，约20%，其余80%尽管是多数，却是次要的</p>
<p>富人总是占少数，穷人总是占多数。他们两者的比例一般会保持在20：80左右。</p>
<p>20%的人占有80%的财富</p>
<p>两个人投入同样的8个小时，而产出的成果是绝对不一样的。员工工作了8小时获得的报酬是100元，而老板工作了8小时获得的报酬是1万元。</p>
<p>对一个企业来说，顾客中的约20%占有营业额的80%左右，而他们就是所谓的‚贵客‛。如果公司发现约20%的产品带来了约80%的利润，那么这家公司就应该集中精力予这些利润高的产品。</p>
<p>一本书约80%的价值，已经在约20%的页数中就已经阐明了，所以只要看完整部书的20%左右就可以了。当然这种看法不能适用于阅读所有的书籍，对有些书还是要从头到尾细细阅读的。</p>
<p>股市中有80%的投资者只想着怎么赚钱，仅有20%的投资者考虑到赔钱时的应变策略。但结果是只有那20%的投资者能长期赢利，而80%的投资者却常常赔钱。对于投资者来说，如果能吃透‚二八定律‛的精髓，把它应用于股市，赚钱就会变得很轻松。</p></blockquote>
<p><strong>你买，我也跟着买——示范效应</strong></p>
<p>facebook?微博控？广告？买了kindle后悔了？物联网？大众点评网？</p>
<blockquote><p>在日常生活中，我们常常会发现这种现象：当你的同事或者邻居买了某种商品，引得其他人羡慕的时候，你也会跟着购买这种商品。</p>
<p>由此可见，人们的消费行为不但受收入水平的影响，而且受其他人——主要是那些收入与其相近的人——消费行为的影响。这就是示范效应在起作用。</p>
<p>示范效应往往是双向的，这就是所谓‚坏‛榜样和‚好‛榜样所起的影响。从动态上看，<strong>示范效应最终会使少数成为主流。</strong></p>
<p>消费者在认识和处理自己的收入与消费及其相互关系时，会和其他消费者相比较。例如，单位组织向贫困地区捐款，这对捐款的人来说当然是消费支出。有些人在这时不一定是看自己收入的高低，而是会先看看周围的人捐了多少。他们会根据自己的判断，觉得自己应该跟哪些人捐一样多。即使他的收入高点，他也不会多捐，他担心有出风头的嫌疑。即使他的收入较低，他也要向某一部分人看齐，甚至会‚打肿脸充胖子‛，他不愿意别人说他小气。从理论上讲，这里所表现的就是消费的示范效应。这就使我们看到消费者分成了许多群体，有许多消费者自觉不自觉地把自己算在一定的群体内，他的消费向这个群体内的其他人看齐。</p>
<p>在市场环境下，特别是在商品供应比较丰富的情况下，消费的示范效应表现得越来越明显，对市场供求关系起着比较大的影响，比如说有人看到别人的衣服漂亮，不管自己穿着好不好看，也要千方百计买一套穿在自己身上。‚名牌效应‛也是示范效应的典型现象，这完全可以解释为什么各种商家要不惜重金聘请‚明星‛做商品广告的缘故了。</p>
<p>在现代社会中，示范效应随时都左右着人们的经济生活，以及消费习惯。当消费者看到有些人因收入水平或消费习惯的变化而购买高档消费品时，尽管自己的收入没有变化，也可能仿效他人扩大自己的消费开支，或者在收入下降时也不愿减少自己的消费支出。示范效应甚至可以跨越国界，当某国居民接触到别国居民购买高档消费品时，他们可能会仿效别国居民从而改变自己的消费习惯。于是，消费的示范效应会造成低收入水平国家居民的消费需求远远超出他们正常的水平，从而导致储蓄不足和国际收支严重逆差等问题。</p></blockquote>
<p><strong>经济学研究的基石——经济学假设</strong></p>
<p>假设永远不会成为现实的</p>
<blockquote><p>理性经济人、资源稀缺、完全信息这三个基本的假设，为经济学的分析力、决策力提供了现实的前提条件和基础，因而我们在学习经济学的时候就必须了解这些假设</p></blockquote>
<p><strong>7年之痒 &#8212; 扩展的边际效用</strong></p>
<p>同样，边际效用递减的原理广泛地存在于日常生活中</p>
<blockquote><p>边际效用是一个经济学概念。物品都有用，人们消费物品后获得效用。每多消费一个单位量的物品，都能多获得一些额外效用，这些额外效用就叫做边际效用。边际效用在应用的过程中，有一个递减的作用，叫做边际效用递减。</p>
<p>比如说工作，为什么新人的干劲很大，而过几年大家都意志消沉、尽显沧桑了？这就是因为如果一个人在一段时间以内一直做同样的工作，那么工作带给他的新鲜感和满足度是一直边际递减的</p>
<p>还有在婚姻中，之所以会有喜新厌旧的说法，就是由于边际效用递减的缘故。。那么对于生性喜欢追求刺激的人来说这样的生活太没有挑战意义，那么婚姻中的他很有可能通过外在异性的获得来填充这种需求。所以，保持婚姻持久的最好方法就是保持婚姻的新鲜度，让感情常新。</p></blockquote>
<p><strong>从高处看外包</strong></p>
<blockquote><p>外包的方式在企业中应用最为广泛。外包将企业解放出来以更专注于核心业务。外包合作伙伴为企业带来知识，增加后备管理时间。在执行者专注于其特长业务时，为其改善产品的整体质量。</p>
<p>但是，在现实应用中，有些企业或人对外包产生了错误的认识。他们认为‚把不懂的业务全部包出去已经成为企业管理新思潮‛。这是一个非常普遍又危险的误区。对于企业，自身对包出去的业务，可以‚不专‛，但不能‚不懂‛。‚不专‛与，‚不懂‛是有很大区别的。。如果企业对外包出去的业务‚不懂‛，很容易就会丧失对业务的监控、管理和对结果的考核能力，最终所得到的结果就会与初衷背道而驰。‚不懂业务‛从另一个层面来说是指不具备和服务供应商的议价能力，如此一来又如何达成降低成本的目的呢？</p>
<p>众多的研究表明，服务发包商与服务供应商之间最为良好的关系，并不是简单的买卖关系，而是一种合作伙伴关系。一旦外包服务合同关系成立，随之就要确立外包项目的管理模式，要建立诸如项目管理的组织结构、职责界定、交流机制和交流渠道等一系列的内容。如果是长期项目，还要有不断总结改进的机制。这一系列的复杂情况决定了简单的买卖关系很难产生成功的服务外包结果</p></blockquote>
<p><strong>破窗效应</strong></p>
<p>有点类似<strong>示范效应；不过这个是不好的</strong><strong>示范效应。</strong></p>
<blockquote><p>有一家理发店的窗户玻璃破了一个角，由于生意非常红火，老板没有时间去修理它。有一天夜里，一个小男孩路过理发店，看见破了一个角的窗户，就拿起一块石头砸过去，大半截玻璃稀里哗啦地掉了下来。等老板追出来的时候，小男孩已经跑远了。老板想换掉玻璃，可由于马上要过节了，理发的人很多，他非常忙，根本没时间。那扇掉了大半截玻璃的窗户依旧破裂着。过了几天，老板正在里边忙碌着，突然听见‚啪‛的一声，那扇半截玻璃被完全打碎了。等老板追出来的时候，只看见了两个跑远了的孩子的背影。</p>
<p>不得已老板抽出时间装了一块新的玻璃。为了防止玻璃再被打碎，老板只要有时间就站在窗户后面，企图逮住打碎玻璃的小孩。可令他奇怪的是，此后再也没有小孩来打碎他的窗户玻璃了。</p>
<p>这个小故事反映了这样一个道理：如果有人打坏了一栋建筑上的一块玻璃，又没有及时修复，别人就可能受到某些暗示性的纵容，去打碎更多的玻璃。久而久之，这些窗户就给人造成一种无序的感觉，在这种麻木不仁的氛围中，就会出现更多破坏性的行为。这就是<strong>政治学</strong>家威尔逊和<strong>犯罪学</strong>家凯琳提出的‚破窗效应‛</p>
<p>对于违反公司程序或廉政规定的行为，有关组织没有进行严肃处理，没有引起员工的重视，从而使类似行为再次甚至多次重复发生</p>
<p>而在一个很干净的地方，人们会很不好意思扔垃圾，但是一旦地上有垃圾出现，人们就会毫不犹豫地随地乱扔垃圾，丝毫不觉得羞愧</p>
<p>在公交车站，如果大家都井然有序地排队上车，又有多少人会不顾众人的文明举动和鄙夷眼光而贸然插队？与这相反，车辆尚未停稳，猴急的人们你推我拥，争先恐后，后来的人如果想排队上车，恐怕也没有耐心了。这些都是‚破窗效应‛的表现。</p>
<p>在管理实践中，管理者必须高度警觉那些看起来是个别的、轻微的‚小过错‛，并坚持严格依法管理。‚千里之堤，溃于蚁穴。‛不及时修好第一扇被打碎玻璃的窗户，就可能会带来无法弥补的损失。而如果能及时修复，则效果会非常明显</p></blockquote>
<p><strong>消费PK节俭——节俭悖论</strong></p>
<p>现在明显是内需不足，产能过剩</p>
<blockquote><p>18世纪，荷兰的曼德维尔博士在《蜜蜂的寓言》一书中讲过一个有趣的故事。一群蜜蜂为了追求豪华的生活，大肆挥霍，结果这个蜂群很快兴旺发达起来。而后来，由于这群蜜蜂改变了习惯，放弃了奢侈的生活，崇尚节俭，结果却导致了整个蜜蜂群体的衰败。</p>
<p>蜜蜂的故事说的就是‚节俭的逻辑‛，在经济学上叫‚节俭悖论‛。在西方经济学说史上，经济学家<strong>凯恩斯</strong>从故事中却看到了刺激消费和增加总需求对经济发展的积极作用，受此启发，他进一步论证了节俭悖论。</p>
<p>根据凯恩斯的总需求决定国民收入的理论，节俭对于经济增长并没有什么好处。实际上，这里蕴涵着一个矛盾：公众越节俭，降低消费，增加储蓄，往往会导致社会收入的减少。因为，人们的收入通常有两种用途——消费和储蓄，而消费与储蓄成反方向变动，即消费增加储蓄就会减少，消费减少储蓄就会增加。所以，储蓄与国民收入呈现反方向变动，储蓄增加国民收入就减少，储蓄减少国民收入就增加。根据这种看法，增加消费减少储蓄会通过增加总需求而引起国民收入增加，就会促进经济繁荣；反之，就会导致经济萧条。由此可以得出一个蕴涵逻辑矛盾的推论：节制消费增加储蓄会增加个人财富，对个人是件好事，但由于会减少国民收入引起萧条，对整个国民经济发展却是件坏事。</p>
<p>节俭悖论告诉我们：节俭减少了支出，迫使厂家削减产量，解雇工人，从而减少了收入，最终减少了储蓄。储蓄为个人致富铺平了道路，然而如果整个国家加大储蓄，将使整个社会陷入萧条和贫困。也就是说，在资源没有得到充分运用、经济没有达到潜在产出的情况下，只有社会每个成员都尽可能多地消费，整个经济才能走出低谷，迈向更加充分就业、经济繁荣的阶段。</p>
<p>总之，我们要辩证地看待节俭和消费的问题。像本书开头案例中王先生的父亲和儿子，他们的观点都对，但又都不全对。这里关键是一个度的把握问题。节俭是中华民族的传统美德，但并不是不去消费；而<br />
消费也不是奢侈地去浪费。我们要大力提倡理性消费，也要理直气壮地反对盲目消费。</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://yumianfeilong.com/html/2012/01/10/542.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>Scalability.Rules.notes</title>
		<link>http://yumianfeilong.com/html/2012/01/05/541.html</link>
		<comments>http://yumianfeilong.com/html/2012/01/05/541.html#comments</comments>
		<pubDate>Thu, 05 Jan 2012 06:39:50 +0000</pubDate>
		<dc:creator>yumianfeilong</dc:creator>
		
		<category><![CDATA[Boring]]></category>

		<category><![CDATA[ELNINO]]></category>

		<category><![CDATA[Family]]></category>

		<category><![CDATA[架构]]></category>

		<guid isPermaLink="false">http://yumianfeilong.com/?p=541</guid>
		<description><![CDATA[图书&#8221;Scalability Rules 50 Principles for Scaling Web Sites&#8220;列举了易扩展的web应用在设计，开发，实施，运维中的50个关键的实践经验，其中很多经验都已经脍炙人口，在很多web应用中都有体现，如分库分表，cache,LB,异步消息等。
书作者都有大型互联网公司工作的经验，在最后章节对所有的50个rule按照重要级别和实施成本作了分类；如下我摘录一些比较常见的rule按照类型进行一下分类，如属于设计范畴或运维范畴等。
设计原则

Rule 1—Don’t Over-engineer the Solution &#8212; 适合的是最好的




What: Guard against complex solutions during design.
How to use: Resist the urge to over-engineer solutions by testing ease of understanding with fellow engineers.
Why: Complex solutions are costly to implement and have excessive long-term costs.
Key takeaways: Systems that are overly complex limit your [...]]]></description>
			<content:encoded><![CDATA[<p>图书&#8221;<a href="http://book.douban.com/subject/6397551/">Scalability Rules 50 Principles for Scaling Web Sites</a>&#8220;列举了易扩展的web应用在设计，开发，实施，运维中的50个关键的实践经验，其中很多经验都已经脍炙人口，在很多web应用中都有体现，如分库分表，cache,LB,异步消息等。</p>
<p>书作者都有大型互联网公司工作的经验，在最后章节对所有的50个rule按照重要级别和实施成本作了分类；如下我摘录一些比较常见的rule按照类型进行一下分类，如属于设计范畴或运维范畴等。</p>
<p><strong>设计原则</strong></p>
<ul>
<li><strong>Rule 1—Don’t Over-engineer the Solution &#8212; 适合的是最好的<br />
</strong></li>
</ul>
<blockquote>
<ol>
<li>What: Guard against complex solutions during design.</li>
<li>How to use: Resist the urge to over-engineer solutions by testing ease of understanding with fellow engineers.</li>
<li>Why: Complex solutions are costly to implement and have excessive long-term costs.</li>
<li>Key takeaways: Systems that are overly complex limit your ability to scale. Simple systems are more easily and cost effectively maintained and scaled.</li>
</ol>
</blockquote>
<ul>
<li><strong>Rule 2—Design Scale into the Solution (D-I-D Process) &#8212; 在设计阶段就考虑scale成本最低并最有效率<br />
</strong></li>
</ul>
<blockquote><p>How to use:<br />
+Design for 20x capacity.<br />
+Implement for 3x capacity.<br />
+Deploy for ~1.5x capacity.</p></blockquote>
<p><strong>架构设计</strong></p>
<ul>
<li><strong>Rule 43—Communicate Asynchronously As Much As Possible &#8212; 使用可信赖的消息队列<br />
</strong></li>
</ul>
<blockquote>
<ol>
<li>What: Use asynchronous instead of synchronous communication as often as possible.</li>
<li>When to use: Consider for all calls between services and tiers.</li>
<li>Why: Synchronous calls stop the entire program’s execution waiting for a response, which ties all the services and tiers together resulting in cascading failures.</li>
<li>Key takeaways: Use asynchronous communication techniques to ensure that each service and tier is as independent as possible. This allows the system to scale much farther than if all components are closely coupled together.</li>
</ol>
</blockquote>
<ul>
<li><strong>Rule 29—Failing to Design for Rollback Is Designing for Failure &#8212; 减少失败就是提高可用性<br />
</strong></li>
</ul>
<blockquote>
<ol>
<li>What: Always have the ability to roll back code.</li>
<li>Key takeaways: Don’t accept that the application is too complex or that you release code too often as excuses that you can’t roll back. No sane pilot would take off in an airplane without the ability to land, and no sane engineer would roll code that they could not pull back off in an emergency.</li>
</ol>
</blockquote>
<p><span id="more-541"></span></p>
<ul>
<li><strong>Rule 37—Never Trust Single Points of Failure  &#8212; 增加可用性，还可以提高用户网络体验<br />
</strong></li>
</ul>
<blockquote>
<ol>
<li>What: Never implement and always eliminate single points of failure.</li>
<li>When to use: During architecture reviews and new designs.</li>
<li>How to use: Identify single instances on architectural diagrams. Strive for active/active configurations.</li>
<li>Why: Maximize availability through multiple instances.</li>
<li>Key takeaways: Strive for active/active rather than active/ passive solutions. Use load balancers to balance traffic across instances of a service. Use control services with active/passive instances for patterns that require singletons.</li>
</ol>
</blockquote>
<p><strong>Web开发设计</strong></p>
<ul>
<li><strong>Rule 21—Use Expires Headers  &#8212; cache in client</strong></li>
</ul>
<blockquote>
<ol>
<li>What: Use Expires headers to reduce requests and improve the scalability and performance of your system.</li>
</ol>
</blockquote>
<ul>
<li><strong>Rule 22—Cache Ajax Calls       &#8212; cache is king； cache in multiple ties<br />
</strong></li>
<li><strong>Rule 23—Leverage Page Caches</strong></li>
<li><strong>Rule 24—Utilize Application Caches</strong></li>
<li><strong>Rule 25—Make Use of Object Caches</strong></li>
<li><strong>Rule 26—Put Object Caches on Their Own “Tier”  &#8212; don&#8217;t abuse cache<br />
</strong></li>
<li><strong>Rule 4—Reduce DNS Lookups  &#8212; volecity大会中介绍过很多类似的方法，提高web页面相应速度<br />
</strong></li>
</ul>
<blockquote>
<ol>
<li>What: Reduce the number of DNS lookups from a user perspective.</li>
<li>When to use: On all Web pages where performance matters.</li>
<li>How to use: Minimize the number of DNS lookups required to download pages, but balance this with the browser’s limitation for simultaneous connections.</li>
<li>Why: DNS lookups take a great deal of time, and large numbers of them can amount to a large portion of your user experience.</li>
</ol>
</blockquote>
<ul>
<li><strong>Rule 39—Ensure You Can Wire On and Off Functions &#8212; 通过文件或者数据库配置，可以针对用户打开或者关闭某个服务，类似oracle 11g中的invsisiable index<br />
</strong></li>
</ul>
<blockquote>
<ol>
<li>What: Create a framework to disable and enable features of your product.</li>
<li>When to use: Risky, very high use, or shared services that might otherwise cause site failures when slow to respond or unavailable.</li>
<li>How to use: Develop shared libraries to allow automatic or on-demand enabling and disabling of services.</li>
<li>Why: Graceful failure (or handling failures) of transactions can keep you in business while you recover from the incident and problem that caused it.</li>
<li>Key takeaways: Implement Wire On/Wire Off frameworks whenever the cost of implementation is less than the risk and associated cost of failure.Work to develop shared libraries that can be reused to lower the cost of future implementation.</li>
</ol>
</blockquote>
<ul>
<li><strong>Rule 40—Strive for Statelessness  &#8212; 无状态web应用；不大懂web开发；可能是将session信息存储在应用服务器端的成本太高<br />
</strong></li>
</ul>
<blockquote>
<ol>
<li>What: Design and implement stateless systems.</li>
<li>When to use: During design of new systems and redesign of existing systems.</li>
<li>How to use: Choose stateless implementations whenever possible. If stateful implementations are warranted for business reasons, refer to Rules 41 and 42.</li>
<li>Why: The implementation of state limits scalability and increases cost.</li>
</ol>
</blockquote>
<ul>
<li><strong>Rule 41—Maintain Sessions in the Browser When Possible</strong></li>
</ul>
<blockquote>
<ol>
<li>What: Try to avoid session data completely, but when needed, consider putting the data in users’ browsers.</li>
<li>When to use: Anytime that you need session data for the best user experience.</li>
<li>How to use: Use cookies to store session data on the users’ browsers.</li>
<li>Why: Keeping session data on the users’ browsers allows the user request to be served by any Web server in the pool and takes the storage requirement away from your system.</li>
<li>Key takeaways: Using cookies to store session data is a common approach and has advantages in terms of ease of scale but also has some drawbacks. One of the most critical cons is that unsecured cookies</li>
</ol>
</blockquote>
<ul>
<li><strong>Rule 42—Make Use of a Distributed Cache for States &#8211;可以将session信息持久化到数据库中，同时在应用服务器和数据库之前提供一层高可用的cache；<br />
</strong></li>
</ul>
<blockquote>
<ol>
<li>What: Use a distributed cache when storing session data in your system.</li>
<li>When to use: Anytime you need to store session data and cannot do so in users’ browsers.</li>
<li>How to use: Watch for some common mistakes such as a session management system that requires affinity of a user to a Web server.</li>
<li>Why: Careful consideration of how to store session data can help ensure your system will continue to scale.</li>
<li>Key takeaways: Many Web servers or languages offer simple server-based session management, but these are often fraught with problems such as user affiliation with specific servers. Implementing a distributed cache will allow you to store session data in your system and continue to scale.</li>
</ol>
</blockquote>
<p><strong>网络实施</strong></p>
<ul>
<li><strong>Rule 20—Leverage CDNs  &#8212; 收益和成本的balance<br />
</strong></li>
</ul>
<blockquote>
<ol>
<li>What: Use CDNs to offload traffic from your site.</li>
<li>When to use: Ensure it is cost justified and then choose which content is most suitable.</li>
<li>How to use: Most CDNs leverage DNS to serve content on your site’s behalf.</li>
<li>Why: CDNs help offload traffic spikes and are often economical ways to scale parts of a site’s traffic.</li>
<li>Key takeaways: CDNs are a fast and simple way to offset spikiness of traffic as well as traffic growth in general. Ensure you perform a cost-benefit analysis and monitor the CDN usage.</li>
</ol>
</blockquote>
<ul>
<li><strong>Rule 6—Use Homogenous Networks</strong></li>
</ul>
<blockquote>
<ol>
<li>What: Don’t mix the vendor networking gear.</li>
<li>When to use: When designing or expanding your network.</li>
<li>How to use:<br />
+ Do not mix different vendors’ networking gear (switches and routers).<br />
+ Buy best of breed for other networking gear (firewalls, load balancers, and so on).</li>
<li>Why: Intermittent interoperability and availability issues simply aren’t worth the potential cost savings.</li>
<li>Key takeaways: Heterogeneous networking gear tends to cause availability and scalability problems. Choose a single provider.</li>
</ol>
</blockquote>
<p><strong>数据库相关</strong></p>
<ul>
<li><strong>Rule 31—Be Aware of Costly Relationships  &#8212; FK约束会对数据库的分库分表等行为有一定</strong><strong>限制</strong></li>
</ul>
<blockquote>
<ol>
<li> What: Be aware of relationships in the data model.</li>
<li>When to use: When designing the data model, adding tables/columns, or writing queries consider how the relationships between entities will affect performance and scalability in the long run.</li>
<li>How to use: Think about database splits and possible future data needs as you design the data model.</li>
<li>Why: The cost of fixing a broken data model after it has been implemented is likely 100x as much as fixing it during the design phase.</li>
<li>Key takeaways: Think ahead and plan the data model carefully. Consider normalized forms, how you will likely split the database in the future, and possible data needs of the application.</li>
</ol>
</blockquote>
<ul>
<li><strong>Rule 14—Use Databases Appropriately   &#8212; 选择传统关系数据库？<br />
</strong></li>
</ul>
<blockquote>
<ol>
<li>What: Use relational databases when you need ACID properties to maintain relationships between your data. For other data storage needs consider more appropriate tools.</li>
<li>How to use: Consider the data volume, amount of storage, response time requirements, relationships, and other factors to choose the most appropriate storage tool.<br />
Why: RDBMSs provide great transactional integrity but are more difficult to scale, cost more, and have lower availability than many other storage options.</li>
<li>Key takeaways: Use the right storage tool for your data. Don’t get lured into sticking everything in a relational database just because you are comfortable accessing data in a database.</li>
</ol>
</blockquote>
<ul>
<li><strong>Rule 7—Design to Clone Things (X Axis)   &#8211;（复制:一写N读）</strong></li>
</ul>
<blockquote>
<ol>
<li>What: Typically called horizontal scale, this is the duplication of services or databases to spread transaction load.</li>
<li>How to use:<br />
+ Simply clone services and implement a load balancer.<br />
+ For databases, ensure the accessing code understands the difference between a read and a write.</li>
</ol>
</blockquote>
<ul>
<li><strong>Rule 8—Design to Split Different Things (Y Axis) &#8212; 按照function或者service分库</strong></li>
<li><strong>Rule 9—Design to Split Similar Things (Z Axis) &#8212; 分表</strong></li>
</ul>
<blockquote>
<ol>
<li>What: This is often a split by some unique aspect of the customer such as customer ID, name, geography, and so on.</li>
<li>When to use:Very large, similar data sets such as large and rapidly growing customer bases.</li>
<li>How to use: Identify something you know about the customer, such as customer ID, last name, geography, or device and split or partition both data and services based on that attribute.</li>
<li>Why: Rapid customer growth exceeds other forms of data growth or you have the need to perform “fault isolation” between certain customer groups as you scale.</li>
</ol>
</blockquote>
<ul>
<li><strong>Rule 35—Don’t Select Everything</strong></li>
</ul>
<blockquote>
<ol>
<li>What: Don’t use Select * in queries.</li>
<li>When to use: Never select everything (unless of course you are going to use everything).</li>
<li>How to use: Always declare what columns of data you are selecting or inserting in a query.</li>
<li>Why: Selecting everything in a query is prone to break things when the table structure changes and it transfers unneeded data.</li>
<li>Key takeaways: Don’t use wildcards when selecting or inserting data.</li>
</ol>
</blockquote>
<p><strong>Datacenter</strong><strong>实施</strong></p>
<ul>
<li> <strong>Rule 12—Scale Out Your Data Centers</strong></li>
</ul>
<blockquote>
<ol>
<li>What: Design your systems to have three or more live data centers to reduce overall cost, increase availability, and implement disaster recovery.</li>
<li>When to use: Any rapidly growing business that is considering adding a disaster recovery (cold site) data center.</li>
<li>How to use: Split up your data to spread across data centers and spread transaction load across those data centers in a “multiple live” configuration. Use spare capacity for peak periods of the year.</li>
</ol>
</blockquote>
<p><strong>运维</strong></p>
<ul>
<li><strong>Rule 30—Discuss and Learn from Failures</strong></li>
</ul>
<blockquote>
<ol>
<li>What: Leverage every failure to learn and teach important lessons.</li>
<li>How to use: Employ a postmortem process and hypothesize failures in low failure environments.</li>
<li>Why:We learn best from our mistakes—not our successes.<br />
Key takeaways: Never let a good failure go to waste. Learn from every one and identify the technology, people, and process issues that need to be corrected.</li>
</ol>
</blockquote>
<ul>
<li><strong>Rule 27—Learn Aggressively  &#8212; 27&amp;30 2个rules都是为了避免incident成为mistake<br />
</strong></li>
</ul>
<blockquote>
<ol>
<li>When to use: Be constantly learning from your mistakes as well as successes.</li>
<li>How to use: Watch your customers or use A/B testing to determine what works. Use postmortems to learn from incidents and problems in production.</li>
<li>Why: Doing something without measuring the results or having an incident without learning from it are wasted opportunities that your competitors are taking advantage of.</li>
</ol>
</blockquote>
<ul>
<li><strong>Rule 16—Actively Use Log Files  &#8212; for DW or troubleshooting<br />
</strong></li>
</ul>
<blockquote>
<ol>
<li>What: Use your application’s log files to diagnose and prevent problems.<br />
When to use: Put a process in place that monitors log files and forces people to take action on issues identified.</li>
<li>How to use: Use any number of monitoring tools from custom scripts to Splunk to watch your application logs for errors. Export these and assign resources for identifying and solving the issue.</li>
<li>Why: The log files are excellent sources of information about how your application is performing for your users; don’t throw this resource away without using it.</li>
<li>Key takeaways: Make good use of your log files and you will have fewer production issues with your system.</li>
</ol>
</blockquote>
<ul>
<li><strong>Rule 29—Failing to Design for Rollback Is Designing for Failure &#8212; 减少失败就是提高可用性</strong></li>
<li><strong></strong><strong>Rule 49—Design Your Application to Be Monitored</strong></li>
</ul>
<blockquote>
<ol>
<li>What: Think about how you will need to monitor your application as you are designing it.</li>
<li>When to use: Anytime you are adding or changing modules of your code base.</li>
<li>How to use: Build hooks into your system to record transaction times.</li>
<li>Why: Having insight into how your application is performing will help answer many questions when there is a problem.</li>
<li>Key takeaways: Adopt as an architectural principle that your application must be monitored. Additionally, look at your overall monitoring strategy to make sure you are first answering the question of “Is there a problem?” and then the “Where” and “What.”</li>
</ol>
</blockquote>
<ul>
<li><strong>Rule 47—Purge, Archive, and Cost-Justify Storage  &#8212; 真对OLTP数据库，归档数据可以保证cache命中率<br />
</strong></li>
</ul>
<blockquote>
<ol>
<li> What: Match storage cost to data value, including removing data of value lower than the costs to store it.</li>
<li> Why: Not all data is created equal (that is, of the same value) and in fact it often changes in value over time.Why then should we have a single storage solution with equivalent cost for that data?</li>
<li> Key takeaways: It is important to understand and calculate the value of your data and to match storage costs to that value. Don’t pay for data that doesn’t have a stakeholder return.</li>
</ol>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://yumianfeilong.com/html/2012/01/05/541.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>宝宝</title>
		<link>http://yumianfeilong.com/html/2012/01/03/540.html</link>
		<comments>http://yumianfeilong.com/html/2012/01/03/540.html#comments</comments>
		<pubDate>Tue, 03 Jan 2012 12:44:26 +0000</pubDate>
		<dc:creator>yumianfeilong</dc:creator>
		
		<category><![CDATA[Family]]></category>

		<guid isPermaLink="false">http://yumianfeilong.com/?p=540</guid>
		<description><![CDATA[今天宝宝从床下掉下来了。在我找尿布的时候，也就5秒中没有看他，没有把他放到床中间，翻了两个身估计，然后哐当一下，还好没有摔坏，哭了2声。
标记下，5个半月第一次摔地上。
]]></description>
			<content:encoded><![CDATA[<p>今天宝宝从床下掉下来了。在我找尿布的时候，也就5秒中没有看他，没有把他放到床中间，翻了两个身估计，然后哐当一下，还好没有摔坏，哭了2声。</p>
<p>标记下，5个半月第一次摔地上。</p>
]]></content:encoded>
			<wfw:commentRss>http://yumianfeilong.com/html/2012/01/03/540.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>MongoDB.in.Action notes</title>
		<link>http://yumianfeilong.com/html/2011/12/27/538.html</link>
		<comments>http://yumianfeilong.com/html/2011/12/27/538.html#comments</comments>
		<pubDate>Tue, 27 Dec 2011 13:28:17 +0000</pubDate>
		<dc:creator>yumianfeilong</dc:creator>
		
		<category><![CDATA[Boring]]></category>

		<category><![CDATA[MongoDB]]></category>

		<guid isPermaLink="false">http://yumianfeilong.com/?p=538</guid>
		<description><![CDATA[MongoDB算是比较接近传统关系数据库的no-sql类型的文档数据库，最近其发展越来越快，一个是使用范围越来越广，搜索mongodb ppt的话可以有一大堆；一个是10gen的大力支持，不断增加的新功能和社区增加的新需求都在使MongoDB不断完善并且变的庞大。
以下是阅读MongoDB.in.Action一些读书笔记，都是&#8221;点&#8221;：主要是MongoDB模式设计和维护相关。包括

Embed versus reference 例如blog中如何实现post和comments
One-to-many:
Many-to-many: Products and categories之间多对多的relation展现（一个product属于很多category，一个category可以有很多product）
Tree: 如论坛留言
Dynamic attributes 是否引入嵌入式文档
namespaces文件的限制
 mmap&#8211; MongoDB如何使用内存
内存是如何影响性能的，推荐是index都被缓存在内存中
Limits on document size
Custom types，例如存储带有时区的时间
a single global reader-writer lock 如何影响并行
因为单一global RW lock对创建/重建索引的影响
WHEN TO SHARD
indexes in shard
Sharding an existing collection
MANUAL PARTITIONING


Embed versus reference 例如blog中如何实现post和comments
Suppose you’re building a simple application in MongoDB that stores blog posts and comments. How do you represent this data? Do [...]]]></description>
			<content:encoded><![CDATA[<p>MongoDB算是比较接近传统关系数据库的no-sql类型的文档数据库，最近其发展越来越快，一个是使用范围越来越广，搜索mongodb ppt的话可以有一大堆；一个是<a href="https://jira.mongodb.org/secure/Dashboard.jspa">10gen的大力支持</a>，不断增加的新功能和社区增加的新需求都在使MongoDB不断完善并且变的庞大。</p>
<p>以下是阅读MongoDB.in.Action一些读书笔记，都是&#8221;点&#8221;：主要是MongoDB模式设计和维护相关。包括</p>
<ol>
<li>Embed versus reference 例如blog中如何实现post和comments</li>
<li>One-to-many:</li>
<li>Many-to-many: Products and categories之间多对多的relation展现（一个product属于很多category，一个category可以有很多product）</li>
<li>Tree: 如论坛留言</li>
<li>Dynamic attributes 是否引入嵌入式文档</li>
<li>namespaces文件的限制</li>
<li> mmap&#8211; MongoDB如何使用内存</li>
<li>内存是如何影响性能的，推荐是index都被缓存在内存中</li>
<li>Limits on document size</li>
<li>Custom types，例如存储带有时区的时间</li>
<li>a single global reader-writer lock 如何影响并行</li>
<li>因为单一global RW lock对创建/重建索引的影响</li>
<li>WHEN TO SHARD</li>
<li>indexes in shard</li>
<li>Sharding an existing collection</li>
<li>MANUAL PARTITIONING</li>
</ol>
<p><span id="more-538"></span></p>
<p><strong>Embed versus reference 例如blog中如何实现post和comments</strong></p>
<blockquote><p>Suppose you’re building a simple application in MongoDB that stores blog posts and comments. How do you represent this data? Do you embed the comments in their respective blog post documents? Or is it better to create two collections, one for posts and the other for comments, and then relate the comments to the posts with an object id reference?<br />
This is the problem of embedding versus referencing, and it’s a common source of confusion for new users of MongoDB. Fortunately, there’s a simple rule of thumb that works for most schema design scenarios: Embed when the child objects always appear in the context of their parent. Otherwise, store the child objects in a separate collection.<br />
What does this mean for blog posts and comments? It depends on the application. If the comments always appear within a blog post, and if they don’t need to be ordered in arbitrary ways (by post date, comment rank, and so on), then embedding is fine. But if, say, you want to be able to display the most recent comments, regardless of which post they appear on, then you’ll want to reference. Embedding may provide a slight performance advantage, but referencing is far more flexible.</p>
<p>但要注意MongoDB对单一文档有大小限制，不同版本可能不一样。如果将post和comments都存储在一个文档中，需要注意大小。</p></blockquote>
<p><strong>One-to-many : embedding or referencing.</strong></p>
<blockquote><p>As stated in the previous section, you can represent a one-to-many  relationship by either embedding or referencing. You should embed when  the many object intrinsically belongs with its parent and rarely  changes.</p>
<p><strong>embedding</strong> <strong>example</strong>: <strong>step and sub-steps</strong></p>
<p>{ title: &#8220;How to soft-boil an egg&#8221;,<br />
steps: [<br />
250 APPENDIX B Design patterns<br />
{ desc: &#8220;Bring a pot of water to boil.&#8221;,<br />
materials: [&#8221;water&#8221;, &#8220;eggs&#8221;] },<br />
{ desc: &#8220;Gently add the eggs a cook for four minutes.&#8221;,<br />
materials: [&#8221;egg timer&#8221;]},<br />
{ desc: &#8220;Cool the eggs under running water.&#8221; },<br />
]<br />
}</p>
<p><strong>referencing </strong><strong>example</strong><strong>: post and comments<br />
</strong></p>
<p>a sample of post document = { _id: ObjectId(&#8221;4d650d4cf32639266022018d&#8221;),<br />
title: &#8220;Cultivating herbs&#8221;,<br />
text: &#8220;Herbs require occasional watering&#8230;&#8221;<br />
}</p>
<p>A sample of comment document = { _id: ObjectId(&#8221;4d650d4cf32639266022ac01&#8243;),<br />
post_id: <strong>ObjectId</strong>(&#8221;4d650d4cf32639266022018d&#8221;),<br />
username: &#8220;zjones&#8221;,<br />
text: &#8220;Indeed, basil is a hearty herb!&#8221;<br />
}</p>
<p>we need index on comments collection : db.comments.ensureIndex({post_id: 1})</p></blockquote>
<p><strong>Many-to-many: Products and categories之间多对多的relation展现（一个product属于很多category，一个category可以有很多product）</strong></p>
<blockquote><p>here’s a sample product from a gardening store.</p>
<p>a sample of product doc =<br />
{ _id: new ObjectId(&#8221;4c4b1476238d3b4dd5003981&#8243;),<br />
slug: &#8220;wheel-barrow-9092&#8243;,<br />
sku: &#8220;9092&#8243;,<br />
name: &#8220;Extra Large Wheel Barrow&#8221;,<br />
description: &#8220;Heavy duty wheel barrow&#8230;&#8221;,<br />
details: {<br />
weight: 47,<br />
weight_units: &#8220;lbs&#8221;,<br />
model_num: 4039283402,<br />
manufacturer: &#8220;Acme&#8221;,<br />
color: &#8220;Green&#8221;<br />
},<br />
total_reviews: 4,<br />
average_review: 4.5,pricing: {<br />
retail: 589700,<br />
sale: 489700,<br />
},<br />
price_history: [<br />
{retail: 529700,<br />
sale: 429700,<br />
start: new Date(2010, 4, 1),<br />
end: new Date(2010, 4, <img src='http://yumianfeilong.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /><br />
},<br />
{retail: 529700,<br />
sale: 529700,<br />
start: new Date(2010, 4, 9),<br />
end: new Date(2010, 4, 16)<br />
},<br />
],<br />
<strong>category_ids: [new ObjectId(&#8221;6a5b1476238d3b4dd5000048&#8243;),<br />
new ObjectId(&#8221;6a5b1476238d3b4dd5000049&#8243;)],<br />
main_cat_id: new ObjectId(&#8221;6a5b1476238d3b4dd5000048&#8243;),</strong><br />
tags: [&#8221;tools&#8221;, &#8220;gardening&#8221;, &#8220;soil&#8221;],<br />
}</p>
<p>a sample of category doc =<br />
{ _id: new ObjectId(&#8221;6a5b1476238d3b4dd5000048&#8243;),<br />
slug: &#8220;gardening-tools&#8221;,<br />
ancestors: [{ name: &#8220;Home&#8221;,<br />
_id: new ObjectId(&#8221;8b87fb1476238d3b4dd500003&#8243;),<br />
slug: &#8220;home&#8221;<br />
},<br />
{ name: &#8220;Outdoors&#8221;,<br />
Listing 4.2 A category document<br />
Designing an e-commerce data model 61<br />
_id: new ObjectId(&#8221;9a9fb1476238d3b4dd5000001&#8243;),<br />
slug: &#8220;outdoors&#8221;<br />
}<br />
],<br />
<strong>parent_id: new ObjectId(&#8221;9a9fb1476238d3b4dd5000001&#8243;),</strong><br />
<strong>name: &#8220;Gardening Tools&#8221;,</strong><br />
description: &#8220;Gardening gadgets galore!&#8221;,<br />
}</p>
<p>如果category的name并不经常变化，但经常要查询属于某个category下的product，则可以将category name也加入到product文档中。</p></blockquote>
<p><strong><br />
Tree: 例如如下论坛留言的形式，每条记录需要级录其parent</strong></p>
<p><a href="http://yumianfeilong.com/wp-content/uploads/2011/12/mongodb_pic.jpeg"><img class="aligncenter size-full wp-image-539" title="mongodb_pic" src="http://yumianfeilong.com/wp-content/uploads/2011/12/mongodb_pic.jpeg" alt="" width="437" height="257" /></a></p>
<blockquote><p>each node in the tree contains a path field. This field stores the concatenation of each of the node’s ancestor’s IDs, and root-level nodes have a null path because they have no ancestors.</p>
<p>{ _id: ObjectId(&#8221;4d692b5d59e212384d95001&#8243;),<br />
depth: 0,<br />
path: null,<br />
created: ISODate(&#8221;2011-02-26T17:18:01.251Z&#8221;),<br />
username: &#8220;plotinus&#8221;,<br />
body: &#8220;Who was Alexander the Great&#8217;s teacher?&#8221;,<br />
thread_id: ObjectId(&#8221;4d692b5d59e212384d95223a&#8221;)<br />
}</p>
<p>Examine the first of these, and note that path contains the _id of the immediate parent:</p>
<p>{ _id: ObjectId(&#8221;4d692b5d59e212384d951002&#8243;),<br />
depth: 1,<br />
path: &#8220;4d692b5d59e212384d95001&#8243;,<br />
created: ISODate(&#8221;2011-02-26T17:21:01.251Z&#8221;),<br />
username: &#8220;asophist&#8221;,<br />
body: &#8220;It was definitely Socrates.&#8221;,<br />
thread_id: ObjectId(&#8221;4d692b5d59e212384d95223a&#8221;)<br />
}</p>
<p>The next deeper comment’s path contains both the IDs of the original and immediate parents, in that order and separated by a colon:</p>
<p>{ _id: ObjectId(&#8221;4d692b5d59e212384d95003&#8243;),<br />
depth: 2,<br />
path: &#8220;4d692b5d59e212384d95001:4d692b5d59e212384d951002&#8243;,<br />
created: ISODate(&#8221;2011-02-26T17:21:01.251Z&#8221;),<br />
username: &#8220;daletheia&#8221;,<br />
body: &#8220;Oh you sophist&#8230;It was actually Aristotle!&#8221;,<br />
thread_id: ObjectId(&#8221;4d692b5d59e212384d95223a&#8221;)<br />
}</p>
<p>some indexes are needed.</p>
<p>db.comments.ensureIndex({thread_id: 1})<br />
db.comments.ensureIndex({path: 1})</p></blockquote>
<p><strong><br />
Dynamic attributes 是否引入嵌入式文档</strong></p>
<blockquote><p>In a single products collection, you can then store disparate product types. You might store a set of headphones</p>
<p>{ _id: ObjectId(&#8221;4d669c225d3a52568ce07646&#8243;)<br />
sku: &#8220;ebd-123&#8243;<br />
name: &#8220;Hi-Fi Earbuds&#8221;,<br />
type: &#8220;Headphone&#8221;,<br />
attrs: { color: &#8220;silver&#8221;,<br />
freq_low: 20,<br />
freq_hi: 22000,<br />
weight: 0.5<br />
}<br />
}</p>
<p>and an SSD drive:</p>
<p>{ _id: ObjectId(&#8221;4d669c225d3a52568ce07646&#8243;)<br />
sku: &#8220;ssd-456&#8243;<br />
name: &#8220;Mini SSD Drive&#8221;,<br />
type: &#8220;Hard Drive&#8221;,<br />
attrs: { interface: &#8220;SATA&#8221;,<br />
capacity: 1.2 * 1024 * 1024 * 1024,<br />
rotation: 7200,<br />
form_factor: 2.5<br />
}<br />
}</p>
<p>If you need to frequently query on these attributes, you can create sparse indexes for them. For example, you can optimize for range queries in headphone frequency response:</p>
<p>db.products.ensureIndex({&#8221;attrs.freq_low&#8221;: 1, &#8220;attrs.freq_hi&#8221;: 1},{sparse: true})</p>
<p>You can also efficiently search hard disks by rotation speed with the following index:</p>
<p>db.products.ensureIndex({&#8221;attrs.rotation&#8221;: 1}, {sparse: true})</p>
<p>If your attributes are completely unpredictable, then you can’t build a separate index for each one. You have to use a different strategy in this case as illustrated by the following sample document:</p>
<p>{ _id: ObjectId(&#8221;4d669c225d3a52568ce07646&#8243;)<br />
sku: &#8220;ebd-123&#8243;<br />
name: &#8220;Hi-Fi Earbuds&#8221;,<br />
type: &#8220;Headphone&#8221;,<br />
attrs: [ {n: &#8220;color&#8221;, v: &#8220;silver&#8221;},<br />
{n: &#8220;freq_low&#8221;, v: 20},<br />
{n: &#8220;freq_hi&#8221;, v: 22000},<br />
{n: &#8220;weight&#8221;, v: 0.5}<br />
]<br />
}</p>
<p>Here attrs points to an array of sub-documents. Each of these documents has two values,n and v, corresponding to each dynamic attribute’s name and value. This normalized representation allows you to index these attributes using a single compound index:</p>
<p>db.products.ensureIndex({&#8221;attrs.n&#8221;: 1, &#8220;attrs.v&#8221;: 1})</p>
<p>You can then query using these attributes, but to do that, you must use the $elemMatch query operator:</p>
<p>db.products.find({attrs: {$elemMatch: {n: &#8220;color&#8221;, v: &#8220;silver&#8221;}}})</p>
<p>这个设计还是挺拧的；</p></blockquote>
<p><strong><br />
namespaces文件的限制</strong></p>
<blockquote><p>The database files themselves are all named after the database they belong to. <strong>garden.ns </strong>is the first file to be generated. The file’s extension, ns, stands for namespaces. Every collection and index in a database gets its own namespace, and the metadata for each namespace is stored in this file. By default, the .ns file is fixed to 16 MB, which lets it store approximately 24,000 namespaces. This means that the sum of the number of indexes and collections in your database can’t exceed 24,000. You’re not likely to need anywhere close to this number of collections or indexes. But on the off chance that you need even more, you can makes the file larger by using the &#8211;nssize server option.</p></blockquote>
<p><strong>Limits on document size</strong></p>
<blockquote><p>BSON documents in MongoDB v2.0 are limited to 16 MB in size.</p>
<p>If you’re simply storing large binary objects, like images or videos, that’s a slightly different case &#8212; GridFS.</p>
<p>The number has varied by server version and is continually increasing. To see the limit for your server version,run db.ismaster from the shell, and examine the maxBsonObjectSize field. If you can’t find this field, then the limit is 4 MB (and you’re using a very old version of MongoDB).</p></blockquote>
<p><strong><br />
mmap&#8211; MongoDB如何使用内存</strong></p>
<blockquote><p>MongoDB tells the operating system to map all data files to memory using the mmap() system call. From this point on, the data files,which include all documents, collections, and their indexes, are swapped in and out of RAM by the operating system in 4 KB chunks called pages.</p>
<p>Whenever data from a given page is requested, the operating system must ensure that the page is available in RAM. If it’s not, then a kind of exception known as a page fault is raised, and this tells the memory manager to load the page from disk into RAM.With sufficient RAM, all of the data files in use will eventually be loaded into memory.</p>
<p>Whenever that memory is altered, as in the case of a write, those changes will be flushed to disk asynchronously by the OS, but the write will be fast, occurring directly in RAM. When data fits into RAM, you have the ideal situation because the number of disk accesses is reduced to a minimum. But if the working data set can’t fit into RAM, then page faults will start to creep up. This means that the operating system will begoing to disk frequently, greatly slowing read and write operations. In the worst case, as data size becomes much larger than available RAM, a situation can occur where, for any read or write, data must be paged to and from disk. This is known as thrashing, and it causes performance to take a severe dive.</p>
<p>MongoDB中read block write，较长时间的磁盘访问会降低并行和吞吐量。</p></blockquote>
<p><strong></strong></p>
<p><strong> </strong></p>
<p><strong>内存是如何影响性能的，推荐是index都被缓存在内存中</strong></p>
<blockquote><p><strong><br />
</strong>It’s important to keep an eye on total index size, as database performance will be best<br />
when all utilized indexes can fit in RAM.</p>
<p>db.stats()<br />
{<br />
&#8220;collections&#8221; : 3,<br />
&#8220;objects&#8221; : 10004,<br />
&#8220;avgObjSize&#8221; : 36.005,<br />
&#8220;dataSize&#8221; : 360192,<br />
&#8220;storageSize&#8221; : 791296,<br />
&#8220;numExtents&#8221; : 7,<br />
&#8220;indexes&#8221; : 1,<br />
&#8220;indexSize&#8221; : 425984,<br />
&#8220;fileSize&#8221; : 201326592,<br />
&#8220;ok&#8221; : 1<br />
}</p></blockquote>
<p><strong><br />
Custom types，例如存储带有时区的时间</strong></p>
<blockquote><p>But what if you must store your times with their time zones? Sometimes the basic BSON types don’t suffice. Though there’s no way to create a custom BSON type, you can compose the various primitive BSON values to create your own virtual type. For instance, if you wanted to store times with zone, you might use a document structure like this, in Ruby</p>
<p>{:time_with_zone =&gt;<br />
{:time =&gt; Time.utc.now,<br />
:zone =&gt; &#8220;EST&#8221;<br />
}<br />
}</p>
<p>算是充分利用文档结构的数据类型</p></blockquote>
<p><strong>a single global reader-writer lock 如何影响并行</strong></p>
<blockquote><p>It’s important to understand how concurrency works in MongoDB.</p>
<p>As of MongoDB v2.0, the locking strategy is rather coarse; <strong>a single global reader-writer lock reigns over the entire mongod instance.</strong> What this means is that at any moment in time, the database permits either one writer or multiple readers (but not both). This sounds a lot worse than it is in practice because there exist quite a few concurrency optimizations around this lock.</p>
<p>One is that the database keeps an internal map of which document are in RAM. For requests to read or write documents not residing in RAM, the database yields to other operations until the document can be paged into memory.</p>
<p>A second optimization is the yielding of write locks. The issue is that if any one write takes a long time to complete, all other read and write operations will be blocked for the duration of the original write. All inserts, updates, and removes take a write lock. Inserts rarely take a long time to complete. But updates that affect, say, an entire collection, as well as deletes that affect a lot of documents, can run long. The current solution to this is to allow these long-running ops to yield periodically for other readers and writers. When an operation yields, it pauses itself, releases its lock, and resumes later. But when updating and removing documents, this yielding behavior can be amixed blessing. It’s easy to imagine situations where you’d want all documents updated or removed before any other operation takes place.</p>
<p>For these cases, you can use a special option called $atomic to keep the operation from yielding. You simply add the $atomic operator to the query selector like so:</p>
<p>db.reviews.remove({user_id: ObjectId(&#8217;4c4b1476238d3b4dd5000001&#8242;),{$atomic: true}})</p>
<p>The same can be applied to any multi-update. This forces the entire multi-update to complete in isolation:</p>
<p>db.reviews.update({$atomic: true}, {$set: {rating: 0}}, false, true)</p>
<p>This update sets each review’s rating to 0. Because the operation happens in isolation,the operation will never yield, ensuring a consistent view of the system at all times.</p></blockquote>
<p><strong><br />
因为单一global RW lock对创建/重建索引的影响</strong></p>
<blockquote><p>you can check the index build progress by running the shell’s <strong>currentOp() </strong>method:10</p>
<p>&gt; db.currentOp()<br />
{&#8221;inprog&#8221; : [{&#8221;opid&#8221; : 58,<br />
&#8220;active&#8221; : true,<br />
<strong>&#8220;lockType&#8221; : &#8220;write&#8221;,</strong><br />
&#8220;waitingForLock&#8221; : false,<br />
&#8220;secs_running&#8221; : 55,<br />
&#8220;op&#8221; : &#8220;insert&#8221;,<br />
&#8220;ns&#8221; : &#8220;stocks.system.indexes&#8221;,<br />
&#8220;query&#8221; : {},<br />
&#8220;client&#8221; : &#8220;127.0.0.1:53421&#8243;,<br />
&#8220;desc&#8221; : &#8220;conn&#8221;,<br />
&#8220;msg&#8221; : &#8220;index: (1/3) external sort 3999999/4308303 92%&#8221;}]}</p>
<p>The last field, msg, describes the build’s progress.</p>
<p><strong>Note also the lockType, which indicates that the index build takes a write lock. This means that no other client can read or write from the database at this time. I</strong>f you’re running in production, this is obviously a bad thing, and it’s the reason why long index builds can be so vexing. We’re going to look right now at two possible solutions to this problem.</p>
<p><strong>Background indexing</strong>If you’re running in production and can’t afford to halt access to the database, you can specify that an index be built in the background. <strong>Although the index build will still take a write lock, the job will yield to allow other readers and writers to access the database.</strong> If your application typically exerts a heavy load on MongoDB, then a background index build will degrade performance, but this may be acceptable under certain circumstances. For example, if you know that the index can be built within a time window where application traffic is at a minimum, then background indexing in this case might be a good choice.</p>
<p>To build an index in the background, specify {background: true} when you declare the index. The previous index can be built in the background like so:</p>
<p><strong>db.values.ensureIndex({open: 1, close: 1}, {background: true})</strong></p>
<p><strong>Offline indexing</strong></p>
<p>If your production data set is too large to be indexed within a few hours, then you’ll need to make alternate plans. This will usually involve taking a replica node offline, building the index on that node by itself, and then allowing the node to catch up with the master replica. Once it’s caught up, you can promote the node to primary and then take another secondary offline and build its version of the index. This tactic presumes that your replication oplog is large enough to prevent the offline node from becoming stale during the index build.</p>
<p>You can do this by dropping and recreating individual indexes or by running the reIndex command, which will rebuild all indexes for a given collection:</p>
<p>db.values.reIndex();</p>
<p>Be careful about reindexing: the command will take out a write lock for the duration of the rebuild, temporarily rendering your MongoDB instance unusable. Reindexing is best done offline, as described earlier for building indexes on a secondary. Note that the compact command,  will also rebuild indexes for the collection on which it’s run.</p></blockquote>
<p><strong><br />
WHEN TO SHARD</strong></p>
<blockquote><p>The question of when to shard is more straightforward than you might expect. We’ve talked about the importance of keeping indexes and the working data set in RAM, and this is the primary reason to shard.</p>
<p>If an application’s data set continues to grow unbounded, then there will come a moment when that data no longer fits in RAM.</p>
<p>To be sure, there are some fudge factors here. For instance, if you have your own hardware and can store all your data on solid state drives (an increasingly affordable prospect), then you’ll likely be able to push the data-to-RAM ratio without negatively affecting performance.</p>
<p>Whatever the case, the decision to shard an existing system will always be based on regular analyses of disk activity, system load, and the ever-important ratio of working set size to available RAM.</p></blockquote>
<p><strong><br />
indexes in shard</strong></p>
<blockquote><p>a few more points about indexes should bekept in mind when running a sharded cluster.</p>
<p>1 Each shard maintains its own indexes. This should be obvious, but to be clear,know that when you declare an index on a sharded collection, each shard builds a separate index for its portion of the collection. For example, when you issued the db.spreasheets.ensureIndex() command via mongos in the previous section, each individual shard processed the index creation command individually.</p>
<p>2 It follows that the sharded collections on each shard should have the same indexes. If this ever isn’t the case, you’ll see inconsistent query performance.</p>
<p>3<strong> Sharded collections permit unique indexes on the _id field and on the shard key only. </strong>Unique indexes are prohibited elsewhere because enforcing them would require intershard communication, which is complicated and still deemed too slow to be worth implementing.</p></blockquote>
<p><strong><br />
Sharding an existing collection</strong></p>
<blockquote><p>You can shard existing collections, but don’t be surprised if it takes some time to distribute the data across shards. Only one balancing round can happen at a time, and the migrations will move only around 100-200 MB of data per minute. <strong>Thus, sharding a 50 GB collection will take around eight hours, and this will likely involve some moderate disk activity. </strong></p>
<p>In addition, when you initially shard a large collection like this, you may have to split manually to expedite the sharding process, since splitting is triggered by inserts.</p>
<p>最好还是从一开始就设计好sharding</p></blockquote>
<p><strong><br />
MANUAL PARTITIONING</strong></p>
<blockquote><p>There are a couple of cases where you may want to manually split and migrate chunks on a live shard cluster. For example, as of MongoDB v2.0, the balancer doesn’t directly take into account the load on any one shard. Obviously, the more a shard is written to, the larger its chunks become, and the more likely they are to eventually migrate. Nevertheless, it’s not hard to imagine situations where you’d be able to alleviate load on a shard by migrating chunks. This is another situation where the movechunk command can be helpful.</p>
<p>&gt; sh.splitAt( &#8220;cloud-docs.spreadsheets&#8221;,<br />
{ &#8220;username&#8221; : &#8220;Chen&#8221;, &#8220;_id&#8221; : ObjectId(&#8221;4d6d59db1d41c8536f001453&#8243;) })</p>
<p>&gt; sh.moveChunk(&#8221;cloud-docs.spreadsheets&#8221;, {username: &#8220;Chen&#8221;}, &#8220;shardB&#8221;)</p>
<p>比方说hot chunk,通过手工migration，可以将hot chunk分散到多个shards中。</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://yumianfeilong.com/html/2011/12/27/538.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>宝宝新动态</title>
		<link>http://yumianfeilong.com/html/2011/12/17/537.html</link>
		<comments>http://yumianfeilong.com/html/2011/12/17/537.html#comments</comments>
		<pubDate>Sat, 17 Dec 2011 07:39:45 +0000</pubDate>
		<dc:creator>yumianfeilong</dc:creator>
		
		<category><![CDATA[Family]]></category>

		<category><![CDATA[Favorites]]></category>

		<category><![CDATA[宝宝]]></category>

		<guid isPermaLink="false">http://yumianfeilong.com/?p=537</guid>
		<description><![CDATA[5个月大的宝宝已经脱离了频繁吃小手的低级趣味，开始翻身和搓小脚了。而且还会抓人，手上的力气也大了，不但抓别人，还抓自己，时常会看到宝宝使劲的抓自己脑袋，偶尔还会抓破，对自己比较狠狠狠。
宝宝目前只会主动的往右侧翻身，猜测如果是左撇子的话，小孩会不会往左侧翻身。
宝宝喜欢电视了，而且看电视的时候特别老实，不乱动。白天录制的DV，晚上关灯投影在墙上，宝宝看的一动不动的，也不翻身也不搓脚，对小孩非常具有吸引力。
最近开始给宝宝喂蛋黄，每天1/5个蛋黄混着水，宝宝也不拒绝；还用小勺子挖苹果沫沫喂宝宝，虽然拉过一次绿便，但宝宝精神头依然旺盛。
]]></description>
			<content:encoded><![CDATA[<p>5个月大的宝宝已经脱离了频繁吃小手的低级趣味，开始翻身和搓小脚了。而且还会抓人，手上的力气也大了，不但抓别人，还抓自己，时常会看到宝宝使劲的抓自己脑袋，偶尔还会抓破，对自己比较狠狠狠。</p>
<p>宝宝目前只会主动的往右侧翻身，猜测如果是左撇子的话，小孩会不会往左侧翻身。</p>
<p>宝宝喜欢电视了，而且看电视的时候特别老实，不乱动。白天录制的DV，晚上关灯投影在墙上，宝宝看的一动不动的，也不翻身也不搓脚，对小孩非常具有吸引力。</p>
<p>最近开始给宝宝喂蛋黄，每天1/5个蛋黄混着水，宝宝也不拒绝；还用小勺子挖苹果沫沫喂宝宝，虽然拉过一次绿便，但宝宝精神头依然旺盛。</p>
]]></content:encoded>
			<wfw:commentRss>http://yumianfeilong.com/html/2011/12/17/537.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>跳楼的结局</title>
		<link>http://yumianfeilong.com/html/2011/11/25/535.html</link>
		<comments>http://yumianfeilong.com/html/2011/11/25/535.html#comments</comments>
		<pubDate>Fri, 25 Nov 2011 03:40:30 +0000</pubDate>
		<dc:creator>yumianfeilong</dc:creator>
		
		<category><![CDATA[NoFeeling]]></category>

		<guid isPermaLink="false">http://yumianfeilong.com/?p=535</guid>
		<description><![CDATA[模特先跳，图片传来。

几棵大葱从13楼落下，成了这个模样。有的葱头摔没有了，有的葱肚子爆炸了，葱体都变的松软了。中午就把它们做成葱爆肉，应该很好吃。
谁的单位有鸭梨大想不开的，就多吃点大葱吧。
我无压力，最后表示，别担心我；大葱只是因为北风太大从阳台上吹落的。
]]></description>
			<content:encoded><![CDATA[<p>模特先跳，图片传来。</p>
<p><a href="http://yumianfeilong.com/wp-content/uploads/2011/11/dacong.jpg"><img class="aligncenter size-medium wp-image-536" title="dacong" src="http://yumianfeilong.com/wp-content/uploads/2011/11/dacong-300x195.jpg" alt="" width="300" height="195" /></a></p>
<p>几棵大葱从13楼落下，成了这个模样。有的葱头摔没有了，有的葱肚子爆炸了，葱体都变的松软了。中午就把它们做成葱爆肉，应该很好吃。</p>
<p>谁的单位有鸭梨大想不开的，就多吃点大葱吧。</p>
<p>我无压力，最后表示，别担心我；大葱只是因为北风太大从阳台上吹落的。</p>
]]></content:encoded>
			<wfw:commentRss>http://yumianfeilong.com/html/2011/11/25/535.html/feed</wfw:commentRss>
		</item>
		<item>
		<title>enq: US - contention</title>
		<link>http://yumianfeilong.com/html/2011/11/22/534.html</link>
		<comments>http://yumianfeilong.com/html/2011/11/22/534.html#comments</comments>
		<pubDate>Tue, 22 Nov 2011 09:27:53 +0000</pubDate>
		<dc:creator>yumianfeilong</dc:creator>
		
		<category><![CDATA[Boring]]></category>

		<category><![CDATA[Oracle]]></category>

		<guid isPermaLink="false">http://yumianfeilong.com/?p=534</guid>
		<description><![CDATA[这是oracle10g中开始出现的bug，当因为系统activity增加或者降低的时候，oracle SMON进程会自动ONLINE或者OFFLINE rollback segments。这样导致某些与undo segments相关的latch或者enqueue被hold住太长时间，导致系统很多活跃session都开始等待enq: US - contention。
可以同时使用以下解决方法:
1. 设置event让SMON不自动OFFLINE回滚段。
alter system set events &#8216;10511 trace name context forever, level 1&#8242;;
2. 设置参数_rollback_segment_count ：表示有多少rollback segment要处于online的状态；可以将该数值设置为数据库最繁忙的时候的回滚段数目。
alter system set &#8220;_rollback_segment_count&#8221;=;
3.  undo autotune bug多多。最好disable。
alter system set &#8220;_undo_autotune&#8221; =  false;
4.  有一个patch: A fix to bug 7291739 is to set a new hidden parameter,  _highthreshold_undoretention to set a high threshold for [...]]]></description>
			<content:encoded><![CDATA[<p>这是oracle10g中开始出现的bug，当因为系统activity增加或者降低的时候，oracle SMON进程会自动ONLINE或者OFFLINE rollback segments。这样导致某些与undo segments相关的latch或者enqueue被hold住太长时间，导致系统很多活跃session都开始等待enq: US - contention。</p>
<p>可以同时使用以下解决方法:</p>
<p>1. 设置event让SMON不自动OFFLINE回滚段。</p>
<p>alter system set events &#8216;10511 trace name context forever, level 1&#8242;;</p>
<p>2. 设置参数_rollback_segment_count ：表示有多少rollback segment要处于online的状态；可以将该数值设置为数据库最繁忙的时候的回滚段数目。</p>
<p>alter system set &#8220;_rollback_segment_count&#8221;=;</p>
<p>3.  undo autotune bug多多。最好disable。</p>
<p>alter system set &#8220;_undo_autotune&#8221; =  false;</p>
<p>4.  有一个patch: A fix to bug 7291739 is to set a new hidden parameter,  _highthreshold_undoretention to set a high threshold for undo retention  completely distinct from maxquerylen.</p>
<p>alter system set  &#8220;_highthreshold_undoretention&#8221;=;</p>
<p>UNDO TABLESPACE是8i到9i最好的改进之一；可惜在10g中bug多多。</p>
<p><span id="more-534"></span></p>
<blockquote><p>How to correct performance issues with enq: US - contention related to undo segments [ID 1332738.1]</p>
<p>Applies to:</p>
<p>Oracle Server - Enterprise Edition - Version: 9.2.0.1 to 11.2.0.2 - Release: 9.2 to 11.2<br />
Information in this document applies to any platform.<br />
Purpose</p>
<p>Assist in correcting performance issues related to &#8220;enq: US Contention&#8221; on undo segments.</p>
<p>You have many offline undo segments and the workload starts to online many undo segments over a short period of time. This can lead to high &#8216;latch: row cache objects&#8217; contention may be seen on dc_rollback_segments together with high &#8216;enq: US - contention&#8217; waits when using system managed undo with an auto tuned undo retention period.</p>
<p>Sessions attempting to online undo segments should show ktusmous_online_undoseg() in their call stack.</p>
<p>Another aspect of the problem can be due to long running queries which can raise tuned_undoretention to very high values and exhausts the undo tablespace resulting in ORA-1628.</p>
<p>A real world case:<br />
A query is being executed and some rows are fetched from the cursor and then the user stops working on that query (e.g. does not press the &#8220;next&#8221; button on the application screen) and works on something else (e.g. in a different window). After some time the user continues working on the query &#8230; auto-tune starts tracking the query from this point and the maxquerylen is quite large now, hence also the tuned_undoretention (that depends directly on the maxquerylen).</p>
<p>NOTE: The Seibel application can allow for this problem to happen.<br />
Last Review Date</p>
<p>June 24, 2011<br />
Instructions for the Reader<br />
A Troubleshooting Guide is provided to assist in debugging a specific issue. When possible, diagnostic tools are included in the document to assist in troubleshooting.<br />
Troubleshooting Details</p>
<p>The wait event &#8220;enq: US Contention&#8221; is associated with contention on the latch in the row cache (dc_rollback_seg).  Enqueue US - Contention can become a bottle-neck for performance if workload dictates that a lot of offlined undo segments must be onlined over a short period of time. The latch on the row cache can be unable to keep up with the workload.</p>
<p>This can happen for a number of reasons and some scenarios are legitimate workload demands.</p>
<p>Solution:</p>
<p>Ensure that peaks in onlined undo segments do not happen (see workaround #2). That is not always feasible.</p>
<p>Workarounds:</p>
<p>1. Bounce the instance.</p>
<p>2. Setting _rollback_segment_count to a high number to keep undo segments online.</p>
<p>alter system set &#8220;_rollback_segment_count&#8221;=;</p>
<p>3. Set _undo_autotune to false</p>
<p>alter system set &#8220;_undo_autotune&#8221; = false;</p>
<p>NOTE: Simply using _smu_debug_mode=33554432 may not be enough to stop the problem, but valid fix for bug 5387030.</p>
<p>4. A fix to bug 7291739 is to set a new hidden parameter, _highthreshold_undoretention to set a high threshold for undo retention completely distinct from maxquerylen.</p>
<p>alter system set &#8220;_highthreshold_undoretention&#8221;=;</p>
<p>If problems persist, please file a Service Request with Oracle Support.</p>
<p>@ Diagnosis<br />
@<br />
@ Should the workarounds and/or configuration changes not help to alleviate the problems,<br />
@ development would need the following diagnostics data:<br />
@<br />
@ a. Provide alert.log which shows the last instance startup parameters through the time of the<br />
@ latest isssues.<br />
@<br />
@ b. AWR and/or ASH report of 30 or 60 minutes interval.<br />
@<br />
@ b. Following query output:<br />
@<br />
@ alter session set nls_date_format=&#8217;mm/dd/yy hh24:mi:ss&#8217;;<br />
@ select begin_time, MAXQUERYID, MAXQUERYLEN from v$undostat;<br />
@<br />
@ c. While the error is ongoing:<br />
@<br />
@ On single instance:<br />
@<br />
@ sqlplus / as sysdba<br />
@ oradebug setmypid<br />
@ oradebug unlimit<br />
@ oradebug hanganalyze 3<br />
@ oradebug dump systemstate 266<br />
@<br />
@ wait for 5 seconds<br />
@<br />
@ oradebug dump systemstate 266<br />
@<br />
@ wait for 2 minutes<br />
@<br />
@ sqlplus / as sysdba<br />
@ oradebug setmypid<br />
@ oradebug unlimit<br />
@ oradebug hanganalyze 3<br />
@ oradebug dump systemstate 266<br />
@<br />
@ wait for 5 seconds<br />
@<br />
@ oradebug dump systemstate 266<br />
@<br />
@ On RAC get tracing on all nodes<br />
@<br />
@ sqlplus / as sysdba<br />
@ oradebug setmypid<br />
@ oradebug unlimit<br />
@ oradebug -g all hanganalyze 3<br />
@ oradebug -g all dump systemstate 266<br />
@<br />
@ wait for 5 seconds<br />
@<br />
@ oradebug -g all dump systemstate 266<br />
@<br />
@ wait for 2 minutes<br />
@<br />
@ sqlplus / as sysdba<br />
@ oradebug setmypid<br />
@ oradebug unlimit<br />
@ oradebug -g all hanganalyze 3<br />
@ oradebug -g all dump systemstate 266<br />
@<br />
@ wait for 5 seconds<br />
@<br />
@ oradebug -g all dump systemstate 266<br />
References</p>
<p>BUG:12652689 - HIGH ENQ: US - CONTENTION AFTER UPGRADED TO 11.1.0.7.5<br />
BUG:7279902 - US ENQUEUE CONTENTION OCCURS DUE TO WAITING FOR &#8220;GC CURRENT REQUEST&#8221;<br />
BUG:7291739 - CONTENTION UNDER AUTO-TUNED UNDO RETENTION<br />
BUG:9557199 - MASSIVE WAITS FOR &#8216;ENQ: US - CONTENTION&#8217; AND ROW CACHE LOCK IN STRESS TEST<br />
NOTE:5387030.8 - Bug 5387030 - Automatic tuning of undo_retention causes unusual extra space allocation<br />
NOTE:7291739.8 - Bug 7291739 - Contention with auto-tuned undo retention or high TUNED_UNDORETENTION<br />
NOTE:742035.1 - Contention Under Auto-Tuned Undo Retention</p></blockquote>
<blockquote>
<div id="feedbackBox" style="display: none; position: absolute; top: 268px; background-color: #fffeed;">
<form>
<input id="articleId" name="articleId" type="hidden" value="1332738.1" />
<input id="feedBackText" name="feedBackText" type="hidden" value="Thank you for your feedback. Please help us to improve our content; comments are required when selecting a rating of " />
<input id="initialCommentText" name="initialCommentText" type="hidden" value="Provide feedback for this article. Please use 'Contact Us' for other feedback." />
<table class="tables" style="height: 100%;" border="0" width="100%">
<tbody>
<tr>
<td class="tables" width="100%" height="100%" valign="top">
<div style="font-weight: bold; font-size: 12px; color: #364a8d;">Article Rating</div>
<table border="0" width="240">
<tbody>
<tr>
<td style="font-weight: bold; font-size: 12px;">Rate this document</td>
</tr>
<tr>
<td style="font-size: 12px;">
<input id="rating" name="rating" type="radio" value="3" />Excellent</td>
</tr>
<tr>
<td style="font-size: 12px;">
<input id="rating" name="rating" type="radio" value="2" />Good</td>
</tr>
<tr>
<td style="font-size: 12px;">
<input id="rating" name="rating" type="radio" value="1" />Poor</td>
</tr>
<tr>
<td class="horizontalLine" width="100%"></td>
</tr>
<tr>
<td style="font-weight: bold; font-size: 12px;" width="100%">Did this document  help you?</td>
</tr>
<tr>
<td style="font-size: 12px;">
<input id="relevancy" name="relevancy" type="radio" value="3" />Yes</td>
</tr>
<tr>
<td style="font-size: 12px;">
<input id="relevancy" name="relevancy" type="radio" value="2" />No</td>
</tr>
<tr>
<td style="font-size: 12px;">
<input id="relevancy" name="relevancy" type="radio" value="1" />Just browsing</td>
</tr>
<tr>
<td class="horizontalLine" width="100%"></td>
</tr>
<tr>
<td style="font-weight: bold; font-size: 12px;" width="100%">How easy was it to  find this document?</td>
</tr>
<tr>
<td style="font-size: 12px;">
<input id="easeOfUse" name="easeOfUse" type="radio" value="3" />Very easy</td>
</tr>
<tr>
<td style="font-size: 12px;">
<input id="easeOfUse" name="easeOfUse" type="radio" value="2" />Somewhat easy</td>
</tr>
<tr>
<td style="font-size: 12px;">
<input id="easeOfUse" name="easeOfUse" type="radio" value="1" />Not easy</td>
</tr>
</tbody>
</table>
</td>
<td class="verticalLine"></td>
<td width="100%" height="100%" valign="top">
<div style="font-weight: bold; font-size: 12px; color: #364a8d;">Comments</div>
<p><textarea id="commentsInput" class="labelTextareaEmpty" style="font-size: 12px; color: black;" cols="70" rows="14" name="commentsInput">Provide feedback for this article. Please use &#8216;Contact Us&#8217; for other feedback.</textarea></td>
</tr>
</tbody>
</table>
</form>
</div>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://yumianfeilong.com/html/2011/11/22/534.html/feed</wfw:commentRss>
		</item>
	</channel>
</rss>

