2012年10月10日

OMG Facts of Moon Festival and National Holidays in China

1. Moon Festival
Also knows as Mid-Autumn Festival, together with Spring Festival, are two big events for Family reunion, which are as important as Thanksgiving and Christmas in US.
One tradition of this festival is to eat Moon Cake, which is only eaten during the festival, kind like Turkey for Thanksgiving.
It's not yet confirmed how this festival has been invented, some people think it related to the timing of Mid-Autumn, which means harvest and people think in that day the Moon is closest to The Earth, so it should be biggest and brightest of the year.
For ancient China is an agricultural country, it's very reasonable to hold a big event to celebrate harvest.
And people had a very serious relationship with The Moon, for Moon means romantic and homesick.
Thoughts of poetries have been dedicated to the Moon.
About 2 thoughts of years ago, China Kingdom had begun to use professional officials to rule the country, most of these officials are educated with classic books, and poetries are important part of it. And after these people passed certification and have been selected to rule, normally they had to transfer into a strange palace rather than their home town.
And as it is said, even the Moon is brighter in my home town. The Moon created a emotional connection to home.
Even now, millions of people have to work and live in the city out of home town, and the Moon means sweat home, it connects people from very far away.
One of the most famous poetries of Moon is written by Su Shi at almost 1 thought years ago:
---------------------------------------------------------------------
Title: 水调歌头 明月几时有 When will the moon be clear and bright?

When will the moon be clear and bright?
With a cup of wine in my hand, I ask the blue sky
what season it would be up the heaven for tonight.

Oh Moon, how I wish to get closer
By riding on the breeze.
Yet I fear your crystal and jade chateau,
Are much too high and cold.
So, let me just dance here with my moonlight shadow.

Rounds and rounds, my red mansion, till you shine on my silk pillow,
Sleepless, but bearing no regrets
Blame not the full moon when people has to apart
Sorrow or joy, be near or far,
Things happen like that, and we still believe in fate.

Toast to you, we are all be blessed
Though distant away, we look at the same moon
And in that way, we have never been apart.

Su Shi (translated by Charles Hartman)
---------------------------------------------------------------------

More information please refer to WIKI: http://en.wikipedia.org/wiki/Mid-Autumn_Festival

2. National Holidays
From 1 Oct to 7 Oct, it's China's National Holidays, to celebrate the establishment of PRC in 1949.
The government made this policy to encourage people to travel and consume during this holidays, so National Holidays is also been called as Golden Holidays.
A special policy for this year's National Holidays is to cancel highway tolls during the holidays.
In China, the price of a new passage car is around 25% to 100% more expensive than same model in US. The gas price is almost twice of US, and the highway tolls costs almost same money of gas, that means if people chose to travel by car, the spending is almost 4 times of in US.
Highway tolls means a lot of money, which is almost 1 billion US Dollars from 30 Sep to 7 Oct.
Till the end of 2011, there're over 10 million passenger cars in China, and a lot of them want to take the advantage, so lots of cars were trapped in the free highways, people were stopped for hours, and some walk dogs, or play badminton just in highway, or use telescope the check the status ahead.


And almost 100 people were killed in car accidents everyday.
Yet the worst traffic situation was happened outside Capital city Beijing in 2010, cars were trapped over 62 miles for 12 days.
As for this year's Golden Holidays, another issue is people crowded almost everywhere, here're photos taken in Forbidden City and The Great Wall.




So don't bother to travel China during any China's National Holidays, I'm not kidding.


2012年10月9日

BBC睡眠十律

一、睡前洗澡:洗澡时体温升高不是让人产生睡意的原因,不过体温升高后的体温下降阶段人会产生睡意。所以睡前洗个热水澡,让体温升高,在其后的体温下降时段会比较容易入睡。

二、睡眠限制:每天只在固定的时间呆在床上,比如12点到第二天早上8点,这样可以调整好混乱的睡眠。

三、打盹法:.打盹可以补充晚上的睡眠不足,一般最佳时间是下午12点至5点之间。

四、打鼾是一种病,可能与心脏与血压高有关。会影响自己和伴侣的睡眠质量。

五、咖啡和酒对睡眠质量的影响。咖啡会让人保持清醒,难以入睡。喝酒会容易让人产生困意,但是入睡后的后半夜睡眠质量不佳。

