精品欧美一区二区三区在线观看 _久久久久国色av免费观看性色_国产精品久久在线观看_亚洲第一综合网站_91精品又粗又猛又爽_小泽玛利亚一区二区免费_91亚洲精品国偷拍自产在线观看 _久久精品视频在线播放_美女精品久久久_欧美日韩国产成人在线

演講實錄|唐劉:Rust in TiKV

企業動態
本文是 Rust 專場 Meetup 上,我司首席架構師唐劉同學的現場分享,共享給大家。

本文是 Rust 專場 Meetup 上,我司***架構師唐劉同學的現場分享,共享給大家。

Hello everyone, today I will talk about how we use Rust in TiKV.

Before we begin, let me introduce myself. My name is TangLiu, the Chief Architect of PingCAP. Before I joined PingCAP, I had worked at Kingsoft and Tencent. I love open source and have developed some projects like LedisDB, go-mysql, etc…

At first, I will explain the reason why we chose Rust to develop TiKV, then show you the architecture of TiKV briefly and the key technologies. In the end, I will introduce what we plan to do in the future.

What’s TiKV?

All right, let’s begin. First, what is TiKV. TiKV is a distributed Key-Value database with the following features:

  • Geo-replication: We use Raft and Placement Driver to replicate data geographically to guarantee data safety.
  • Horizontal scalability: We can add some nodes directly if we find that the rapidly growing data will soon exceed the system capacity.
  • Consistent distributed transaction: We use an optimized, two phase commit protocol, based on Google Percolator, to support distributed transactions. You can use “begin” to start a transaction, then do something, then use “commit” or “rollback” to finish the transaction.
  • Coprocessor for distributed computing: Just like HBase, we support a coprocessor framework to let user do computing in TiKV directly.
  • Working with TiDB like Spanner with F1: Using TiKV as a backend storage engine of TiDB, we can provide the best distributed relational database.

We need a language with…

As you see, TiKV has many powerful features. To develop these features, we also need a powerful programming language. The language should have:

  • Fast speed: We take the performance of TiKV very seriously, so we need a language which runs very fast at runtime.
  • Memory safety: As a program that is going to run for a long time, we don’t want to meet any memory problem, such as dangling pointer, memory leak, etc…
  • Thread safety: We must guarantee data consistency all the time, so any data race problem must be avoided.
  • Binding C efficiency: We depend on RocksDB heavily, so we must be able to call the RocksDB API as fast as we can, without any performance reduction.

Why not C++?

To develop a high performance service, C++ may be the best choice in most cases, but we didn’t choose it. We figured we might spend too much time avoiding the memory problem or the data race problem. Moreover, C++ has no official package manager and that makes the maintaining and compiling third dependences very troublesome and difficult, resulting in a long development cycle.

Why not Go?

At first, we considered using Go, but then gave up this idea. Go has GC which fixes many memory problems, but it might stop the running process sometimes. No matter how little time the stop takes, we can’t afford it. Go doesn’t solve the data race problem either. Even we can use double dash race in test or at runtime, this isn’t enough.

Besides, although we can use Goroutine to write the concurrent logic easily, we still can’t neglect the runtime expenses of the scheduler. We met a problem a few days ago: we used multi goroutines to select the same context but found that the performance was terrible, so we had to use one sub context for one goroutine, then the performance became better.

More seriously, CGO has heavy expenses, but we need to call RocksDB API without delay. For the above reasons, we didn’t choose Go even this is the favorite language in our team.

So we turned to Rust…

But Rust…

Rust is a system programming language, maintained by Mozilla. It is a very powerful language, however, you can see the curve, the learning curve is very very steep.

I have been using many programming languages, like C++, Go, python, lua, etc. and Rust is the hardest language for me to master. In PingCAP, we will let the new colleague spend at least one month to learn Rust, to struggle with the compiling errors, and then to rise above it. This would never happen for Go.

