Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
LevelDB on S3 As A KVS
Search
shunsukeaihara
June 02, 2015
Programming
3k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
LevelDB on S3 As A KVS
shunsukeaihara
June 02, 2015
More Decks by shunsukeaihara
See All by shunsukeaihara
BONXを支える技術:発話区間検出(VAD)の話/Akerun & BONX Tech Talk
shunsukeaihara
4
7.8k
Goのnet.TCPConnの話/shibuya.go01
shunsukeaihara
3
890
Norikra in Gunosy Network Ads@Norikra meetup #2
shunsukeaihara
1
6.1k
色恒常性仮説に基づく色補正ライブラリcolorcorrect / 2015-01-31-kantocv27
shunsukeaihara
3
2.6k
Sparkによる分散処理 / 2015-01-16 PyData.Tokyo#3
shunsukeaihara
11
3.6k
ゼロから始めた Gunosyアドサーバ開発運用記 / 2014-12-16-dots
shunsukeaihara
6
1.2k
Gunosy.Go#5 index/io/log
shunsukeaihara
0
200
Gunosy.go#2 package/compress
shunsukeaihara
0
150
Other Decks in Programming
See All in Programming
新卒PdEのリアル
ryu1013
1
520
Snowflakeで業務アプリを作ろう。 Snowflakeのアプリ機能解説&実践ガイド
ayumu_yamaguchi
2
300
Webの地図
yosuke_furukawa
PRO
6
4.8k
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
4
3.9k
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
110
難しいけど、読めた。- OSSの入口に立った話。
sts11142
0
120
JPUG勉強会 OSSデータベースの内部構造を理解しよう(第2回)
oga5
0
270
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
370
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
3.7k
カツオ、ご期待ください
suneo3476
0
100
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
680
巨大モノリシックアプリ モダン化大作戦
ktcryomm
1
1.1k
Featured
See All Featured
The Limits of Empathy - UXLibs8
cassininazir
1
690
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
530
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
920
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
280
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
Leo the Paperboy
mayatellez
10
2.3k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
370
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
The Curse of the Amulet
leimatthew05
3
15k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
540
Transcript
LevelDB'on'S3'As'A'KVS
Who$am$I • Shunsuke)Aihara(@shunsukeaihara) • ΞυͬͯΔ • ܭࢉݴޠֶ • ը૾ॲཧɾԻॲཧɾݴޠॲཧͷϥΠ ϒϥϦ͍Ζ͍Ζॻ͍ͯΔ
• h1ps:/ /bitbucket.org/aihara
ΞυαʔόΛϦϓϨΠεͨ͠ • Python(tornado)͔Βgo.+.kamiʹॻ͖͑ • όουϊϋΛ՚ྷʹશճආ
50ms%or%DieΛ્Ήͷ 1. Redis 2. Redis 3. Redis 4. GIL 5.
etc
ՄೳͳݶΓڞ༗DBΛ৮Βͳ͍ ΫϥελͷϝϯςͭΒ͍ RedisγϯάϧεϨου
ΞυḉͰRDB৮ΔౕԿΛͬͯμϝ
AWSͰҰ൪҆ఆ͍ͯ҆͠ࢄDB?
S3
S3ͷ͍υίϩ • S3Λͦͷ··KVSͱͯ͠͏ • ผͷαʔϏεͰ࣮ࢪ&/&݁ߏεέʔϧ • shard&keyͱ͔ࢦఆͰ͖Δ͚ͲΞυαʔόͰϨΠςϯγͷ ͕ • S3্ʹϑΝΠϧDBΛஔ
• ϑΝΠϧDBΛόϥϚΩ
LevelDBΛS3ʹஔ • Norikra(+(Redshi/(+(PythonΫϥελͰ౷ܭใɺλʔήςΟ ϯάใΛ͍ΖΜͳϥΠϑαΠΫϧͰߋ৽ • MessagepackܗࣜͰɺLevelDBʹ์ΓࠐΉ • h=ps:/ /github.com/shunsukeaihara/goDleveldbDobjectstorage/ •
֎෦ެ։൛
goଆ࣮ • golevelΛར༻ • ىಈ࣌ʹLevelDBΛμϯϩʔυ • λΠϚʔͰఆظతʹ࠶μϯϩʔυ • ҰͭͷLevelDBϑΝΠϧͷΞΫηεҰͭͷGorou-neͰ •
ϑΝΠϧͷચ͍ସ͑ͳΜ͔ಛʹؾʹ͠ͳ͍
CommandύλʔϯͬΆ͍࣮ • get(unpack)/set/expireͱ͔ • ΑΓChannelΛ༻͍ͨՄಡੑΛ • MessagepackΛUnpackͨ͠σʔλΦϯϝϞϦͰΩϟογϡ • RedisͬΆ͍ExpireΛ࣮ •
Expire:merͱChannelͰ࣮
gcTick := time.NewTicker(10 * time.Second) defer gcTick.Stop() updateTick := time.NewTicker(time.Duration(ldb.dbConf.Options.UpdateInterval)
* time.Second) defer updateTick.Stop() for { select { case cmd := <-ldb.get: cmd.result <- ldb.execGet(cmd) case <-ldb.reset: ldb.cache = map[string]*cachedItem{} case <-updateTick.C: ldb.mu.RLock() if !ldb.downloading { go ldb.download(ctx, true) } ldb.mu.RUnlock() case msg := <-ldb.switchDB: oldDB := ldb.db oldPath := ldb.dbpath ldb.db = msg.db ldb.dbpath = msg.dbpath oldDB.Close() os.RemoveAll(oldPath) case <-ldb.expire: ldb.simpleExpire(1) case <-gcTick.C: ldb.simpleExpire(1) case msg := <-ldb.exit: ldb.db.Close() os.RemoveAll(ldb.dbpath) ldb.cache = map[string]*cachedItem{} msg <- struct{}{} break } }
IFͱ͔ • ςΩτʹΦϨΦϨDSL͔ΒδΣωͬͯΔ func GetCandidate(ctx context.Context, key string) ([]*data.Candidate, bool)
{ ldb, ok := levelDBFromContext(ctx, candidateDBKey) if !ok { panic("no candidate db in context") } res, ok, _ := ldb.getCandidate(key) return res, ok } func (ldb *LevelDB) getCandidate(key string) ([]*data.Candidate, bool, bool) { cmd := NewDBGetCmd(key, data.UnmarshalCandidates, int64(ldb.dbConf.Options.CacheExpire)) ldb.get <- cmd r := <-cmd.result if !r.ok { return nil, false, false } return r.val.([]*data.Candidate), r.ok, r.hit }
ͦΕͰRedisɾMemcache͕ඞཁͳॴ…… • Redisࣗମਨࢄ/ਫฏࢄ • RedisΫϥελʹରͯ͠LevelDBΞΫηεͱಉ༷ɺػೳຖʹ 1Goru2neΛׂΓͯ • MessagepackΛUnpackͨ͠σʔλΩϟογϡ • ͬͪ͜ʹRedisͬΆ͍expireઓུΛ࣮
݁Ռ • ςΩτʹॻ͍ͯेૣ͍ • PythonͰॻ͍͍ͯͨαʔόͷ8ഒͷεϧʔϓοτ • 10ms-or-Die͙Β͍ͷͰಈ࡞ • ܕ͕༗Δͷେخ͍͠ͱ͍͏ؾ࣋ͪ •
ίʔυҾ͖ܧ͗࣌ͷܕͷ͋Γ͕ͨ͞