六、光线疗法:光线对睡眠质量有一定的影响。光线会经过眼底刺激大脑,使人体内的褪黑素发生变化。光线弱时褪黑素多,人会昏昏欲睡;光线强时(特别是蓝色灯光),褪黑素减少,人会清醒。睡之前拉上房间窗户可改善你的睡眠质量。(注意:长期服用褪黑素药物会有副作用:晚上睡眠变浅,白天眼皮沉重,没有精神,记忆力下降等)

七、食物疗法:碳水化合物含量多的食物能让人产生困意,蛋白质含量多的能让人保持清醒。

八、挨饿16个小时左右可以重置人体的生物钟,饱餐会让你的睡眠质量受损。

九、肌肉放松法:在睡觉前15分钟,进行肌肉紧张、放松练习,可以更好地进入睡眠。。

十、药物疗法:薰衣草和缬草等草药可以帮助改善睡眠。

2012年9月12日

科幻小说《考古》


我一直怀疑我的邻居是个外星人。他那古怪的额头,还有可笑的口音,常常引得人们围观哄笑。所以我常常叫他"老外 ",意思是别瞒我了,我知道你是外星人。
晚上看完电影《黑衣人3》回来,我们一起到小区楼下的小饭馆喝酒。老外特别喜欢喝瓶装的燕京啤酒,而我喜欢喝扎啤 ,我们经常一起点上几个小菜,有一搭没一搭地喝。老外和我一样有失眠症,有时夜深了他会到我这里喝酒。他比我年长十岁,有时除了取笑他是个外星人以外,我会怂恿他讲讲自己的事,这时他就编一些火星漫游之类的故事逗我玩,有时我们会比赛看谁编的故事更离谱。
但是今天晚上喝过酒以后,老外突然慢慢地说:"能陪我一起走会儿么?我想我很快会和你告别了。"于是我们一起晃晃悠悠地走上了三环。
此时夜色已深,我突然意识到这个城市变得安静,立交桥就象一个个疲惫的怪兽,无声地栖息在夜的阴影里,一轮暗黄的月亮斜斜地挂在天边。
老外说道:"我不是外星人,但是我来自未来世界。"我有点吃惊,但又仿佛早已预料到了,于是我一边走,一边听着他讲这个奇怪的故事。
原来在地球上,文明经历了漫长的时间而没有消失,但是世界变化很大,科技也有了很大的变化。有一天,科学家在观测一个银河系外围的黑洞时,发现从里面逃逸出很多的信号,经过转换分析,人们惊讶地发现,许多信号原来记录的是很多世纪以前地球人类的生活。这也许是某个外星智慧观察者所留下的记录,但不管怎样样,这个信号源源不断地输出给地球,变成了人们最大的娱乐项目。但是这个观察的角度是有限的,因此看上去就象若干个频道在不停地播放着关于过去生活的肥皂剧,并且剧情是不连贯的。
"这非常有趣",我说,"在我小的时候,在夏夜,当我站在院子里,看着遥远的星星,我常常在想,会不会有一双眼睛在一直盯着我看。"
"很可能,但是刚好看到你的机率实在是太小了",老外说。
通过这种方式观察别人的生活,这是一种非常奇特的感受,仿佛过去和现在叠加在一起,相互缠绕。
"呈现在你眼前的画面是如此真实,不禁让人感同身受。当看着别人正在做出一个艰难的决定时,你不会意识到,这个决定,其实在若干个世纪之前已经发生。"
另一方面,以未来的眼光看待过去,往往会给过去披上一层浪漫的面纱,从而显得分外迷人。
"当然,在某些方面,你的这个世纪确实比我的世界浪漫得多。比如说,在我们的时代,月亮消失了。"
"这怎么会呢?"
"怎么不会?在两百年前,有一颗小行星接近地球,为了保护地球的生命,人类用核弹改变了月亮的轨道,让它与小行星相撞。地球得到保护了,但是月亮也撞成了碎片,肉眼是看不到了。"
我很吃惊,因为我无法想象没有月亮的世界。没有了月亮,意味着那个千百年来,人们通过诗篇共同构筑的瑰丽想象世界消失了,夜就不再有夜的味道了。
"所以当我看到信号中出现过去的月亮时,我总是看得如痴如醉。"
"难怪你经常深夜出来喝酒,是不是为了看月亮啊?"我打趣道。
"早看饱了。"
"好吧,趁着夜色无边,讲讲你的艳遇吧。"
"有一回,我在信号上看到了南国的风景,是深夜,某个湖边,湖水微微地荡漾,将月光打得粉碎又慢慢地揉成一团。风吹着树叶,而路灯就象湖滨的杨柳,温柔地起伏在高楼的阴影里。"
"那一定是西湖。"
"是的。然后我看到一个女孩,慢慢地沿着湖堤行走,我看不到她的脸,但是风不时地吹拂她的长发。突然间,我曾读过的一首诗从脑海中跳跃而出。。。"
"塞纳河在米拉博桥下流着/而我们的爱情/我必须追忆么/那痛苦后面往往是欢乐/愿黑夜来临愿钟鸣响啊/时日在飞逝而我却滞留着。。。"
"你一定是爱上这个女孩了。"
"没办法的事,何况在这样的一个月夜。"
"你是因为这个来到我们时代的吗?这样倒是好理解了。"
"是的,在我们的时代,科学家们已经发明了时间机器,但是和科幻小说里所描写不同的是,所有的时间机器都是单程使用的,就是说一旦你进入了某个设定的时间后,你就回不去了。"
"那么,你是被困在我们这个时代了。不知道刚说你是勇敢还是笨。"
"其实你们这个时代挺不错的。我愿意留下来。"
"接着说那个女孩的事。"
"过来之后,我找到了那个女孩。"
"后来呢?"
"我们恋爱,结婚,然后又分手了。"
"啊?你大老远地过来,就这样子结束啊?"
"这很正常,非常正常。"
"能说说你们分手的原因吗?"
"小秋她很漂亮,也很温柔。我们曾经相处得很好,但是两个人处一辈子实在是太难了。象我,经常和周围格格不入,而她,仿佛永远长不大,太孩子气了。我们都曾经试着去改变对方,但是要改变一个人是很难甚至是徒劳的。所以最终我们选择了放弃。"
"那么最终你选择了一个人孤独地漂泊在异时代?"
"其实,我来到这个时代,除了恋爱以外,是有使命的。"
"哦",我一下子有了兴趣,"说说看,是什么使命?"
"用我们的话说,是考古。"
"时间旅行是很昂贵的,象我一介平民,怎么拿得出那么一大笔钱?所以我们和政府签订协议,用考古来作为交换。"
所谓考古,是指当时间旅行者来到古代以后,要以历史亲历者的身份记录那个时代的生活,并撰写成文字流传到他们的时代,以作为文明传承的借鉴。
"说起来,文字的流传可不容易,你们怎么保证能够将记录完整地保存到你们的时代呢?"
"所以我们在时间旅行之前会先进行写作的培训,掌握一定的技巧。此外我们会有一些基金会提供赞助,以方便记录的印刷和保存。"
我笑道,"难道说诺贝尔基金会的钱你们也投了?难道说诺贝尔文学奖获得者中也有不少是时间旅行者?"
老外笑了笑,"也许吧。"
"我说呢,他们怎么能够从那么不一般的视角来看待所处的世界。"
"其实你们中国古代也有不少诗人和哲学家也是已确认的考古者。"
"我猜庄子和李商隐应该是。象庄周梦蝶完全是记录来到另一个世界的经验,而李商隐的《夜雨寄北》、《锦瑟》更是直白地描写了时间旅行带来的惆怅。"
他笑了笑,"也许吧,原谅我不能透露得更多,这是我对他们保持尊敬的方式。"
我问道:"那么你呢?你写得怎么样了?潜伏在我身边的大作家?"
他摇了摇头,"才刚刚开始写。"
突然他抬起头来,"朋友我要和你告别了。我要去别的地方去听听、看看。"
这时我们已经走到了通惠河边,我知道是分手的时候了。
我说道,"那么老外,你在时间旅行的过程中,有什么时刻是特别完美的吗?"
他严肃起来,说道,"在我经历的所有时刻中,并没有一个时刻比别的时刻更加完美,每一个时刻都值得你去用生命细细体会。"
他指着天边的明月,"在一些时代里,月亮连接了千万代人的内心世界,是文明的永恒象征。但是在另一些时代,已经消逝的生命却依然鲜活地呈现在后人面前。所以生命虽然短暂而又渺小,但是却比月亮更为悠长。而时间就象河流,时而和缓时而狂暴,时而坚硬成冰,时而弥漫如雾,在河边的人们一代代地跨过时间之河,却看不到河的源头和归宿。而人们在河边的身影就幻化成文明。"
我们握手道别,我呆呆地看着他的身影从远处的路灯下消失,而天空象个漏斗一样倒挂下来。
我突然觉得疲倦,就走到河边的躺椅下,躺下来休息。我迷糊地想到,也许老外只是我的一个想象,也许我一觉醒来会意识到自己才是个时间旅行者,又或者我会发现自己变成了一条鱼,好奇地向上看着这个世界。
总之,我睡着了。