Besides, the compiling time is very long, even longer than C++. Each time when I type cargo build to start building TiKV, I can even do some pushups.

Although Rust is around for a long time, it still lacks of libraries and tools, and some third projects have not been verified in production yet. These are all the risks for us. Most seriously, it is hard for us to find Rust programmer because only few know it in China, so we are always shorthanded.

Then, Why Rust?

Although Rust has the above disadvantages, its advantages are attractive for us too. Rust is memory safe, so we don’t need to worry about memory leak, or dangling pointer any more.

Rust is thread safe, so there won’t be any data race problem. All the safety are guaranteed by compiler. So in most cases, when the compiling passes, we are sure that we can run the program safely.

Rust has no GC expenses, so we won’t meet the “stop the world” problem. Calling C through FFI is very fast, so we don’t worry the performance reduction when calling the RocksDB API. At last, Rust has an official package manager, crate, we can find many libraries and use them directly.

We made a hard but great decision: Use Rust!

TiKV Timeline

TiKV Timeline

Here you can see the TiKV timeline. We first began to develop TiKV January 1st, 2016, and made it open source on April 1st, 2016, and this is not a joke like Gmail at All April Fool’s Day. TiKV was first used in production in October, 2016, when we had not even released a beta version. In November, 2016, we released the first beta version; then RC1 in December, 2016, RC2 in February, this year. Later we plan to release RC3 in April and the first GA version in June.

As you can see, the development of TiKV is very fast and the released versions of TiKV are stable. Choosing Rust has already been proved a correct decision. Thanks, Rust.

TiKV Architecture

TiKV Architecture

Now let’s go deep into TiKV. You can see from the TiKV architecture that the hierarchy of TiKV is clear and easy to understand.

At the bottom layer, TiKV uses RocksDB, a high performance, persistent Key-Value store, as the backend storage engine.

The next layer is Raft KV. TiKV uses the Raft to replicate data geographically. TiKV is designed to store tons of data which one Raft group can’t hold. So we split the data with ranges and use each range as an individual Raft group. We name this approach: Multi-Raft groups.

TiKV provides a simple Key-Value API including SET, GET, DELETE to let user use it just as any distributed Key-Value storage. The upper layer also uses these to support advanced functions.

Above the Raft layer, it is MVCC. All the keys saved in TiKV must contain a globally unique timestamp, which is allocated by Placement Driver. TiKV uses it to support distributed transactions.

On the top layer, it is the KV and coprocessor API layer for handling client requests.

Multi-Raft

Multi-Raft

Here is an example of Multi-Raft.

You can see that there are four TiKV nodes. Within each store, we have several regions. Region is the basic unit of data movement and is replicated by Raft. Each region is replicated to three nodes. These three replicas of one Region make a Raft group.

Scale Out

Scale-out (initial state)

Here is an example of horizontal scalability. At first, we have four nodes, Node A has three regions, others have two regions.

Of course, Node A is busier than other nodes, and we want to reduce its stress.

Scale-out (add new node)

Scale-out (add new node)

So we add a new Node E, and begin to move the region 1 in Node A to Node E. But here we find that the leader of region 1 is in Node A, so we will first transfer the leader from Node A to Node B.

Scale-out (balancing)

Scale-out (balancing)

After that, the leader of region 1 is in Node B now, then we add a new replica of region 1 in Node E.

Scale-out (balancing)

Then we remove the replica of region 1 from Node A. All these are executed by the Placement Driver automatically. What we only need is to add node, if we find the system is busy. Very easy, right?

A simple write flow

A simple write flow

Here is a simple write flow: when a client sends a write request to TiKV, TiKV first parses the protocol and then dispatches the request to the KV thread, then the KV thread executes some transaction logics and sends the request to Raft thread, after TiKV replicates the Raft log and applies it to RocksDB, the write request is finished.

Key technologies

Now let’s move on to the key technologies:

For networking, we use a widely used protocol, Protocol Buffers, to serialize or unserialize data fastly.

