Windows mind set vs. Linux mind set

I wanted to talk about this for a long time, however, the key points were not clear until recently I ran into the pipeline concept in PowerShell.

When you do pipeline in PowerShell, you’re passing not a text stream from the left command to the right command, but rather, you’re passing a .net object.

When I read this from TechNet, I smiled to myself, yes, this is typical Microsoft!

Windows PowerShell provides a new architecture that is based on objects, rather than text. 
The cmdlet that receives an object can act directly on its properties and methods without 
any conversion or manipulation. Users can refer to properties and methods of the object by
 name, rather than calculating the position of the data in the output.

And I said to myself, now I know what I wanted to say.

One key difference between Windows and Linux is, Windows always tries to be smarter, where GNU Linux tries to stay plain and humble. Pipeline in scripting is just one recent example.

Linux has been using text configuration files. Windows came along and said, we need something better. That’s how Windows Registry came about.

Linux has been using pipeline for IPC. Windows came along and said, we need something better. That’s how COM came about.

Linux has been using lock files to prevent processes to start another instance. Windows came along and said, we need something better. So they use Kernel Object instead.

Linux has been using permissions as a basic security measure. Windows came along and said, we need something better. So they do everything using ACLs.

Linux has been using symbolic links. Windows came along and said, we need something better and introduced short cuts.

To be fair, not all of them are bad ideas.

Despite its complexity and awkward configuration, COM gained such popularity that it became the basic foundation of modern Windows. Open registry in any Windows that has been used for a while and chances are the biggest tree is HKLM\Classes\CLSIDS. (One of the key reasons why you Windows becomes slower as you install more and more software).

Kernel Object is much more reliable than lock files. ACLs indeed provide much flexibility in terms of access control. Linux is also doing it now.

However, we all know that Windows have record of being smart in cheap ways and then fail pathetically. (SilverLight is the one that came into my mind as I write this) To me, this idea of passing objects through pipeline looks like just another one that will fail.

Having said that, I have to admit that, this difference between Windows and Linux is also not surprising.  Linux is developed by community led by technical experts. Introducing new features always involves extensive discussions between these experts.That’s why Linux has a bad reputation of not listening to its users.

Where as for Windows, most likely, new features are proposed by requirement collection team and developer team, then the list of new features have to go through rounds of prioritization processes. If there are disputes, then there will be escalations and some manager will decide. Once decided, then features still in the list will be implemented. Period.

Now, it is actually surprising that Microsoft actually made some key decisions right, right? 🙂

Monty Hall Problem simulation in Excel

Monty Hall Problem is definitively the most confusing puzzle among educated people. After explaining this to different colleagues and friends (With a success rate below 50%), I found it’s easier simply presenting the fact. So here’s a simulation of it in excel.

monty_hall_excel

Let’s me explain a little bit about this excel:

Each row in the table is a test case, or an experiment.

In each such a experiment, a random number is generated to determine where do we put the car. A goat will be placed behind each of the rest doors. So in the table, we have “C” denotes a Car and “G” denotes a goat.

If the number is between 0-1/3, then the car will be placed behind Door1. If the number is between 1/3-2/3, then the car will be placed behind Door2. If the number is between 2/3-1, then the car will be placed behind Door3.

Then in the 6th column of the table, another random number is generated to determine the 1st choice.

Again, if the number is between 0-1/3, that means the guest chose Door1 in the first attempt. If the number is between 1/3-2/3, then the guest chose Door2 in his/her first attempt. If the number is between 2/3-1, then he/she chose Door3 in his/her first attempt.

Note that both of the 2 random numbers have a unify distribution between 0 and 1. And the 2 numbers are completely independent to each other.

Also in the table, the guest’s first choice is high-lighted in green.

The next column, the 7th column, shows what the guest will get if he sticks to his/her first attempt. And the 8th column shows whether he/she wins a car or not. (1 wins, 0 loss).

The 9th column shows what the guest will get if he/she switches to the other door when he/she is given another chance. And the next column shows whether he/she will win or not if he switches.

In the end of the table, after 400+ experiments, the outcome of the 2 strategy was summed up. Out of 432 experiments, you’ll get a car 142 times, if you stick to your original choice, you’ll get a car 290 times, if you switch.

The good thing about this excel is, you can simply press F9 and ask Excel to recalculated and see with your own eyes of the outcome.

What slows down your Windows?

Windows has long been complained of performing slower and slower as being used. This essay tries to explain how and why.

Before we go into details, let’s make it clear that we’re talking about the architecture design of Windows that makes it not performing in certain situation. So this is consistently measurable performance difference. We’re not talking about bad performance because of wrong configuration. Nor are we going to talk about performance of a specific program.  A specific instance of slow down, for example, your notepad will performance slower when you have a lot of other programs running, is not what we’re going to talk about.

First of all, there’s no reason Windows should perform worse (or better) if you just spend more time on it. If the installation keeps the same, the size of your computer keeps the same, Windows should perform the same.

However, if one of your running programs or a device driver has memory leak, then it will eat up more and more memory as time pass by. That will slow down your Windows. The unique thing about this type of performance issue is, after a fresh restart, Windows should perform well. In the early days, memory leak was a common issue on Windows. That attributed much to the common belief that you should restart your Windows once in a while to keep better performance. Now, most commonly used program is mature enough to be free of memory leak, Windows should perform just the same as time goes by.

However, as time goes by, you’ll probably keep installing new software on your Windows. This could indeed slow down your computer. The reason is, by installing any non-trivial software, you’re not only copying files to the disk, but also registering COM components to Windows. These registry key/values will be keep in memory. So the more software you install, the less memory your program will be able to get.