2012年9月8日

房事2007(三)

前面说了,房产开发的实质是将土地变现。因此,伴随着房产的开发,社会财富随之增加,因而在市场上流通的货币也随之增加。那么为什么前几年没有因为这个原因而发生通货膨胀呢?
考虑一下影响货币流通量的因素。
除了土地变现和国有企业资产变现以外,还有2个重要因素会增加货币流通量。
1是引进外资和贸易顺差。外资进入中国,必须通过政府银行兑换成人民币在国内流通,企业出口赚的外汇也必须兑换成人民币。对于这部分人民币,政府并不是从国库里拿的,而是直接增加印刷量,从而造成供应量增加。
2是银行坏账。政府除了财政拨款外,也会通过增发人民币来填补银行的坏账。
而下面的3个因素会减少货币的流通量。
1是居民储蓄,存入银行的钱多了,用于消费的钱就少了。
2是国债,购买国债就是将钱直接存入国库。
3是加息,鼓励国民将更多的钱存入银行,并抑制投资。
老百姓为了抵抗房产、教育、医疗这三座大山,不得不选择将自己的更多收入存到银行,并因此节衣缩食,努力减少在其它方面的花费。在社会投入总量变化有限的范围内,投到房产、教育、医疗的钱越多,那么投到食品等日常消费领域的钱就越少。
对比一下我国的改革和俄罗斯的改革,可以看到很有趣的东西。
俄罗斯采用休克疗法实现私有制,也就是通过将国有资产拆成全民股份,然后一人一份分了。因而国民财富通过这种方式一次性折现,造成通货迅速增加,货币对内迅速贬值。为了对付通货膨胀,政府逐年提高国民工资收入,从而加强国民的购买力,打开国内市场。
两国的改革有以下共同点:一是本质都是将国有资产私有化,明确产权。二是引入外资增加货币的供应量。三是改革的结果造成了贫富分化,出现了不同的利益团体。
两国改革的不同点有:一、俄罗斯采用剧烈变革,中国是渐进变革,前者是短痛,后者是长痛。二、俄罗斯在改革前后保障国民的住房、医疗、教育等基本福 利,因此老百姓可以承受通货膨胀的压力。而我国由于受8.9事件的影响,对通货膨胀特别敏感,所以通过住房、医疗、教育来抑制通膨。三、俄罗斯通过卖石油 来引进外资,而我国通过廉价矿产、劳动力来引进外资。四、俄罗斯的改革名义上人人受益,但是引发政治的动荡。中国的土地和国有资产拍卖老百姓无份参与,但 是他们用这部分损失换来了政治上的稳定。