At first, we used MIO to build up the network framework. Although MIO encapsulates low level network handling, it is still a very basic library that we need to receive or send data manually, and to decode or encode our customized network protocol. It is not convenient actually. So from RC2, we have been refactoring networking with gRPC. The benefit of gRPC is very obvious. We don’t need to care how to handle network anymore, only focusing on our logic, and the code looks simple and clear. Meanwhile, users can build their own TiKV client with other programming languages easily. We have already been developing a TiKV client with Java.

For asynchronous framework. After receiving the request, TiKV dispatches the request to different threads to handle it asynchronously. At first, we used the MIO plus callback to handle the asynchronous request, but callback may break the code logic, and it is hard to read and write correctly, so now we have been refactoring with tokio-core and futures, and we think this style is more modern for Rust in the future. Sometimes, we also use the thread pool to dispatch simple tasks, and we will use futures-cpupool later.

For storage, we use rust-rocksdb to access RocksDB.

For monitoring, we wrote a rust client for Prometheus, and this client is recommended in the official wiki. For profiling, we use the jemallocator with enabling profile feature and use clippy to check our codes.

Future plan

Ok, that’s what we have done and are doing. Here are what we will do in the future:

  • Make TiKV faster, like removing Box. we have used many boxes in TiKV to write code easily, this is not efficient. In our benchmark, dynamic dispatch is at least three times slower than static dispatch, so later we will use Trait Trait directly.
  • Make TiKV more stable, like introducing Rust sanitizer.
  • Contribute more Rust open source modules, like raft library, open-tracing, etc.
  • Participate in other Rust projects more deeply, like rust-gRPC
  • Write more articles about Rust on Chinese social media and organize more Rust meetups.
  • Be a strong advocate of Rust in China.

【本文是51CTO專欄機構“PingCAP”的原創文章,轉載請聯系作者本人獲取授權】

戳這里,看該作者更多好文

責任編輯:趙寧寧 來源: 51CTO專欄
相關推薦

2013-12-22 22:58:16

柳傳志IBM

2013-04-11 16:59:07

IDF2013賈斯汀

2017-11-03 13:30:41

深度學習TensorFlowGoogle Brai

2017-12-01 13:13:39

AI網易傳媒信息流

2017-06-04 23:18:44

數據庫分布式

2025-05-19 08:43:00

2017-12-01 12:35:57

信息無障礙

2011-05-12 14:16:54

2013-09-11 16:34:57

蘋果iPhone 5ciPhone 5s

2018-04-28 14:29:50

晨犀科技

2024-06-13 07:55:19

2016-06-21 16:09:14

智能化

2020-05-12 22:42:31

IBMThink Digit

2020-05-12 23:00:25

IBMThink Digit

2020-05-12 22:52:23

IBMThink Digit

2020-05-12 23:03:12

IBMThink Digit

2025-06-10 16:29:25

IlyaAI
點贊
收藏

51CTO技術棧公眾號

