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

chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
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
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
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
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
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
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

We're in Beta

About us Mission Statement