2012年8月21日

[歌词] 希望和悲伤

看不清,你那闪烁的眼睛
听不清,你那隐约的耳语
你的心,仿佛忽远又忽近
我的心,猜不透你我的结局

慢慢靠近,缩短你我的距离
依然小心,避免莫名的抗拒
回首往事,你曾开心地鼓励
搜寻记忆,欢笑陪伴着泪水

而泪水,记录了一天又一天
而欢笑,憧憬着一夜又一夜

希望和悲伤只是我的幻觉
在梦里依然期盼你的出现
不要说过去只是美丽的错误
就让一切留待明天去回忆

希望和悲伤不是我的幻觉
在梦里依然看见你的出现
如果说过去只是美丽的错误
就让一切留待明天去回忆

2012年8月8日

The 5S Rules in IT System Design



Here 5S Rules means: Simple, Solid, Strong, Safe, Smart.

Simple
Simple means: 1. the logic is easy to understand; 2. the architecture has weak coupling connections.

According to Modular Design methodology, generally during design, we firstly define the Domain of the system, and then define Modules within system, and then define Function Points within Module.

When wo do Top-Down design, it's easy to follow Simple Rule, but sometimes the Function grows slowly, it extends from a Function Point to a whole system, in that case, we need to reconstruct the system design, and that's painful.

Let's take an example of Manufacturing System.

There's a work station in the workshop, which needs a worker to do assemlby and quality check after that. So strictly speaking, this worker combins 2 roles: Operator and Quality-checker. But since it requires low skill level and long cycle time, so these 2 functions have been combined to 1 single person. Accordingly, the IT system writes 1 single Logic for that.

But as it requires shorter cycle time and higher efficiency, new worker has been recruted, so this workstaton has been extended to 2 workstations shared with 2 persions, 1 for assembly, 1 for quality checking. At that point, IT system will also be required to split the funtion into 2 Function Points.

