Silence & Solitude makes...

Pu's mind space

Thoughs on Chum Salmons

Small Salmon

It’s the first time I write an article expressing subtle feelings in English. Though I have written some English articles before, it’s basically used to describe things more definitely or more professionally. And I know I can only vaguely express feelings with this language, so just like Leonardo’s reverse scripts, using my Chinglish to write an article is kind of trying to encrypt it. So I won’t blame if you were scared away by the 6 (maybe more) grammar errors appearing in this first paragraph.

Starting with an introduction to a specific kind of fish. The “Chum Salmon” in title, “Oncorhynchus keta” as the biological terminology, is a kind of migratory fish, which born at rocky small streams in cold zones in Northen US or North Asia, as the title picture shows. Typically their birth day is in Spring, latter when their first summer comes, they will swim along streams to rivers and finally to the Pacific and live their for arround 3 years, which is almost their whole life. After that they will go up along the rivers to streams, some place where they are born, to spawn there.

Spawning Salmon

This is amazing. I wonder if biologiests know how this happends, how such instinct is composed of. Do they achieve this by following routes in their memories, with the help of some build-in high resolution GPS system, or are they driven by some kind of hormone whoes secretion is highly and sentitively connected with temporature, fluid speed, and clearity of wator. What will happen to a group which is born in a specific stream and reclaim land from the stream when that group/generation of Chum Salmons are in ocean? Will they still heading to that the exact spot or will they went to similar places? Will they still spawn if they can’t find a place which is similar to the environment they stored in their childhood memory?

This is not another article but, my wife is 32 years old, me too. The world has experienced huge changes in this 32 years, even more in China. Old generations always try to help young generation with their experience on living, even though they use web and cars heavily, they think their experiences about making a living, about building a harmony family, about giving birth to child, about pregnancy-care should be the same, or more or less reusable. As the most responsible generation of this society, 30+s should be cruel neither to elders nor the youth. But if elders regard 30+s to have children as their source of happiness, there’s something cruel going to happen.

I feel driven by some instinction, though haven decided not to give birth to chidren in recent 2 years last year, I can’t stop keeping thinking of it. How to name such instinct? Like protecting next generation even before they are really exist? How can I consider to protect an not existing thing(child)? Just like I can’t picture wave-particle duality of light. I feel like being a Salmon going up the rivers, difference is I don’t exactly know where the stream is. Maybe just following distinct will make things easier, but it would be the last option.

Bears living along North Pacific beach need to store enough energy before hibernation, Chum Salmons choose to go to risky places in Autumn to spawn, some of them feed bears. Fishman in Amur River area setup net in Autumn, Chum Salmons also feed human. When they are going back from ocean, they are doomed not being able to witness next summer. Even not feeding human and bears, Salmons’ happiest ending also fall prey to the marvellous nature, they will die likely 2 weeks later after they spawn, they use their body to churn the rocks to bury their newly laid eggs in the their last days. No one has explained what they typically died from.

Dead Salmon




防守人很怕对方反弹,但是如果反应够快,可以在对方进攻的第一时间 – 对方前锋出脚之后刚刚回收的期间 – 通过类似前锋反弹的击球方式防守,这样可以轻易突破对方锋线把球输送到前场。 – 这就是我之前总结的快速出球打法
对方进攻失败后把球控制住,选择合适的时机合适的角度,用大力射门的方式把球击出。 – 这是成功率打法。

这里说的结论其实是马后炮,因为我见到了成功率打法的拿了我司桌上足球比赛的冠军,而我–快速出球打法的信奉者–表现并不是很好。其实思考原因也很简单, 因为人的力量和反应时间是几乎固定的两个指标,训练到极致也无法突破某个比例,而桌上足球尺寸的大小已经决定了只可能存在完美的进攻,没有完美的防守。所以除非你的前锋比对方前锋把握能力强10倍,否则不要使用快速出球的打法,虽然突破了对方前锋的第一道防线,很大程度上你的前锋也不会能利用好这个机会,所以相比于把球控下来,这样做(快速出球)无异于把控球状态变为开球状态。



[ ]
| |
| | |
[ ]


[ ]
| |
| | |
[ ]


A Programmer's Daily Time Distribution And Beyond

