DEV Community

Evan Lin
Evan Lin

Posted on • Originally published at evanlin.com on

[TIL][Go] Code Reading Tips for etcd: Optimizing Segregated Hashmaps

Preface:

Whenever the topic of understanding architecture through open source research comes up in the Gopher TW discussion group, I personally highly recommend etcd. The reasons are as follows:

  • Simple tasks: etcd's tasks are relatively straightforward.
  • Basic Client/Server concept (and many tools available)
  • Features the RAFT distributed computing HA algorithm

So, when discussing how to study code, I also enjoy sharing etcd.

Code Link:

https://github.com/etcd-io/etcd

Related Recommendations:

So, during this discussion, I also made the following suggestions:

Reading well-structured code based on your objectives is like reading a good book. It's very beneficial!

Netizen's suggestion for segregated hashmap performance optimization:

According to netizen Naruto's suggestion:

Because the page storage area of the bbolt db will have performance problems, a set of segregated hashmap was designed to solve it

Quick search, summarized:

segregated hashmap

An optimization initiated by Alibaba, based on performance bottlenecks they discovered in their business operations.

Very effective

The new optimization reduces time complexity of the internal freelist allocation algorithm in etcd from O(n) to O(1) and the page release algorithm from O(nlgn) to O(1) , which solves the performance problem of etcd under the large database size. Literally, the etcd’s performance is not bound by the storage size anymore. The read and write operations when etcd stores 100GB of data can be as quickly as storing 2GB. This new algorithm is fully backward compatible.

I'll find some time to study it...

Top comments (0)