To reduce development time, we might add some IF THEN ELSE judgement into original logic, and then different role executes different logic block. That means, load the whole logic first, then execute its sub-logic-block.

Another solution is, analyze the request following Simple Rule even during original design, to package Assembly & Quality-check logic into different Logic Block, and then combine the Logic Block during deployment. That means, 1 person will be assigned with 2 roles' logic before change, and 2 persons will be assigned with their own roles with their own Logic Blocks after change. The background codes only covers Logic Block, and frontground will display it according to role-logicblock configuration.

Solid
Solid means: The logic need to be solid and complete.

The completeness of business logic could help to reduce system exception, and increse system availability.

An effective method of executing Solid Rule is to run Black-box test, let users to write test cases, let users to do the acceptance test.

Because developing guys focus on nornal work flow mostly, but users notice more exceptional work flow, and the test for exceptional work flow helps to increase the completeness of business logic.

Strong
Strong means the system needs to be strong, can support multiply sessions, lots of users, huge data. The system needs to reduce down time throughout all kinds of methods.

As for hardware, we may use Cluster, Load Balance and other technology to increse system availability.

As for software, we may use Cache, Read-write seperation, User grouping, Redundancy, Archive, Database Partition, and other technology to reduce computing time.

One simple method of keeping strong is to find the Bottle Neck of the problem. For example, the bottle neck of one system is running one specific report, which may cause long time waiting if several persons are running it in the same time. The resolution is to increase hardware performance to reduce query time, or to optimize query SQL and Table struchture, or to dispatch report with user permission, such as running report in advance during free time.

Safe
Safe means to avoid service interruptions by all means.

The Black Swan Inccidents - unpredictable exceptional inccidents - are difficult to avoid, the resolution is to accumulate problem resolving methods, and deal with exceptions by alert, logging, notification, so the system can continue to serve.

It will be good to desing a configurable Exception-handling Module, which could take exceptions quickly without rewriting core codes.

Smart
Smart means to use smart methods.

Now we have a lot of open source codes, modules, methodology, and a lot of internet appplications might be introduced into Enterprise systems.

For example, Map-Reduce is known as Google's methodology, it has been used in lots of web sites, and actually we could use it to simplize logic blocks with a lot of IF THEN ELSE judgement.

IT系统设计中的5S原则



5S原则:Simple, Solid, Strong, Safe, Smart.

Simple
Simple就是简单原则,这里的简单有两个意思,一个是逻辑简单容易理解,另一个是架构简单耦合性弱。
按照模块化设计的方法,通常我们在设计时,首先界定系统的边界,然后在系统内划分模块,然后在模块内划分功能点。
通常在进行自顶向下设计的时候,Simple原则是很容易遵守的,但是有时功能是在慢慢增强的,从一个功能点成长为一个系统,在后期开发的时候往往会对前期的设计进行重构,这是相当痛苦的。
举一个制造系统的例子。
比如车间有一个工位,要求工人做装配的活,装配完成后做质量检查。严格地说,这个工人集成了两个角色:装配工和质检员,但是由于生产技术难度低,对生产节拍要求也低,因此为了节省人力成本,这两个动作由同一个人完成。而对应的IT系统功能将逻辑也统一起来,以方便用户操作。
但是后来生产节拍要求越来越高,为了提升效率,车间招募了新的工人,一个工位变成了两个工位,一个人的活变成了两个人的活,其中一人专门做装配,另一人专门做质检。这时要求IT系统将功能拆分出来,将一个逻辑变成了两个逻辑。
通常为了减少开发的时间,我们可以在原先的完整逻辑中增加若干个IF THEN ELSE的判断,然后让不同的角色执行不同的逻辑块。也就是说,先加载逻辑,再判断执行。
另一种设计思路是,在第一次开发的初期,按照Simple原则进行分析,将装配的逻辑和质检的逻辑分别封闭成逻辑块,在实施的时候根据配置的情况进行组合。对应的,变更前一个用户执行两个角色的逻辑,变更后两个用户各执行对应角色的逻辑。后台的代码只负责各自独立的逻辑,前台的展现则根据配置的情况对逻辑进行组合。

Solid
Solid就是逻辑要牢固完整。
业务逻辑的完整可以减少系统的异常,从而提升系统的可用性。
执行Solid原则的一个有效方法是黑箱测试,让用户撰写测试场景,让用户进行接收测试。
开发人员往往想到正常的业务流,而用户则熟悉更多异常的业务流,而对异常业务流的测试可以提升逻辑的完整性。