As a programmer, I’ve witnessed peers moaning about working-overtime or being pushed by schedule, such as these. Utopia is coding at home with beer aside, pets/kids occasionally interrupt you with their cuteness, but where are your boss and peers in this territory – if you want be a cathedral guy instead of making a living in the bazaar as a vendor, you can’t go through without them. Certainly, working like that won’t maximize your employer’s profits and can’t cooperate with teammates effectively. So that situation is unreachable, we still have to go to office, but at least there’s a way to make yourself really comfortable in office and your employer get the maximum output from you. But how? I happen to have some shower thoughts the other day regarding this.


We need to make some consensus before making a bargain.

First, programmer’s effective input is not measurable, not by working time, not by code-lines. Unlike manufacturing industry, in which qualified parts built by a worker in a unit time is measurable, building software is always a non-linear work, fixing one critical bug may need as much time as writing ten ‘qualified’ features which passed all unit tests and integrational tests, but would fail the stress test, and of course can require as less time as typing several characters if it’s obvious, to someone – I’m not emphasizing this because this example is focus on the diversity of bugs themselves, so programmers’ diversity is not the point.

Second the output is not measurable either, a software is nothing if there’s no user, or user find it hard to use. Even if we don’t consider the money a software can make, or the productivity a software can improve, as metric, just use the software metrics, like story points in the agile context, it is not measurable too. We all experienced two similar stories bidding the same points, but actually the first implemented one values much than the first one, as you know copy&paste constitute most of the most programmer’s activity.

Bearing these in mind, then, from the manager/employer’s perspective, how does he knows his management job is well done, or how is he get the best of his employers? I don’t think there’s any way, person varies with person, if you can not measure their productivity, just believe they are professional(how to ensure this is another topic and is HR’s duty which is answered when he get the offer), and ensure them are productive. If I were a boss, what I would like to is to just make programmers being in a vigorous state, both mental & physical.

Mentally vigorous

It dictates communication in a proper extent. Communicating with others would help you to recognize your issue-to-handle more clearly, but too much of this would blur your focus, make you not-so-targeted – not to mention occupying your time.

Reading an internet post, raising an issue or service request, talking to peers or join a meeting are all kinds of communicating.

It also demand you to distribute your mental activity reasonably. By distribute reasonably, I mean you might need some music or non work chat when you have worked for long time(say longer than 4 four), as long as there’s meal break and coffee break, this would be a problem, the only constraint it brings is not to work over-time heavily and constantly. But it has another meaning which is often ignored, that is even you have 6 hour code time, if it’s broken down into many piecies, I mean divided by meetings, peer-communications, coffee break or internet surfing, it won’t make ‘mental vigorous’ too, with experience, you at least need a block of 1.5 - 2 hours’ time to solve real-challenging problems.

Physical health

I mean cervical/lumbar spondylosis. The 10 tips to prevent lumbar spondylosis or such things always mention don’t keep sitting in 1 hour, walk every 1 hour or so. I’m suggesting this too, actually this didn’t conflict with the 2 hour block you need to solve real-challenge, you can keep thinking of the same issue with this break. And for other breaks outside the 2 hour, talk with peers or go for coffee is surely OK.

Programmer’s daily time distribution

In common sense, to make you productive, yourself or your manager would give you a list of things-to-do, daily or weekly. Books tell you do so too, but as a mental job, things-to-do didn’t always get done even if you assign enough time to it. As I mentioned, inevitable breaks (for mental and physical healthy) and communications didn’t list in your things-to-do, but they actually effect if you can get things done with fixed time. For not-so-competent tasks, you might need more communication. For boring-tasks, you might breaking more, consciously or not. And also for improvement, you need spend time learning, as an employee, you need spend time to meet executive’s requirement, daily task can easily fail if you count in all these. If you log your time by actual items like communication, break, coding, learning&documenting, instead of business items, problems get more clear.

But unfortunately managers often focus the latter, i.e. today you spend 4 hour on issue1, and 4 hour on issue2, why they are not improving? Not until you and your employers start to care about your first log, i.e. daily time distribution(DTD), would the programmer’s life more easier.

What profile does most of the programmer’s DTD look like actually concretize the so called corporational culture. I feel satisfied with my productivity recently, and I think my DTD is reasonable, I’ll give it here:

item time(h)
communication 3
break 1.5
coding 2
learning&documenting 2

