In part 2, we figured out a benchmark for the low-performant API, now we start to deep dive to see if we can find the root cause and remediation.
Performance tuning Part 2
A good performance testing requires more than just executing a single script.
In part 1, I talked about the right way to identify and address the problem, now here I will talk more about what is a good performance testing and how to do a benchmark appropriately.
Performance tuning Part 1
Prelude
We received a critical incident report from Project X on the Production environment. The CPU of the Database (i.e. Couchbase, more specifically, a bucket called members) increased drastically and reached 100%, and the system became unavailable for a few hours.
The lucky thing was that the system was restored after the traffic spike ceased, but the sad thing was …
We didn’t know where the traffic was from and why it caused intensive CPU usage on Database, so the symptom may happen again in future.
Algebraic Data Types in TypeScript
So, what’s algebraic data type?
In computer programming, especially functional programming and type theory, an algebraic data type (ADT) is a kind of composite type, i.e., a type formed by combining other types.
No worries if you have a hard time to understand the definition above, we start with storytelling.
Less is more when it comes to code
I have been learning Haskell for a while, it’s one of the famous functional programming languages. When I practiced with some exercises, I found an interesting thing that the Excercise here requires you to write the code as little as possible.
Well, it is not necessary to pursue the most minimalistic line of code in most cases, but in general, a smaller code base is easier to understand and maintain over time.
Then I was curious how shorter I could get it done with … Haskell.
Send HTTP requests with netcat
Occasionally I need to call HTTP API from a bare-bones environment, where we don’t have curl
or wget
. Nowadays, it’s so common that we run everything in the dockerized environment, and we are apt to use a slim docker image without many utility libraries.
Bring Emacs to the foreground on macOS Catalina
I have been using Emacs for a few months, I always keep one instance and use a global shortcut key cmd + e
to open or switch it to the foreground.
I did it with Karabiner-Element key mapping{
"from": {
"key_code": "e",
"modifiers": {
"mandatory": [
"right_command"
]
}
},
"to": [
{
"shell_command": "open -a 'emacs'"
}
],
"type": "basic"
}
Recently I upgraded the macOS to Catalina and found the open -a emacs
can not bring it to foreground anymore. I spent hours searching with google until I found this post(https://spin.atomicobject.com/2019/12/12/fixing-emacs-macos-catalina/).
When ramdajs meets Promise
Challenge
I use ramdajs a lot as I like its conciseness and functional style, but recently I met a challenge with it with Promise. The scenario is deadly simple, I need to fetch some records from the DB and do some transformation and save them back.
Quite straightforward to use ramda for data transformation, isn’t it?
const ids = ['123', '456', '789'] |
Redis Sentinel Docker
I am a big fan of TDD, and I use docker a lot to build the dependencies(APIs, Database, etc.) for the unit test in my local development environment and CI. Everything goes well until one day our lovely DevOps guys asked me to use Redis sentinel which provides high availability, it’s a good practice, and I like the automatic failover capability. Since we always try to align the test environment to the production one, even for the local development environment, so I plan to build the Redis sentinel with docker.
Challenge
Redis Sentinel is a typical distributed architecture, the significant difference of using sentinel is that you should ask “redis-sentinel” for “redis-master” first, then issue redis command to the “redis-master” sentinel told you.
Long story short, I need to orchestrate 1 master/ 1 slave/ 1 sentinel with docker properly.
从命令式编程到函数式编程
不要被题目骗了:D, 此文不讲概念(题目太大),只和大家分享一个很简单的案例, 权当抛砖引玉。
背景
最近在做一个项目,对接的API要求对response body进行签名,验签规则此处不赘述了,有一点比较好玩的事要求对嵌套的字段进行stringify再进行验签处理,有点类似于lodash的flatten, 不过不是处理array而是json object, 可能说到这里有点费解,看代码便知。
TALK IS CHEAP, SHOW ME THE CODE!