Strong
Strong就是系统要可靠,能够支持多并发性、多用户、大数据量,通过各种方式减少当机时间。
硬件方面,可以通过Cluster、Load Balance等提升系统的可用性。
软件方面,可以通过缓存、读写分离、用户分组、冗余、归档、数据库分区等技术减少计算时间。
保持Strong的一个简单原则是找到并解决瓶颈所在。比如某个系统的瓶颈是跑某个特定的报表,如果几个人在同一个时间段跑此报表,则造成数据库查询长时间等待。解决的办法是从硬件的角度提升数据库的查询效率,或者优先查询语句及表结构,还有一种办法是在用户允许的情况下,对查询请求进行调度,比如提前在空闲的时间段事先在后台执行查询。

Safe
Safe就是安全原则,通过各种办法避免系统服务的中断。
在IT系统中,黑天鹅事件(无法预测的异常事件)是难以避免的,解决的办法是不断累积异常处理措施,每当有异常的时候,通过报错、日志、通知等方式将异常处理,从而避免系统服务的中断。
系统在设计的时候,应该规划一个可配置的异常处理模块,这样可避免在重写核心代码的情况下实现异常的及时处理。

Smart
Smart就是聪明原则。
现在网络上开源的代码、模块、方法论很多,许多互联网的应用也可以借用到企业系统。
比如Map-Reduce是GOOGLE倡导的方法论,实际上许多包括大量IF THEN ELSE的代码都可以利用Map-Reduce进行逻辑的简化。

2012年7月21日

Walking in the Air中文歌词.lrc



儿子喜欢听Walking in the Air,但还不会唱这么长的英文歌,于是做了翻译,加工成中文版。
根据Connie Talbot版本制作伴奏带:


[00:02.22]空中漫步
[00:05.45]中文翻译:tallrain
[00:08.12]
[00:10.34]我们漫步在空中
[00:15.31]飘在月下的天空
[00:22.80]看见了人们
[00:25.32]睡在香甜的梦中
[00:29.94]
[00:32.71]紧紧地拥抱
[00:37.82]在蓝色的夜空驰骋
[00:45.18]一起向上飞
[00:47.66]飞向遥远的星辰
[00:54.71]
[01:10.25]穿过这世界
[01:15.29]村庄消失在梦中
[01:22.81]河流和山丘
[01:25.23]森林溪水一起走
[01:29.99]
[01:33.06]孩子们张着嘴
[01:37.91]惊讶地看着
[01:42.82]没有人能相信
[01:47.48]他的眼睛
[01:51.48]
[01:51.63]遨游在空中
[01:56.44]游过冰冻的天空
[02:03.99]巨大的冰山
[02:06.87]飘过我们的身边
[02:11.43]
[02:29.01]突然间跳进了
[02:34.20]深深的大海 
[02:39.02]沉睡的鲸鱼呀
[02:44.13]跳向了天空 
[02:48.75]
[02:50.28]漫步在空中
[02:55.26]在这夜空中跳舞
[03:02.82]看见了人们
[03:05.26]送上他们的祝福
[03:11.07]
[03:12.74]漫步在空中
[03:17.53]漫步在空中

2012年7月20日

What IT System can learn from US Transportation System?



I've travelled to US for 2 weeks at May this year, and was deeply impressed by the high effiency of US Transportation System.
It's said that US is A Country On Wheels, and somehow the Transportation System's effiency affects its Labor Productivity, and the Road Network also improves the balance between city and country.
Here from performance point view, I want to list out some learnings from US Transportation System, which might help us to improve IT System.

1. Read/Write Separation
US roads mainly includes Interstate Road, State Road, and Country Road.
For Interstate Road, it's the main road for long driving Trucks, and a wide Buffer Zone is setup between the 2 directions. For State Road, it might not setup Buffer Zone, but a Mark Line is painted for separation. And as for Country Road, it doesn't need Buffer Zone or Mark Line because of its low traffic.
To understand it in IT language, this design might be regarded as Read/Write Separation.
Considering business request, both Read & Write operations are part of normal procedure, they are not special logicically. But if Read & Write happens into the same Database Object, then we must consider impact of concurrency: Write operation might lock the Table, thus makes Read Operation waiting.
According to Object-Oriented Methodology, if both Read & Write operations are for same Object, then after mapping, both opertions should be defined in the same Table, and this mapping is logically simple.
For example, if we need to read Attribute 1 and to write Attribute 2 of Object A, then after mapping, it equals to Read Column 1 of Table A, and to Write Column 2 of Table A. Since these 2 Attributes are defined in the same Table A, then Writing Column 2 will lock the records of Table A, and Reading Column 1 will be held until the lock released(after Commint/Rollback). So this design might impact performance.
Let's take an example of Manufacturing System.
For Object of Work Order, it has some Meta Information such as Scheduled Date, Product Number, Quantity, and it also has Non-Meta information such as Current Manufacturing Station, Current Stock Location.
From begining of Manufacturing, the Meta information will not be changed, it will only be accessed from Read operation, but the frequency might be high, because every station requests to Read it.
While its Current Manufacturing Station and Current Stock Location will be changed a lot of times, so they will be updated every time, and each time it updates, this kind of Write Operation will lock records of Work Order Table, so the Reading of Meta data might be delayed.
So considering performance, we should define Work Order's Meta information into one Table, and define Current Manufacturing Station, Current Stock Location and other frequently changing Attributs into another Table or other Tables, as a result, the Read & Write operation has been separated, so the Write operation will not impact Read operation.

