tduccuong

tduccuong

Realtime status on CubDB compaction process?

Hi @lucaong,

first, thanks a lot for the great library. I am using CubDB as embedded DB for my project. The service runs on an SD-card based Pi node that continuously writes lots of log lines into CubDB. To protect the SD card, I create a RAM disk to host the CubDB file. Periodically (every 2 hours), I backup the RAM disk content to a persistent folder on SD. Next time the service starts, it copy the content of that folder to the RAM disk.

My question is whether this approach makes sense for CubDB? If it does, can I query CubDB to know if it is currently doing compaction, so I can wait till it is done to avoid backing up a half-done DB file?

Thanks a lot!

Marked As Solved

tduccuong

tduccuong

Thanks for the clarification @garrison, the reason I don’t use regular log file + rotation, is because I need to also frequently query the logs based on timestamp and certain metadata. CubDB provides good trade off for that, only the problem of disk wear. But also, at some point in time, the DB can grows larger than RAM.

So I guess the best trade off now that I can do is to buffer write for CubDB with relatively long flush to DB interval (via CubDB.put_multi/2).

Also Liked

lucaong

lucaong

Hi @tduccuong , thanks for the kind words :slight_smile:

My question is whether this approach makes sense for CubDB?

I don’t see problems with your approach, but it could be simpler. If you use a RAM disk, you probably do not need complete durability in case of a restart, and you are ok loosing very recent logs (after the most recent disk copy). In that case, you could do without a RAM disk, and simply use the option auto_file_sync: false. This will avoid flushing buffers to disk for each transaction, and instead let the OS control the flush to disk. You can also explicitly call CubDb.file_sync(pid) periodically to force a flush. In all likelihood this would cause disk writes more frequently than every 2 hours though, so if that’s a problem you might still follow your approach.

You can check if there is an ongoing compaction by calling CubDB.compacting?(pid), or you can disable auto compaction completely with the auto_compact: false option, and force a compaction manually when you see fit, with CubDB.compact(pid). The latter option can be especially useful if you have “quiet times” when you can perform a large compaction, and “busy times” when you prefer not to add overhead. Delaying a compaction won’t affect read or write performance, and will simply cause the database file to be larger than it could. Compactions are also more efficient during quiet times, when the database does not need to catch up on writes that happen after compaction is started.

I hope this helps :slight_smile:

tduccuong

tduccuong

Never mind my last question, I got the answer after going through your code base. I think my approach now is:

  • auto_file_sync = false
  • Build a BTree in memory as buffer, that exposes same API as CubDB (put/2, put_multi/2) for client code
  • Periodically flush the BTree to disk via CubDB.put_multi/2

Do you think this helps protect the SD card better?

Thanks for your help!

lucaong

lucaong

Consider that CubDB is already structured as an append-only btree, so at the file level writes are always appended (even in case of an update or a deletion). Therefore, the write characteristics are very similar to a plain log file, but with the added ability to perform point and range queries efficiently.

What’s the expected write volume in terms of entries per unit of time? Depending on it, it might be worth using CubDB straight away, with the options discussed above.

Where Next?

Popular in Questions Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement