Badger: How to use badger without Persistent ? only in ":memory:"

Created on 26 Dec 2017  Â·  7Comments  Â·  Source: dgraph-io/badger

I want to use badgerdb for chat application with multiple room options. I want to store all chat in badgerdb, I want to ask the badgerdb team, is badgerdb right choice for chat message app?

Also, as stated in example README file, it stores code in same file, but I want to store them in memory without persistence.

opts := badger.DefaultOptions
  opts.Dir = "/tmp/badger"
  opts.ValueDir = "/tmp/badger"
  db, err := badger.Open(opts)

Is there any option, where we can set option to store data in ":memory:" and not in file.

kinquestion

All 7 comments

@rebootcode Badger is designed to support high throughput writes and reads with persistence in mind. If you want to store the data in memory without persistence you might want to look for other alternatives.
Else you can also try badger with sync writes set to false in option, it would give you better performance and also persist the data in async way.

You could also use tmpfs to store data. That would give you fast storage.

Sent from Nexus 6P

On Dec 27, 2017 9:52 AM, "Janardhan Reddy" notifications@github.com wrote:

@rebootcode https://github.com/rebootcode Badger is designed to support
high throughput writes and reads with persistence in mind. If you want to
store the data in memory without persistence you might want to look for
other alternatives.
Else you can also try badger with sync writes set to false in option, it
would give you better performance and also persist the data in async way.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/dgraph-io/badger/issues/377#issuecomment-354022015,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABsyNJWY3-sb6WPPyAsTH98GkdQWOw2Qks5tEXi-gaJpZM4RMuPL
.

@janardhan1993 and @manishrjain - I would like to verify below settings as recommended above :-

opts := badger.DefaultOptions
opts.Dir = "/tmp/badger"   // tmp directory as recommended
opts.ValueDir = "/tmp/badger"
opts.SyncWrites = false   // sync write to false as recommended
db, err := badger.Open(opts)

Thanks

Looks good.

One handy reason to support in-memory storage (or something like a memory-backed os.FS) is that it makes writing tests with throw-away data much more convenient without thrashing the disk unnecessarily. :)

You can set TableLoadingMode = options.LoadToRAM, which would still give you the durability, without compromising on read performance. I'd also recommend using LSMOnlyOption (instead of Default), and setting ValueLogLoadingMode to at least options.MemoryMap (or even options.LoadToRAM if you have the memory available for it).

@manishrjain thanks for the tip!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

whyrusleeping picture whyrusleeping  Â·  8Comments

JeanMertz picture JeanMertz  Â·  7Comments

jackmiller334 picture jackmiller334  Â·  7Comments

brk0v picture brk0v  Â·  7Comments

deepakjois picture deepakjois  Â·  7Comments