2. Redundancy
There're 3 examples, which might be understood from concept of Redundancy of IT System.
1) Buffer Zone of City Road
Buffer Zone is setup between 2 directions in City Road, and it's getting narrow right before Street Cross, and an extra Lane appears for Left Turn cars waiting.
The advantage of this design is that the Left Turn cars wouldn't affect direct traffic, after all direct traffic impact total traffic mostly, so its priority should be highest.
2) Waiting Zone of small road
Cars driving in the main road will not slow down before Street Cross with Green Light signal, it will keep normal speed, for the main road has the highest driving priority.
As for cars drving in small road, they might be waiting for quite a long time before getting into main road. So the Waiting Zone should be designed with capacity of having quite a lot of cars waiting.
3) STOP Board
While cars are driving at community, they should be stopped at STOP Board literally - even no one in sight, and drivers must make sure it't clear before continues driving.
This act seems like an obvious redundancy, for the rate of cars meeting is not high for most of time, but the law orders drivers to stop, why?
Because even the incident rate is low, but as a typical Black Swan incident, it's very hard to forecast, and it will be the Bottle Neck while it happens.
So following this rule, although people spend more time at road, but the incident rate is dropped down, so it's acceptable.

As for IT System, the Redundancy design is an effective method to improve performance.
Take examples of Database Query performance, usually there're 3 cases might affect performance.
1) Group By Query
According to design method of Database, during Group By Query, it's quickest while the type of Group By Column is Number Type. And the Query time might be hundreds or thousands of times longer - if the type of Group By Column is Char.
So if business requires Group By Query, at first we should add a redundant Column, which Type is Number, then we map the Number with original Char value. So we Query data Group By Number Column, and then we Join this Dataset with mapping Table, to get result finally.
As from Business point view, this extra Number Column is redundant, but it's a Must to improve performance.
2) Full-table scan
Full-table scan is a very common scenario, it consumes a lot of Query time, and the solution is very simple: adding Index.
From business point view, Index is also redundant, but the affection is great.
3) Recursive Query
Recursive Query is Database's weak point, it consumes a lot of time even Database has Built-in Functions for it.
A common example is BOM structure. Usually BOM uses multiple levels of Parent-Child relationship to build structure, so it requires a lot of Recursive Query to get the whold structure, and it's getting much longer while quantity or level increses.
For this kind of Query, a common solution is prepare the data before business required, by querying BOM, and saving it into a Flat Table or a Materialized View, and the business logic could Query from this Flat Table or Materialized View later.
That means, to use redundant time before buniness required, to use redundat data outside business logic, prepare data in advance, so that we can reduce Query time while business happened.

美国公路系统对IT系统的借鉴



本人于今年5月到美国出了两周的公差,在此期间美国公路系统的发达高效给我留下了深刻的印象。
我们常听说美国是车轮上的国家,从某种意义上来说,公路系统的效率直接影响了国民的劳动生产率,而公路网的健全也促进了城乡之间的均衡。
这里我试图从性能的角度出发,记录几点美国公路系统对IT系统的借鉴。