As an example, after you install a program that is able to open a new file format, chances are:

  • You’ll not be able to see a thumb nail that shows the content of the file in Explorer;
  • You’ll see this program listed in the pop-up menu of this file type;

They were made possible using COM technology that depends heavily on Windows Registry.

The problem is, this registry keys/values won’t get cleaned up when you uninstall the software. So Windows registry keeps growing and growing, your programs have lesser and lesser memory to use.

The other factor that would for sure slow down your computer is disk fragmentation. Disk fragmentation affect performance not only when your program does disk IO. If your page file is fragmented, paging operation will be slow. That will cause noticeable sluggish. Also remember that all executable files and dll files become memory map files, so if they are fragmented, your program will be slow not only during start up, but also in running phase.

Bloated registry and disk fragmentation are the two reason that your Windows slows down in the long run. In some of my Windows computers, I actually create separate partitions for page file, for outlook pst file and Windows tmp file. These techniques worked quite well.

泊松分布在容量管理中的应用

其实是泊松分布的经典应用:

已知某呼叫中心每小时会进ci个电话,每个电话平均时长为tp,则在任意给定时刻,并发电话的为x的概率服从泊松分布。此处假设不同的电话是完全独立事件。

并发电话为x的概率,等同于在tp时长内,进入x路电话的概率。在tp时长内,平均会进的电话数为tp*ci。因此,并发电话小于或等于x的概率为(excel公式):

POISSON(x,tp*ci,TRUE)

其中最后一个参数TRUE,表明这里计算的是并发电话小于或者等于x的概率;如果用FALSE,则只计算等于x的概率。

此公式可用于呼叫中心容量规划,比如:如果已知呼叫量和平均通话时长,则要确保容量在99%的情况下够用,则只需求x,使得POISSON(x,tp*ci,TRUE)>0.99。

在某呼叫中心,把历史数据应用了一下,符合度很高:

call_vol_verification

其中横轴是时间,黄色为实际并发量,蓝色为按照0.999计算出的并发量上限。

如果把横轴改成按照实际并发量排序,则得到:

call_vol_verification_2

可以看到实际并发量几乎总是在预计容量之下。几个实际并发量高于预计容量的情况,后来证实都是系统出了故障,导致客户竞相反复拨打,意味着不仅原来的参数不再适用,独立同分布的假设也不再适用。

 

Illusions well illustrated

The documentary Test you Brain from National Geographic is awesome!

Illusions are well known to human, but not all of them have been well illustrated in action. The problem is, some of the illusions are very  best described in experiment to shows all the intricacies. For that we need carefully designed experiments and video making. This is the first time I saw something like this is made.

As an example, here’s how this documentary illustrated an attention saturation situation devised in David Copperfield’s studio:

First you see a magician told you that he wanted to do something not at all legal with money. After showing you the cash, then messing around it, the silently putting it back to his pocket, you’re asked, “did you notice anything?”.

vlcsnap-2012-01-30-08h41m37s953

Of course you didn’t. Then the video rewind and show you what had happened before and after.

Then another video shot by a camera from another angel showed you these changes were made actually well you were watching. You didn’t notice only because you didn’t pay attention to them.

vlcsnap-2012-01-30-08h47m43s393

vlcsnap-2012-01-30-08h42m18s374

So after you see this, you cannot help to say to yourself, aha, that’s how they’ve deceived me. But then you have to rethink about perception and illusion.

While it’s not available in Youtube, we Chinese can already watch it here:

Documentaries that worth noting

Have been watch documentaries for years now, especially BBC ones. Looking back, not every one of them left the same impression or impact. Here are the ones I’d like to share with others (With links to docuwiki.net, where you can find more information about these documentaries):

Another great documentary from Simon Schama

After “Power of Art”, I’m a fan of Simon Schama now. Two weeks ago I downloaded “A history of Britain”. I haven’t finished it yet, but it’s already ranked very high in my list. 🙂

Something in common in these 2 documentaries: In both of them, there are great music. The music in the opening scene of “Power of Art” is lovely (Moonlight Sonata?), the music in the opening scene of “A history of Britain” is also very intriguing, anyone knows what it is?

中国什么时候算强大了?

奥运会赛程过半,中国人的自豪感自信心水涨船高,论坛里不时有人发一些自信心爆棚,让人目瞪口呆的帖子。

我觉得,国家肯定是发展了。但是,对于我们这样一个历史悠久、人民勤勉,人口众多、重视教育的大国来讲,还是要有更高的目标。这个更高的目标很难具体化,但是,最近我经常在看南方公园,觉得深受启发。我觉得我可以提一条判断标准:

如果有一天,在我们国家,会有这样一部给成年人看的动画片,它讽刺,有趣,它得罪公安、工商、税务、老师、领导、明星、平民、儿童、少数民族、残疾人等等等等,而只会被一笑而过;可能有人抗议,诉讼,但没有人诉诸领导,要求禁播,中国就真的强大了。

立贴为证!

Power of Art by Simon Schama

I downloaded this series 6 moths ago. I tried watch it but seemed that the content seemed too difficult for me – This is the first time I take on a documentary that is art subject. My vocabulary is simply not enough.

In the past days, I forced myself to take notes on sentences that I didn’t understand, and then lookup, and then review the video. Till yesterday night, I finished the first 4 parts. What I can say is, it worth every minute of the effort!

A lot of praise out there already for this great documentary. There’s not much I can add to that. I only hope the future generation will have this kind of art eye-opening in their classroom, or I’ll have to show them this great documentary.