Concurrency Patterns并发模式
Fan-In multiplexes multiple input channels onto one output channel.
|
|
Fan-Out evenly distributes messages from an input channel to multiple output channels.
|
|
Future provides a placeholder for a value that’s not yet known.
|
|
Sharding splits a large data structure into multiple partitions to localize the effects of read/write locks.
|
|
扇入(Fan-In) 将多个输入通道多路复用到一个输出通道上。
|
|
扇出(Fan-Out) 将输入通道的消息均匀分发到多个输出通道。
|
|
Future 为尚未确定的值提供一个占位符。
|
|
分片(Sharding) 将大型数据结构拆分为多个分区,以局部化读写锁的影响。
|
|
Stability Patterns稳定性模式
Circuit Breaker automatically degrades service functions in response to a likely fault, preventing larger or cascading failures by eliminating recurring errors and providing reasonable error responses.
|
|
Debounce limits the frequency of a function call to one among a cluster of invocations.
|
|
Retry accounts for a possible transient fault in a distributed system by transparently retrying a failed operation.
|
|
Throttle limits the frequency of a function call to some maximum number of invocations per unit of time.
|
|
Timeout allows a process to stop waiting for an answer once it’s clear that an answer may not be coming.
|
|
断路器(Circuit Breaker) 在可能发生故障时自动降级服务功能,通过消除重复错误并提供合理的错误响应来防止更大的或级联的故障。
|
|
防抖(Debounce) 将一组调用中的函数调用频率限制为仅执行一次。
|
|
重试(Retry) 通过透明地重试失败的操作来处理分布式系统中可能出现的瞬时故障。
|
|
节流(Throttle) 将函数调用的频率限制在每单位时间内的最大调用次数。
|
|
超时(Timeout) 允许进程在明确答案可能不会到来时停止等待。
|
|
2020 Reading List2020 读书清单
LBRYLBRY
A decentralized video platform – could it be a competitor to YouTube?
一个去中心化的视频平台,似乎是 YouTube 的竞争对手?
The All in Go Stack全面转向 Go 技术栈
"Worse is Better""越差越好"
I stumbled upon an excerpt from an article called “The Rise of Worse is Better.” The author, Richard, reflects on why C and Unix succeeded. The article discusses the four major goals of software design: simplicity, correctness, consistency, and completeness. Two highly representative schools of thought have developed around these four goals: the MIT school and the New Jersey school (where Bell Labs is located). The MIT school believes that software must be absolutely correct and consistent first, then complete, and finally simple. It also “satirizes” the New Jersey school for doing the opposite – they set simplicity as the highest priority, even willing to sacrifice correctness for the sake of simplicity. In other words, software quality (popularity) does not increase with more features; from the perspective of practicality and ease of use, software with fewer features is actually more favored by users and the market.
So now you can see why some people always complain that Go can’t do this and can’t do that, is missing this and missing that. It’s because Rob Pike from Bell Labs is a through-and-through New Jersey school person. So to sum up, Go’s characteristics are:
- Simple
- Very simple
- Nothing but simple
There are several follow-up articles on “Worse is Better”:
- Original: Richard P. Gabriel. The Rise of Worse is Better. 1989. https://www.dreamsongs.com/RiseOfWorseIsBetter.html
- Follow-up 1: Nickieben Bourbaki. Worse is Better is Worse. 1991. https://dreamsongs.com/Files/worse-is-worse.pdf
- Follow-up 2: Richard P. Gabriel. Is Worse Really Better? 1992. https://dreamsongs.com/Files/IsWorseReallyBetter.pdf
- Follow-up 3: Richard P. Gabriel. Worse is Better. 2000. https://www.dreamsongs.com/WorseIsBetter.html
- Follow-up 4: Richard P. Gabriel. Back to the Future: Worse (Still) is Better! Dec 04, 2000. https://www.dreamsongs.com/Files/ProWorseIsBetterPosition.pdf
- Follow-up 5: Richard P. Gabriel. Back to the Future: Is Worse (Still) Better? Aug 2, 2002. https://www.dreamsongs.com/Files/WorseIsBetterPositionPaper.pdf
So which school do you lean towards?
偶然间读到了一篇文章的节选片段《The Rise of Worse is Better》,这篇文章的作者 Richard 围绕为什么 C 和 Unix 能够成功展开了反思。这篇文章中聊到了几个软件设计的四大目标简单、正确、一致和完整。其中围绕四个目标发展出了两大很有代表性的流派: MIT 流派和 New Jersey 流派(贝尔实验室所在地)。MIT 流派认为软件要绝对的正确和一致,然后才是完整,最后才是简单;而一并"讽刺"了 New Jersey 流派反其道而行之的做法,他们将简单的优先级设为最高,为了简单甚至能够放弃正确。换句话说,软件的质量(受欢迎的程度)并不随着功能的增加而提高,从实用性以及易用性来考虑,功能较少的软件反而更受到使用者和市场青睐。
所以你看到为什么总是有些人总是抱怨 Go 这也不行那也不行,这也没有那也没有了。因为来自贝尔实验室的 Rob Pike 就是一个彻彻底底的 New Jersey 流派中人。所以总结起来 Go 的特点就是:
- 简单
- 非常简单
- 除了简单就是简单
然后围绕 Worse is Better 还有好几篇后续文章:
- 原始文章: Richard P. Gabriel. The Rise of Worse is Better. 1989. https://www.dreamsongs.com/RiseOfWorseIsBetter.html
- 后续 1: Nickieben Bourbaki. Worse is Better is Worse. 1991. https://dreamsongs.com/Files/worse-is-worse.pdf
- 后续 2: Richard P. Gabriel. Is Worse Really Better? 1992. https://dreamsongs.com/Files/IsWorseReallyBetter.pdf
- 后续 3: Richard P. Gabriel. Worse is Better. 2000. https://www.dreamsongs.com/WorseIsBetter.html
- 后续 4: Richard P. Gabriel. Back to the Future: Worse (Still) is Better! Dec 04, 2000. https://www.dreamsongs.com/Files/ProWorseIsBetterPosition.pdf
- 后续 5: Richard P. Gabriel. Back to the Future: Is Worse (Still) Better? Aug 2, 2002. https://www.dreamsongs.com/Files/WorseIsBetterPositionPaper.pdf
所以你更倾向于哪个学派?
Proebsting's LawProebsting 定律
Today I read an extra paper. Although it’s not directly related to Go, I think it offers some insightful perspective on the current state of the Go language, so I’d like to share it. The paper is called “On Proebsting’s Law.”
We all know Moore’s Law says the number of transistors on integrated circuits doubles every 18 months, but this paper studies and validates the so-called Proebsting’s Law: the performance improvement brought by compiler optimization techniques doubles every 18 years. Proebsting’s Law was proposed in 1998, and its author Todd Proebsting was probably half-joking, because he suggested that the compiler and programming language research community should reduce their focus on performance optimization and instead pay more attention to improving programmer productivity.
Now, looking back at this suggestion with hindsight, we can see it’s not without merit: although Go’s compiler has gone through several major optimization versions, the techniques it uses aren’t particularly fancy – rather, they are quite traditional and conventional optimization techniques. However, this hasn’t hindered Go’s success, because what it tries to address is exactly programmer productivity:
- By avoiding circular dependencies, it greatly reduces the time programmers spend waiting for compilation
- Its very concise language design and feature set greatly reduces the time programmers spend thinking about how to use the language
- Forward compatibility guarantees almost entirely eliminate the migration and maintenance time caused by version upgrades
今天额外读了一篇论文,虽然跟 Go 没有直接关系,但我觉得对理解目前 Go 语言的现状是有一定启发意义的,所以来分享一下。这篇论文叫做 “On Proebsting’s Law”。
我们都知道 Moore 定律说集成电路上晶体管数量每 18 个月番一番,但这篇论文则研究并验证了所谓的Proebsting 定律: 编译器优化技术带来的性能提升每 18 年番一番。Proebsting 定律是在 1998 年提出的,当时的提出者 Todd Proebsting 可能只是在开玩笑,因为他建议编译器和编程语言研究界应该减少对性能优化的关注,而应该更多的关注程序员工作效率的提升。
现在我们来事后诸葛亮评价这一建议就能发现其实这并不是无道理的: Go 语言的编译器虽然经历过几大版本的优化,但其使用的技术并不够 fancy,相反而是很传统且中规中矩的优化技术。然而这并不影响 Go 语言的成功,因为它尝试解决的正是程序员的工作效率:
- 通过避免循环以来而极大的减少了程序员等待编译的时间
- 非常简洁的语言设计与特性极大的减少了程序员思考如何使用语言的时间
- 向前的兼容性保障几乎彻底消除了因为版本升级给程序员带来的迁移和维护时间
- 论文地址/Paper: https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.29.434&rep=rep1&type=pdf
- Proebsting’s Law: http://proebsting.cs.arizona.edu/law.html
Telegram BotTelegram 机器人
Because the COVID situation in Europe is still terrible, even shopping at an Apple Store requires an appointment in advance. Since I urgently needed to visit an Apple Store recently but couldn’t find any available appointment slots, I quickly hacked together a tool to check availability and send a reminder message via Telegram when an appointment becomes available. Tool link: https://changkun.de/s/apreserve
Interacting with Telegram using Go is straightforward:
- Create a bot from BotFather
- Obtain the bot’s token and the chat ID for your conversation with it
- Then you can handle messages
- BotFather: https://t.me/botfather
- Tg bot API Go bindings: https://github.com/go-telegram-bot-api/telegram-bot-api
|
|
因为欧洲疫情依然很糟糕,所以现在甚至于想去苹果店购物都要提前预约。因为最近急需要去苹果店一次,又苦于刷不到可用的预约位置,刚刚顺手就糊一个工具来检查,当预约可用时给telegram发送一条提醒消息。工具地址: https://changkun.de/s/apreserve
用 Go 和 telegram 进行交互没有任何难度:
- 从 botfather 创建一个 bot
- 获得这个 bot 的 token 以及跟它对话的 chatid
- 于是可以处理消息了
- BotFather: https://t.me/botfather
- Tg bot API Go bindings: https://github.com/go-telegram-bot-api/telegram-bot-api
|
|
Apple SiliconApple Silicon
How is Go’s compilation performance on darwin/arm64? I did a rough and non-rigorous comparison of Go compilation performance between an Intel Mac and an M1 Mac. This compilation report was generated with the following commands:
$ go build -gcflags='-bench=bench.out' -a $ cat bench.out
where -a disables the compilation cache.
MacBook Air (M1, 2020), Apple M1, 16 GB:
|
|
Mac mini (2018), 3 GHz 6-Core Intel Core i5, 8 GB 2667 MHz DDR4:
|
|
Go在darwin/arm64上的编译性能怎么样?我很不严谨的粗略比较了Intel Mac 和 M1 Mac 的 Go 编译性能。这个编译报告由如下指令生成:
$ go build -gcflags='-bench=bench.out' -a $ cat bench.out
其中-a用于禁用编译缓存。
MacBook Air (M1, 2020), Apple M1, 16 GB:
|
|
Mac mini (2018), 3 GHz 6-Core Intel Core i5, 8 GB 2667 MHz DDR4:
|
|