Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
so this is KeyDB! So what.
Search
Naoto Gohko
April 17, 2021
Programming
1
700
so this is KeyDB! So what.
redisの代わりにkeydbを使ってみた話
OSunC 2021/04/17 Spring/Onlineより
Naoto Gohko
April 17, 2021
Tweet
Share
More Decks by Naoto Gohko
See All by Naoto Gohko
asks Canonical about Ubuntu support and starts using Ubuntu
naototty
0
61
Rancher Harvester and KubeVirt HCI operator
naototty
0
390
ODC2020; "Rocky 8", Rocky Linux 8 story
naototty
0
520
2020/07/25 OSC Niigata/Online LT; about xlsx2csv-go-CLI
naototty
1
690
私とOSC Hokkaido Love (私のOSC Hokkaido参加の振り返り)
naototty
1
470
GTB2020; Introduction to virtualization technology on GMO Tech Bootcamp
naototty
0
240
OSS Forum in Tokyo/Winter: Around the OpenStack world in 2019.
naototty
0
360
Use ubuntu canonical's multipass command
naototty
0
350
Bifrost Ironic Standalone deep dive for GPU baremetal cloud
naototty
0
300
Other Decks in Programming
See All in Programming
Git Sync を超える!OSS で実現する CDK Pull 型デプロイ / Deploying CDK with PipeCD in Pull-style
tkikuc
4
240
イベントストーミング図からコードへの変換手順 / Procedure for Converting Event Storming Diagrams to Code
nrslib
2
970
Webの外へ飛び出せ NativePHPが切り拓くPHPの未来
takuyakatsusa
2
580
なぜ適用するか、移行して理解するClean Architecture 〜構造を超えて設計を継承する〜 / Why Apply, Migrate and Understand Clean Architecture - Inherit Design Beyond Structure
seike460
PRO
3
790
型で語るカタ
irof
0
530
Goで作る、開発・CI環境
sin392
0
260
顧客の画像データをテラバイト単位で配信する 画像サーバを WebP にした際に起こった課題と その対応策 ~継続的な取り組みを添えて~
takutakahashi
1
310
ペアプロ × 生成AI 現場での実践と課題について / generative-ai-in-pair-programming
codmoninc
2
20k
テスト駆動Kaggle
isax1015
1
510
はじめてのWeb API体験 ー 飲食店検索アプリを作ろうー
akinko_0915
0
130
AI駆動のマルチエージェントによる業務フロー自動化の設計と実践
h_okkah
0
210
The Niche of CDK Grant オブジェクトって何者?/the-niche-of-cdk-what-isgrant-object
hassaku63
1
500
Featured
See All Featured
Measuring & Analyzing Core Web Vitals
bluesmoon
7
510
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
18
980
Thoughts on Productivity
jonyablonski
69
4.7k
Testing 201, or: Great Expectations
jmmastey
43
7.6k
The Cult of Friendly URLs
andyhume
79
6.5k
A designer walks into a library…
pauljervisheath
207
24k
It's Worth the Effort
3n
185
28k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Making the Leap to Tech Lead
cromwellryan
134
9.4k
How STYLIGHT went responsive
nonsquared
100
5.6k
Become a Pro
speakerdeck
PRO
29
5.4k
Transcript
KeyDBですが、なにか? So this is the ”KeyDB”, so what? DB alternative探訪シリーズ
part 3 forked redis OSunC 2021 Online Spring / 2021-04-17 @naoto_gohko
LT presenter(Itʼs me) • Naoto Gohko / 郷古 直仁 (@naoto_gohko)
• Cloud Service development divistion, GMO Internet Inc., • OpenStackでpublic cloudサービス • 最近の活動主体 • Japan OpenStack user会 / OSC onlineお⼿伝い(Zoom修⾏) • 最近 • 最近とある製品のre: brandにより、美雲あんずは ConoHaショップ店⻑になったらしい @MikumoConoHa @MikumoAnzu
暖かくなってきました。 皆様 お出かけしたいですね …… そんな中、とある仕事 でのweb APIをpython で作る案件で
古きVM構成と冗⻑とローカリティ • Python flask(rest API) + celery + redis +
mongodb構成 • 低コスト(3 VM : node)で冗⻑性について考えてみる • redis : Celeryのbroker store (MQ) • mongodb : APIの処理の結果を永続保存 • flaskでのrest APIをceleryでfront(API) + celery(worker)に分離する • node A : • node B : どうはいちする? • node C : • docker/container じゃない
その時のredisについて考える • Redis 3.0から : Redis clusterにてmulti-master対応 • è 普通にmult-masterならとくに問題ない
• 2020/10⽉ぐらい • è Redis 6.0 branch (v5.9.103) 以降 redis6 multithread I/Oが⼊ってきている その少し前 • redis 5X時のゴタゴタ • バンドの⽅向性の違い è MultiThreadの実装の⽅向性
redis v5.x後半のゴタゴタとは • CPU Coreあたりの処理能⼒が上限になりつつあった2019年 • クロックはあまり上がらず、Core数が増える時代 • Intel より
AMD がマルチ・ダイでマルチコアの効率化 • その時のredisの⽅向性 • redis clusterでshardして、処理インスタンスあたりのCore割当を分散 する • è shardするover headも⼤きい • KeyDBを考えた⼈たち • è そんなことより、単⼀インスタンスあたりの性能をマルチスレッド 化で ⾼めて、shardなんて複雑化しないでover head減らそう
⽅向性の違い è fork : KeyDB 5.x Faster : 5倍 早いだとぉぉ
(当時) Oct. 2019 : Redis v5.0.9⽐較
None
None
今のKeyDB and Redis • Redis 6.2.x (latest) • 結局はmultithread I/O
を受け⼊れる • default 1 thread • CONF: io-threads {INT} • CPU Core数 ‒ 1 と⼿動設定 • KeyDB 6.0.16 (latest) : 設定細かい • 標準thread対応 • default 1 thread • CONF: server-threads {INT} ## 2とかにすると良い CONF: server-thread-affinity true ## なるべくCPUpinする(defautl)
benchmark取るときには、設 定もチューニング必要 ゆっくり考えてね
で、結局どうしたのか : KeyDB node C node B node A keydb
keydb keydb py py mongod arbiter mongod primary mongod secondary • KeyDB multi-master è 普通に使えますね • Pythonからは、localhostでアクセス • KVSとしてはデータローカリティ • haproxyはtcp socketでprimary判定check haproxy haproxy haproxy haproxy haproxy 192.168.1.5 192.168.1.6 192.168.1.7
たまには良いけど、アプリ ケーションサービスのメッ シュを⼿動で組むとか今どき じゃないね 皆さんは、dockerなり、kubernetesとか使いましょう haproxyいれて、⼿動でメッシュしても、きっとどこか抜けている!!
KeyDB multi-master (example • /etc/keydb/keydb.conf 変更点 (node A : 192.168.1.5)
replica-read-only no ## yes を noに変更 cluster-node-timeout 5000 ## peerが切れたら諦めろ multi-master yes active-replica yes replicaof 192.168.1.6 6379 ## node B peer replicaof 192.168.1.7 6379 ## node C peer • node B, node Cはpeer nodeのIPを書き換えておく
KeyDB multi master start • あとは起動 • # systemctl enable
keydb • # systemctl start keydb
status • # systemctl status keydb • • keydb.service -
Advanced key-value store • Loaded: loaded (/usr/lib/systemd/system/keydb.service; enabled; vendor preset: disabled) • Drop-In: /etc/systemd/system/keydb.service.d • └─limit.conf • Active: active (running) since ⼟ 2021-04-17 00:27:21 UTC; 6s ago • Docs: https://docs.keydb.dev, • man:keydb-server(1) • Process: 11922 ExecStart=/usr/bin/keydb-server /etc/keydb/keydb.conf (code=exited, status=0/SUCCESS) • Main PID: 11927 (keydb-server) • CGroup: /system.slice/keydb.service • └─11927 /usr/bin/keydb-server 0.0.0.0:16379 • 4⽉ 17 00:27:21 iso-man11012.g1.tyo1.v4.internal-gmo systemd[1]: Starting Advanced key-value store... • 4⽉ 17 00:27:21 iso-man11012.g1.tyo1.v4.internal-gmo systemd[1]: PID file /var/run/keydb/keydb-server.pid not readable (yet?) after start. • 4⽉ 17 00:27:21 iso-man11012.g1.tyo1.v4.internal-gmo systemd[1]: Started Advanced key-value store.
KeyDB 失敗談 • KeyDBでclusterで⾏こうとしたけど、失敗 • keydb-cli --cluster create \ 192.168.1.5:6379
\ 192.168.1.6:6379 \ 192.168.1.7:6379 --cluster-replicas 1 • replica 1だと、6 node(or instance)必要
node A write / read node A # keydb-cli -p
16379 Message of the day: Join the KeyDB community! https://community.keydb.dev/ 127.0.0.1:6379> set k2 2 OK 127.0.0.1:6379> get k2 "2" 127.0.0.1:6379> exit
node B read node B check # keydb-cli -h 192.168.1.6
-p 6379 Message of the day: Join the KeyDB community! https://community.keydb.dev/ 192.168.1.6 :6379> get k2 "2" 192.168.1.6 :6379> exit
node C read node C check # keydb-cli -h 192.168.1.7
-p 6379 Message of the day: Join the KeyDB community! https://community.keydb.dev/ 192.168.1.7 :6379> get k2 "2" 192.168.1.7 :6379> exit
KeyDB普通に使えるね by multi-master Operationはredisと同じ、 Configは違いもあるけど、楽な点も多い
benchmarkについては、 今回の⽤途では頑張る必要なし • まとめ • 冗⻑でローカリティアクセスのredisをKeyDB multi-masterでできた • cluster構成は3 nodeで失敗
(replica設定 1) è 6 node必要みたい • KeyDBかんたん、悪くないかも • reidis : BSD-3 or commercial license available • KeyDB : BSD-3 (community version and Enterprise version) • nodeごとに⼀回削除して、作り直してもすぐに復帰してた • コンテナの運⽤性も良さそうだ