If goes into detail, communication includes peer-communication(work and non-work, email or non-email) or searching for internet for solving a problem(like SF), and also for meetings(mostly not-related with your task-to-do today), so actually it not always help you finish your task; break includes coffee break, toilet, table-football, and surfing internet; coding include write code, and miscellaneous tasks like download ide plugin, checking api(in internet or not) but not include things searching SF; learning and documenting include reading-book/posts not directly related with your task in hand, write summary, or log time in JIRA, or write post in Confluence.

It can vary among programmer and production phase, say if not so competent with your current task, you need to learn more, and non-lead programmer can have more time learning. But in general, I say it could profile the corporational culture. Some “performance-targeted” company use story points or features-finished to measure a programmer, this would elongate the code time, and squeezing others, especially learning and break. Some “performance-targeted” company judge programmer with there sounding, thus making unnecessary communication time long. Even not to extent of squeezing physiologic break time, at least it could break the mental vigor. I’m not senior programmer, just 5 years experience with several companies, I never meet any company whose HR/manager would like to survey/query programmer’s DTD, so that they can introspect how they can help programmer to improve productivity. I’m not try to be sensational and union the programmer’s party to do something, but employer does have to discard the one-sided view of software engineering, either just accept it’s a chaos and hence only measure programmer with final result or regard it an analog of manufacturing and hence don’t respect programmer’s job as mental work. It would bring WIN-WIN if employer and programmer start to know DTD and its means.









Compare Latin Charactors to Basic ASCII Charactor

In some circumstances we meet words that contains Latin charactors, like the word naïve , especially in names like simão. For some reason, we want to translate them to naive, and simao, or at least we can know that they are equal to naive or simao respectively.

I’ve met such a problem recently, and I try to find a solution to this, but honestly, it’s hard to describe such a question. When I browse all the posible related pages which google shows, I find a function in ES6 called normalize which finally helped me out. If you look at the description of the argument of this function, and finally trace to the concept of the so called Canonical Decomposition, you probably would WOW out like me do. Yes, it’s exactly what we want, we want È É Ê Ë being equal to E, want ìíîï all equal to i. Now with this function, we can easily solve the problem with the help of this function, and I’m really glad I found the solution even before I know how to describe the problem.

So here is the utility function