一、读写分离
美国公路主要分州际公路、州内公路、乡村公路3个级别,大致对应中国的高速公路、国道、省道。
其中州际公路是卡车物流的要道,公路的两个方向之间有很宽的隔离带。州内公路虽然不一定设置隔离带,但是至少通过划线的方式区分行进方向。而乡村公路由于车流量小,往往只有一个车道,因此就没必要区分和标注了。
用IT的语言解读,这个设计相当于读写分离。
从需求的角度出发,读和写的操作都是正常流程的一部分,从逻辑上来理解并没有什么特殊性。但是如果读和写针对同一个数据库对象,那么我们就必须考虑并发性的影响:写操作造成的锁表会导致读操作的等待。
按照面向对象的方法论,如果读和写针对的是同一个对象,那么对象经过映射之后,所有操作针对的属性都应该放在同一个表中,那么这种映射关系的逻辑是最简洁的。
比如对于对象A,要读属性1,要写属性2,那么经过映射,相当于读表A的字段1,写表A的字段2。由于这两个属性放在同一个表中,那么对字段2的写操作会造成表A中这一行数据的锁保护,一直要等到锁保护解除(COMMIT/ROLLBACK)才能进行此行数据的读操作。因此这种设计可能会对性能造成影响。
举一个生产系统的例子。
比如工单这个对象,有工单的元信息如计划生产日期、产品号、数量等,此外还有工单当前所在制造工位和库位等信息。
一旦进入制造环节,那么工单的元信息就不会有变动,对它的操作只有读操作,但是很频繁,因为每个工位都会读取。
而工单的当前工位和库位会不断地变动,因此会不断地写,而每次的写操作都会造成数据行的锁保护,因此影响元信息数据读取。
因此从性能的角度出发,我们应该将工单的元信息放在一个表里,而将当前工位和库位等不断更新的属性放在另一个或若干个表里,从而实现了读写分离,这样写的操作不会影响读的操作。

二、冗余
美国公路系统中有3个例子,可以参照IT系统中冗余的概念进行理解。
1、城市公路中央隔离带
城市公路的2个走向之间有很宽的隔离带,当道路有转向时,隔离带区域缩小,留出一个车位的面积供左转向车等待时停泊。
这样设计的好处是转向车不会影响直行车,毕竟直行车对总体流量的影响是最大的,因为直行车道的畅通是优先级最高的。
2、小路等待区域
行驶在大路上的车辆,如果是绿灯,即使要经过路口,车辆的速度保持在正常行驶速度,司机不会减速行驶,因为大家都认为主路的行驶优先级高。
那么行驶在小路上的车辆,在驶入大路之前,可能会经过较长时间的等待,以避免和主道车辆争抢。因此小路在接入大路之前,所设计的区域应允许较多车辆的临时停留。
3、STOP牌
车辆行驶在住宅或办公区时,在与人车可能交汇的路口设置STOP停车警示牌,司机必须在此牌前将汽车减速停车(即使路口无人),确认安全后再通过。
这个举措表面上看起来是个明显的冗余,因为很多路口人车交汇的概率并不高,但是法律规定司机必须在此牌前停车,其意义何在呢?
这是因为事故出现的概率尽管很低,但是作为黑天鹅事件,是很难预测的,并且一旦出现事故就会造成堵塞交通的瓶颈。
因此尽管大家都增加了道路停留时间,但是恶性事故出现的概率降低了,因此这个冗余是合理的。

对于IT系统来说,冗余设计通常也是提升性能的有效方法。
以数据库查询性能来说,通常影响数据库查询的有以下3种情况:
1、分组查询
按照数据库的设计原理,当进行分组查询的时候,查询的字段类型为整型时效率是最高的,如果用字符型字段进行分组,则查询消耗时间会达成百上千倍之多。
因此当业务需要进行分组查询的时候,首先我们要在数据库里增加冗余字段,将要分组的字符型数据映射成整型数据,将数据按照整型字段汇总,然后将数据集与映射表关联,最终得到我们需要的业务数据。
从业务的角度出发,这个增加的整型字段就是冗余数据,但是它对提升性能是不可或缺的。
2、全表扫描
全表扫描是一个经常碰到的场景,会消耗大量的查询时间,解决方法很简单,是建立索引。
对于业务来说,索引也是冗余数据,但是效果立竿见影。
3、递归查询
对于递归的处理是数据库的弱项,即使数据库有一些处理递归的内置函数,但是往往还是会产生大量的查询时间。
一个常见的例子是BOM的结构。通常BOM采用多级父-子件关系来建立完整的结构,因此在还原时会有大量的递归查询,随着查询数量和层级的增加,查询时间会变得相当长。
对于此类查询,一个常见的解决办法是提前做数据处理,在业务发生之前,将BOM的结构查询出来,并且以展开的平表格式存储到表或物化视图中,这样业务发生时直接查询平表或物化视图即可。
也将是说,利用业务发生前的冗余时间,利用与业务逻辑无关的冗余数据,提前处理从而减少业务发生时的查询时间。