av免费观看一区二区| 污污的视频在线免费观看| 日本在线啊啊| 久久婷婷综合激情| 国产日韩视频在线观看| 美女毛片在线观看| 极品美女一区二区三区| 91精品国产综合久久久久久久久久| 毛片av在线播放| 水莓100国产免费av在线播放| 美国十次了思思久久精品导航| 欧美国产第一页| 中文字幕第20页| 91精品导航| 欧美在线播放高清精品| 青青青青在线视频| 日韩av中文| 久久夜色精品国产噜噜av| 91亚洲精品久久久| 最近免费中文字幕大全免费版视频| 天天操综合网| 亚洲天堂视频在线观看| 欧美性生交xxxxx| 日本一区二区中文字幕| 一本色道亚洲精品aⅴ| 久操手机在线视频| 调教视频免费在线观看| 久久久精品国产免大香伊 | 一区二区三区视频在线播放| 免费观看成年人视频| 极品美女销魂一区二区三区免费| 欧美综合一区第一页| 妺妺窝人体色www婷婷| 99久久夜色精品国产亚洲96 | 91在线视频| 26uuu欧美| 国产一区二区久久久| 国产又黄又大又爽| 日本女人一区二区三区| 日产日韩在线亚洲欧美| 日韩大片免费在线观看| 欧美日韩ab| 欧美老少做受xxxx高潮| 99热这里只有精品4| 欧美三级情趣内衣| 亚洲第一黄色网| 污污免费在线观看| 哺乳挤奶一区二区三区免费看 | 日韩精品一二| 9久草视频在线视频精品| 国产99在线免费| 午夜精品久久久久久久99热黄桃| 国产在线精品一区二区夜色| 国产原创欧美精品| 亚洲视频一区二区三区四区| 日本女人一区二区三区| 国产精品久久久久久亚洲调教| 亚洲综合久久网| 日韩综合在线视频| 国产精品旅馆在线| 中文字幕av久久爽| 麻豆成人在线观看| 91视频免费网站| 国内精品久久久久久久久久久 | 精品视频一区二区不卡| 久久久国产欧美| 久久亚洲人体| 91精品国产综合久久久蜜臀粉嫩| 被黑人猛躁10次高潮视频| 亚洲小说春色综合另类电影| 精品国产一二三区| 色噜噜在线观看| 国产精品一区二区99| 国产一区二区三区在线播放免费观看| 欧美另类69xxxx| 91精品啪在线观看国产18 | 青青草偷拍视频| 一区在线视频| 欧美日韩在线影院| 精品欧美黑人一区二区三区| 天天影视综合色| 欧美高清xxx| 91精品国产免费| 亚洲欧美综合视频| 一本久久青青| www亚洲欧美| 国产亚洲欧美精品久久久久久| 在线播放不卡| 国产精品久久久久aaaa九色| 97国产成人无码精品久久久| 国产成人综合在线播放| 久久久久久久久四区三区| 国产无套粉嫩白浆在线2022年| 中文字幕一区二区三区在线观看| 国产一区二区三区小说| 性欧美1819sex性高清| 欧美高清激情brazzers| 亚洲视频 中文字幕| 国产麻豆精品久久| 久久99视频精品| 国产精品露脸视频| 成人免费视频网站在线观看| 日韩欧美99| 国语对白在线刺激| 在线观看视频91| 成人做爰www看视频软件| 精品成人影院| 久久久综合免费视频| 中文字幕免费高清在线观看| 成人免费毛片aaaaa**| 偷拍视频一区二区| 国产精品yjizz视频网| 欧美日韩mp4| 中文字幕在线观看网址| 欧美成人有码| 国产欧美日韩视频| 欧美偷拍视频| 亚洲综合一区二区三区| 色悠悠久久综合网| 天天躁日日躁成人字幕aⅴ| 久久久久99精品久久久久| 91video| 国产一区91精品张津瑜| 日本一区免费看| 蜜乳av一区| 欧美高清hd18日本| 非洲一级黄色片| 亚洲精品免费观看| 999日本视频| 91caoporm在线视频| 色94色欧美sute亚洲13| 天天插天天射天天干| 午夜精品视频| 51国产成人精品午夜福中文下载| 午夜视频在线观看网站| 欧美性一二三区| 一色道久久88加勒比一| 性欧美videos另类喷潮| 久久久水蜜桃| 天堂中文在线播放| 日韩av在线免播放器| 精品无码黑人又粗又大又长| 懂色av一区二区夜夜嗨| 欧美日韩中文字幕在线播放| 精品成人18| 久久精品男人天堂| 国产精品国产av| 综合久久综合久久| 在线免费黄色网| 久久精品免费一区二区三区| 成人午夜在线视频一区| 国产福利在线播放麻豆| 91精品国产综合久久精品app| 日本污视频网站| 麻豆久久一区二区| 亚洲视频在线观看日本a| 久久99国产精品二区高清软件| 色综合影院在线| 国产精品丝袜黑色高跟鞋| 亚洲欧美日韩久久精品| 三上悠亚 电影| 激情综合在线| 牛人盗摄一区二区三区视频| 国产v综合v| 中文字幕欧美国内| 国产三级精品在线观看| 一区二区国产视频| 香港三日本8a三级少妇三级99| 一区二区福利| 三级三级久久三级久久18| 黄色成人在线观看网站| 免费成人高清视频| 老牛影视av牛牛影视av| 精品日韩美女的视频高清| 永久免费成人代码| 激情小说亚洲一区| 97干在线视频| 成人综合专区| 成人av电影免费| 中文字幕乱码在线播放| 中文一区二区视频| h片在线免费看| 狠狠色噜噜狠狠狠狠97| 亚洲一级黄色录像| 国产福利一区二区三区视频| 欧美激情视频免费看| 精品美女视频| 99在线国产| 欧美韩国亚洲| 久久久久久久久久久免费| 久久久久久女乱国产| 911精品产国品一二三产区| 99免费在线观看| 中文字幕av免费专区久久| 亚洲精品一区二区18漫画| 男女精品网站| 黄色一级大片免费| 国产一区日韩| 147欧美人体大胆444| 偷拍精品精品一区二区三区| 欧美成人精品在线视频| 青青草免费在线| 日韩欧美国产高清| 精品国产乱子伦| 亚洲一区二区三区小说| 欧美日韩国产黄色| www.99精品| 亚洲天堂av一区二区| 亚洲美女91| 男插女免费视频| 女优一区二区三区| 成人区精品一区二区| yw.尤物在线精品视频| 国内揄拍国内精品| 亚洲区欧洲区| 日韩网站免费观看高清| 牛牛澡牛牛爽一区二区| 日韩免费一区二区| 国产精品高潮呻吟久久久| 日本高清不卡一区| 日韩欧美性视频| 一区二区三区中文字幕| 免费成人深夜蜜桃视频| 久久久九九九九| 自拍视频一区二区| 懂色av噜噜一区二区三区av| 国产精品熟女一区二区不卡| 美腿丝袜亚洲综合| 国内自拍视频一区| 亚洲欧美日韩国产综合精品二区 | 久久久久久青草| 亚洲娇小xxxx欧美娇小| 性一交一乱一透一a级| 欧美精品在线一区二区| 波多野结衣毛片| 99精品免费网| 亚洲一区影院| 日韩在线中文| 亚洲乱码一区二区三区| 激情影院在线| 日韩亚洲欧美中文在线| 国产成人免费观看视频| 日韩美女啊v在线免费观看| 99国产精品无码| 亚洲欧美卡通另类91av| 亚洲精品少妇一区二区| 亚洲国产一区二区在线观看 | 麻豆亚洲av熟女国产一区二| 亚洲丝袜自拍清纯另类| 日韩av片在线免费观看| 日本不卡高清视频| 四虎4hu永久免费入口| 99久久99久久精品国产片桃花| 午夜免费在线观看精品视频| av在线导航| 欧美影院一区二区三区| 日韩久久中文字幕| 国产一区二区不卡在线| 国产精品v日韩精品v在线观看| 天天久久夜夜| 久久狠狠久久综合桃花| 亚洲高清极品| 欧美精品在线看| 空姐吹箫视频大全| 国产精品美女一区二区| 91夜夜未满十八勿入爽爽影院| 熟妇人妻av无码一区二区三区 | 精品久久久99| 久久九九热re6这里有精品| 日韩一区二区久久久| 老熟妇高潮一区二区高清视频| 亚洲一二三级电影| 欧美大片日本大片免费观看| 成人无码www在线看免费| 欧美激情aⅴ一区二区三区| 国产乱码精品一区二区三区日韩精品| 国产三区视频在线观看| 欧美综合亚洲图片综合区| av漫画在线观看| 免费视频观看成人| 亚洲国产美国国产综合一区二区| av免费在线播放网站| 国产盗摄精品一区二区酒店| 亚洲成人在线免费| 国模精品一区二区三区| 性感美女福利视频| 国产午夜精品理论片a级大结局 | 亚洲天堂网2018| 高清久久久久久| 五月婷婷综合在线观看| 国产精品久久久久久久午夜片| a级黄色片免费看| 欧美日韩亚洲视频| 97av免费视频| 亚洲欧美成人一区二区在线电影| 秋霞影院午夜丰满少妇在线视频| 97av在线视频| 91精品麻豆| 九9re精品视频在线观看re6| 日韩专区精品| 5月婷婷6月丁香| 激情图区综合网| 动漫精品一区二区三区| 亚洲天堂免费看| 五月激情六月丁香| 宅男在线国产精品| 国产香蕉视频在线看| 色在人av网站天堂精品| 国产精品黄色片| 蜜桃麻豆www久久国产精品| 欧美成人精品| 免费在线观看污网站| 久久久久久久综合日本| 激情五月婷婷在线| 欧美裸体一区二区三区| 精品亚洲综合| 97碰在线观看| 在线一区二区三区视频| 视频一区免费观看| 亚洲一区二区三区高清不卡| 伊人成人免费视频| 国产精品毛片久久久久久| 国产性xxxx高清| 日韩情涩欧美日韩视频| h视频网站在线观看| 538国产精品一区二区在线 | 中文字幕这里只有精品| 成人动漫在线观看视频| 91精品国产福利在线观看麻豆| 五月天激情视频在线观看| 久久伊人蜜桃av一区二区| 亚洲黄色三级视频| 精品国产一区二区三区av性色| 成人影院在线观看| 亚洲www视频| 99久久99久久精品国产片桃花| 天天综合网久久| 国产精品午夜春色av| 久久国产乱子伦精品| 亚洲欧洲偷拍精品| 韩日精品一区二区| 久久精品一二三区| 国产手机视频一区二区| 国产精品久久久免费观看| 午夜久久久久久久久久一区二区| 北条麻妃一二三区| 久久久久久久久电影| 中文字幕一区二区三区四区久久| 日韩亚洲欧美一区二区| 国产一区二区美女诱惑| 全网免费在线播放视频入口| 欧美一级淫片007| 国内在线免费视频| 激情一区二区三区| 久久久久国产精品一区三寸 | 天堂a√在线| 国产91精品青草社区| 国产精品一区2区3区| 69久久久久久| 亚洲视频在线一区| 国产亲伦免费视频播放| 欧美极品少妇xxxxⅹ裸体艺术 | 国产精品综合视频| 久久这里只有精品免费| 精品国产91乱码一区二区三区| 色戒汤唯在线观看| 少妇精品久久久久久久久久| 久久国产精品色婷婷| 国产av无码专区亚洲av毛网站| 日韩欧美国产麻豆| 中国字幕a在线看韩国电影| 日韩成人在线资源| 国产福利一区在线| 国产69精品久久久久久久久久| 国产亚洲aⅴaaaaaa毛片| 91丨精品丨国产| 日韩中字在线观看| 日本一区二区综合亚洲| 国产免费一区二区三区最新不卡| 欧美激情亚洲另类| 国产精品一线天粉嫩av| 免费网站在线观看黄| 亚洲sss视频在线视频| av在线资源站| 国产伦理一区二区三区| 日本中文字幕一区| 精品无码av在线| 伊人久久大香线蕉av一区二区| 日韩中文字幕无砖| 精品国产成人av在线免| 亚洲人成网站在线| 日本免费不卡| 91久色国产| 免费看欧美女人艹b| 日韩精品在线不卡| 日韩在线视频导航| 亚洲宅男一区| 制服.丝袜.亚洲.中文.综合懂| 91久久精品网| av免费不卡国产观看|