function convertLatin(str) {
return str.normalize("NFD").match(/\w/g).join("");

And you’ll find that convertLatin(“naïve”) === “naive”, and convertLatin(“simão”) === “simao”. Enjoy this small utility!

##Update(26 Mar 2017)

After some close investigation, I found the solution above is neither robust nor necessary, as ES6 have provided official support for this user case, please check the new API of


—无韵集句 和小智





新手开始部署他们的第一个Docker Container的时候经常会问的一个问题就是:”我该怎么把应用的配置打包进Docker容器里面?”.问题中提到的配置包括worker的数量,JVM的内存大小,或者数据库的连接串.现实中实现这些有一套标准方法,而它们各有利弊.


1. 将配置烧进容器里




  • 因为配置已经烧到镜像里,未来可能的配置改动都需要修改Dockerfile并重新build来实现

2a. 利用环境变量动态地配置应用

这是一个在Docker Hub上的镜像比较常用的方法,譬如PostgreSQL的’POSTGRES_USER’和’POSTGRES_PASSWORD’这两个环境变量.

简单地说,当你启动容器docker run的时候,需要指定环境变量,而容器的进入点(Entry point)也就是启动脚本会寻找这些变量,并把他们用在相应的配置文件里.



  • 从配置角度看,这样的容器更灵活


  • 打破了生产/开发环境的一致性要求,也就是说其他人可以通过不同的配置使得容器的行为在生产/开发环境下不一致
  • 一些复杂的配置无法映射为简单的键值对

2b. 利用环境变量动态地配置应用




  • 配置更动态
  • 键值存储使得复杂配置成为可能


  • 同样违反了生产/开发环境一致性(译注:和所谓的immutable container是同一个概念)
  • KV store必须高可用,因为所有的容器配置都依赖于这个存储器

3. 将配置文件目录挂载到Docker Volumes

Docker Volume介绍略


docker run -v /home/dan/my_statsd_config.conf:/etc/statsd.conf hopsoft/graphite-statsd


  • 无需修改容器就可以随意配置


  • 违反生产/开发环境一致性要求
  • 如果要用在生产环境中,必须要保证配置文件在基础操作系统中可用.


如上所述,想要配置一个容器包里的应用,方法其实很多,各有利弊.哪个最好?其实取决于你需要多大的动态配置的自由度以及你是否愿意承担额外的譬如维护一个KV store这样的负担.




一次搭建高性能Nodejs httpServer的尝试(2)

上次搞的node http server,一个简单的服务器,接收HTTP POST,解析数据入mongo库(nodejs driver用的native driver而非mongoose),主要做了下面的一些优化:

  • 系统层面放开同时打开的文件数(也就是socket数)的限制
  • 复用链接(主要是ab http1.0 keepalive的坑)
  • 增加并发
  • “优化”业务逻辑

其实都是一些”预”优化,在没有需要针对处理的问题出现的情况下先放开一些东西. 后来测试结果满意,一个小项目开始,两周完成了一个小业务之后,需要部署让测试介入.环境一换,问题就来了.

原先在本地的Linux台式机上近16000的TPS到了openstack(4core, 4GB memory)的VM上TPS瞬间掉到了小几千.赶紧登陆上去vmstat查看,发现Procs的r值(等待执行的进程数)接近20,远大于CPU核心数,也就是说CPU成了应用的瓶颈.–原来台式机是8X3.4GHz,到了虚拟机上只有4X2.3GHz,早该想到!

提高虚拟核心数!当然同时也把node.js的slave process提高到8个.同时,把libuv的线程池的限制也放开(设置UV_THREADPOOL_SIZE=8的环境变量),至于这个有没有用,其实我也是不太清楚的,顺便贴一个关于这个问题的争论—好吧,其实是撕逼,吃瓜群众表示看神仙打架也很有意思嘛—也不知道libuv团队最后有没有采纳这个不礼貌的家伙的建议.但是不管libuv的线程池是否应该跟核心数相等,个人觉得不管怎么说,mongodb的native driver开的线程池的大小是5,如果libuv的线程池大小只有4的话肯定不能发挥出其期待的性能吧.再次顺便提一句,mongodb nodejs官方的driver其默认线程池大小也是可以改的–详见参考文档,但是我这里并没有尝试.

好吧,再次测试,TPS又恢复到了16000+. Done!

之后又简单看了一下GC/内存有没有潜在的问题,这也是上一篇文末希望做的.简单来讲做法就是使用node-inspector+Chrome DevTools来比对heap snapshot(和参考文章的工具小有差异)以及使用–trace_gc来查看请求量大量/持久的压力下GC的时间是否能够接受.





2017-08-20 更新


首先澄清初始问题,依据12-factors的要求:Make the tools gap small: keep development and production as similar as possible.
现在看来这里要求的开发和生产环境的一致性其实是在要求CI/CD环境的一致性,或者具体点,是Jenkins Build Node和Production Node的一致性。由于容器技术的引入,其实小环境一致性的要求是自然满足的,而Node系统以及Docker-Engine本身(版本的)一致性,可以很容易地通过复用诸如Chef recipes或者Openstack Heat Template来达到,至于容器编排器的不一致性 – 譬如在Jenkins Slave上用的是docker-compose而在生产环境中使用Kubernetes – 可能造成的问题,我想是Operation需要解决的,毕竟DevOps的存在只是为了让Ops日子好过点,而不是让Ops失去存在的必要。

这是本文最初关注的问题,因为我当时把开发环境理解成了开发者环境,现在看来这个问题已经没有多少意义了,答案是随便。如果是java开发的话,可能你本机的jdk版本跟容器里的jre版本一致比较好,但是其实也无所谓,如果有一些这种环境差异带来的问题,也会以CI的单元测试失败的形式暴露出来。甚至你的开发机器也可以不需要装Docker,因为有Contract Test的保证,你的应用/服务与其他组件集成时可能出现的问题也会在CI过程中以inter-service测试失败的形式暴露出来。当然如果你希望少一点这种类型的返工,还是需要尽量保持开发机器中的单元测试和CI环境下的环境经可能一致 – 在CI里尽可能调用Gradle Task可以很好地帮助我们实现这一点 – 但是这不是必要的,我想说的是12条军规中的关于开发和生产的环境一致性要求是在要求CI和CD的一致性,而非开发者环境和CI环境的一致性,所以作为开发者来说,这个问题可以忽略。