This is the fifth day of my participation in the August More text Challenge. For details, see:August is more challenging

  • 📢 welcome to like: 👍 collect ⭐ message 📝 If there is any mistake please correct it, send roses, hand left fragrance!
  • 📢 This article is written by Webmote.
  • 📢 author’s motto: life lies in tossing about, when you do not toss about life, life will start tossing you, let us work together! 💪 💪 💪

Preface 🎏

Official definition: ETCD is a highly consistent distributed key-value store that provides a reliable way to store data that needs to be accessed by a distributed system or cluster of machines. It gracefully handles leader elections during network partitions and tolerates machine failures even in leader nodes.

The most common function of ETCD is to store the system configuration in the configuration center, and we know that the configuration center is a read more than write scenario, and the configuration needs to be very consistent, so ETCD is suitable for this scenario.

🎏 01. Just how slow

In some business scenarios, high consistency is most needed, and in order to ensure high consistency, it is of course better to promote high concurrency. Of course, if ETCD is hardwired, it is not recommended to be used in high performance scenarios.

Since ETCD has been selected for some features, let’s test the read and write performance of ETCD.

Set up a 3-node ETCD for the VM with a configuration of 4CPU /2GB. Write test programs. The simplest way is to use the GRPC underlying communication, single-thread read and single-thread write.

The code is as follows:

EtcdClient etcdClient = new EtcdClient("Http://192.168.137.100:2379...");  

var resp = etcdClient.Put("foo/bar"."barfoo");

WatchRequest request = new WatchRequest()
{
    CreateRequest = new WatchCreateRequest()
    {
        Key = ByteString.CopyFromUtf8("foo/a"),
        RangeEnd = ByteString.CopyFromUtf8("foo/z"),}};//print executes in a different thread
etcdClient.Watch(request, print);

Task.Run(() =>
{
    Thread.Sleep(1000);
    Stopwatch sw = new Stopwatch();
    sw.Start();
    for (int i = 0; i < 10000; i++)
    {     
        etcdClient.Put($"foo/bar{i}".$"barfoo333-{i}");       
    }
    sw.Stop();
    Console.WriteLine($"100 Key write  : {sw.ElapsedMilliseconds} ms");
    Thread.Sleep(10000);
    Console.WriteLine($"100 Key Read  : {_ms} ms");
});
private static void print(WatchResponse response){... }Copy the code

After several tests, the read/write performance of ETCD 3 nodes is available:

An old blood spurt, how so slow ~

After communication with experts, it is determined that such a slow speed is not the real performance of ETCD. It should be caused by the slow speed of the virtual robot’s hard disk, so it needs to be changed to SSD disk to show the real strength of ETCD.

🎏 02. Replace the hard disk with an SSD

Copy a virtual machine, is a matter of minutes, change it to SSD, test again, the results reached the ideal state.

Write QPS of 1333, which is pretty good in this configuration.

In addition, the notification event was tested, which was executed in a different thread ID, so if there is business on the consumer side, the transaction needs to be kept non-conflicting.

In addition, the advantage of ETCD is that it can monitor the changes of 1 group of keys,

  • Listen for a range of keys (e.g. I can listen for key=foo/a ~ foo/z). This is an important feature of ETCD.)
  • Different consumer consumption rates do not affect message consumption.

🎏 03. Compare Redis

Now that I have written here, I also compared the performance indicators of Redis. Redis uses Pub/sub method to build. After all, memory database, read and write performance is very high. Part code:

Var _conn = ConnectionMultiplexer. Connect (" 192.168.137.101 "); var db = _conn.GetDatabase(); var sub = _conn.GetSubscriber(); sub.Subscribe("channel1", (channel, val) => { _sw.Restart(); Console.WriteLine($"{channel}: {val }"); _sw.Stop(); _ms += _sw.ElapsedMilliseconds; });Copy the code

10000 Key write : 1312 ms;

10000 Key Read : 351 ms

🎏 04. Summary

ETCD should be able to be applied to the business, after all, our business concurrency is not that high, but this scenario is also suitable for Redis ah, performance is not a bottleneck, but the business needs to make consistency guarantee, since there is a DB base, it should not be a problem!

So architecture is always in the middle, various factors in it, it does not have to be!

To develop a good habit requires constant encouragement and encouragement. Writing ability may be improved through continuous writing, and of course, my own capacity. In the process of continuous output, I find my own deficiencies and consolidate my knowledge.

Today is the fifth day. Come on, guys!

Routine summary, rational view!

Knot is what, knot is I want you to like but can not get the loneliness. 😳 😳 😳

👓 all see this, still care to point a like?

👓 all points like, still care about a collection?

Do you care about a comment when you have collected 👓?