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
Rでドレミ/Do-Re-Mi_with_R
florets1
0
130
Railsのためのパスキー実践入門 〜マルチテナントSaaSでの意思決定〜
utakaha
2
660
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
2
970
Simple Storage Service(S3) is not simple
iwatsukayura
0
290
npm との違いを手がかりにGo の依存管理を理解したい
optim
0
660
ジョジョの世界をXRで再現する
mofurune
0
170
Agentic Software Factoryに、すごく賢いIF文を。 / super smart IF statement into the Agentic Software Factory.
rkaga
8
2.2k
sbt 2.0: takeoff
eed3si9n
0
160
dotNET_vulnclicker_intro.pdf
deka_morita
0
140
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
750
Verilogで学ぶCPU自作入門
uyuki234
8
4.1k
ChromeでローカルLLM
ryu1013
0
140
Featured
See All Featured
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
410
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
520
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
520
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
450
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
850
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
330
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
460
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
1
280
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͙Β͍ͷͰಈ࡞ • ܕ͕༗Δͷେخ͍͠ͱ͍͏ؾ࣋ͪ •
ίʔυҾ͖ܧ͗࣌ͷܕͷ͋Γ͕ͨ͞