<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="137586" data-post-id="137586">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="seb5law" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  seb5law
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a class="mention" href="/u/dch" rel="nofollow">@dch</a> Do you have an explanation, for the very similar performance of your big and fast machine compared to my medium sized laptop? I would expect your storage to be much faster than my ‘normal’ SSDs.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="137586" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/cubdb-a-pure-elixir-embedded-key-value-database/23397/42">Post #41</a>
	                </div>
	            </div>
              <div id="likers-container-137586" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="137586"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #41"></div>
  </section>
</div>
    <div class="postbit" id="137604" data-post-id="137604">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="dch" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/dch/120/2682_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  dch
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<blockquote>
<p>seb5law <a href="https://forum.elixirforum.com/u/seb5law" rel="nofollow">https://forum.elixirforum.com/u/seb5law</a><br>
July 24<br>
<span class="mention">@skunkwerks</span> <a href="https://forum.elixirforum.com/u/skunkwerks" rel="nofollow">https://forum.elixirforum.com/u/skunkwerks</a> Do you have an<br>
explanation, for the very similar performance of your big and fast<br>
machine compared to my medium sized laptop? I would expect your storage</p>
</blockquote>
<p>The short answer is that the test isn’t fully i/o bound, and it’s using a single<br>
path both for storage &amp; cpu, so we are not really stretching any of the<br>
components. If this were running 20 or more io schedulers each doing<br>
real work, the difference would start to show much much more.</p>
<p>It’s possible your laptop has an NVMe drive in it too, and definitely with<br>
2 or 4 PCI paths for IO even if it’s an SSD.</p>
<p>For a single thread BEAM app writing to a single file, a large fast machine<br>
will not show significant different than a smaller one - they’re both PCI<br>
devices writing to broadly similar storage**, with broadly similar CPUs.</p>
<p>Now, if you try to write several thousand threads with concurrent I/O this<br>
starts to show a difference - the drive is better, and the PCI bus has significantly<br>
more channels, and your laptop will hit the wall much earlier.</p>
<p>The other interesting thing is that long IOs cause NVMe drive to get<br>
noticeably hotter. The CubDB tests are not enough to make the drive<br>
throttle for this, but if you leave it running for a couple of hours, you can<br>
expect to see a significant difference as your drive gives up and reduces<br>
its bandwidth to avoid overheating.</p>
<p>This will also show up on shorter tests with increased spread and divergent<br>
percentiles.</p>
<p>A while ago I benchmarked a single dd process both on my laptop &amp; my server,<br>
and sure enough there is very little difference. Where things change is using<br>
multiple dd processes, as high end NVMe drives can have 1000s of parallel<br>
IO queues underway without breaking a sweat.</p>
<p>Indeed just reading off a 60GiB swap partition on the NVMe drive, I get 2x<br>
the throughput as the laptop, and it can sustain this all day, as opposed<br>
for a minutes or two with the laptop.</p>
<p>Raw notes here <a href="https://gist.github.com/dch/890ec336875663349a02cbe0b9b19171" class="inline-onebox" rel="noopener nofollow ugc">This nvme drive does (in real-world terms) ~ 1400GiB/hr streaming reads from a zpool under FreeBSD 12.0p2 amd64 after a couple of years of sustained abuse. · GitHub</a><br>
I did plan to turn it into a blog post at some point, but it needs a bit more<br>
filler info. The above data is also just raw disk throughput, when using<br>
a filesystem like zfs on top, it’s a much more complicated picture.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="137604" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/cubdb-a-pure-elixir-embedded-key-value-database/23397/43">Post #42</a>
	                </div>
	            </div>
              <div id="likers-container-137604" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="137604"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #42"></div>
  </section>
</div>
    <div class="postbit" id="137607" data-post-id="137607">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lucaong" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lucaong/120/21794_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lucaong
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Yes, what <a class="mention" href="/u/dch" rel="nofollow">@dch</a> wrote sounds 100% correct to me. Also, the current benchmarks perform operations serially, not concurrently. Benchmarks of bulk writes and concurrent operations might show a more visible difference. I will add some.</p>
<p>In general, the fact that <code>CubDB</code> is written in pure Elixir, with no dependency, has advantages on the side of convenience and support of any Elixir-capable target, but makes it harder to saturate resources.</p>
<p>In general, <code>CubDB</code> main goals are ease of use from Elixir/Erlang, and data integrity. I am happy to optimize performance as long as it does not impact negatively the other goals. If one cares primarily about raw performance, general purpose C/C++ k/v stores like LMDB or LevelDB are probably a better choice. That said, there are likely still many low-hanging fruits to improve performance of <code>CubDB</code>.</p>
<p>Also consider that, when settings the strictest durability guarantees (<code>auto_file_sync: true</code> in <code>CubDB</code> and equivalent options in SQLite, LMDB, LevelDB, etc.), all stores would perform quite similarly and much slower than the theoretical limit shown in popular benchmarks, far from saturating IO anyway. In that (quite common) use case, ease of use would be, in my opinion, more important than shaving off a few percentage points in performance.</p>
<p>As a final note, thanks a lot people for the interest and for posting your insights and benchmarks! I am quite sure that, with your help, there are lots of opportunities for improving <code>CubDB</code> and make it one more nice entry in the Elixir toolbox <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="137607" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/cubdb-a-pure-elixir-embedded-key-value-database/23397/44">Post #43</a>
	                </div>
	            </div>
              <div id="likers-container-137607" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="137607"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #43"></div>
  </section>
</div>
    <div class="postbit" id="137728" data-post-id="137728">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Qqwy" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Qqwy/120/1349_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Qqwy
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>TypeCheck Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi!</p>
<p>I have two small questions on how to best use CubDB:</p>
<ol>
<li>If you have two different kinds of data, does it make more sense to open two separate DB processes (pointing to different directories), or just use a single one and distinguish data by their IDs (and when <code>select</code>ing, applying the appropriate <code>filter:</code>?)</li>
<li>Is it possible to (lazily) stream responses from a <code>select</code>?</li>
</ol> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="137728" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/cubdb-a-pure-elixir-embedded-key-value-database/23397/45">Post #44</a>
	                </div>
	            </div>
              <div id="likers-container-137728" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="137728"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #44"></div>
  </section>
</div>
    <div class="postbit" id="137735" data-post-id="137735">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lucaong" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lucaong/120/21794_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lucaong
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi <a class="mention" href="/u/qqwy" rel="nofollow">@Qqwy</a>,<br>
thanks a lot for your questions, as they give me an opportunity to mention a few possibilities with <code>CubDB</code> <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<aside class="quote no-group" data-username="Qqwy" data-post="45" data-topic="23397">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/qqwy/48/1349_2.png" class="avatar"> Qqwy:</div>
<blockquote>
<ol>
<li>If you have two different kinds of data, does it make more sense to open two separate DB processes (pointing to different directories), or just use a single one and distinguish data by their IDs (and when <code>select</code> ing, applying the appropriate <code>filter:</code> ?)</li>
</ol>
</blockquote>
</aside>
<p>The best is usually to use the same database, and leverage on the fact that keys can be any term. This way, you can have transactions across different kinds of data.</p>
<p>Suppose that I want to have two different kinds of data, <code>users</code> and <code>messages</code> for example. In a relational DB one would create two tables.</p>
<p>In <code>CubDB</code>, a great way to do that is to structure the keys as <code>{:users, user_id}</code> for users and <code>{:messages, message_id}</code> for messages:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">user = %User{
  id: 123,
  name: "Margaret",
  employer: "NASA"
}
CubDB.put(db, {:users, user.id}, user)

message = %Message{
  id: 46,
  subject: "The Eagle has landed",
  text: "Tranquillity base here..."
}
CubDB.put(db, {:messages, message.id}, message)
</code></pre>
<p>Now, here is how you can query them, leveraging on erlang term sorting:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir"># Get a specific user with id = 123
CubDB.get(db, {:users, 123})
#=&gt; %User{ id: 123, ... }

# Select all users (this works because tuples in Erlang/Elixir are
# compared element by element, nil is smaller than any map, and
# bigger tuples are greater than smaller ones):
CubDB.select(db, [
  min_key: {:users, nil},
  max_key: {:users, nil, nil}
])

# Select the first 30 messages, with id &gt; 10:
CubDB.select(db, [
  min_key: {:messages, 10},
  max_key: {:messages, 10, nil},
  pipe: [{ take: 30 }]
])
</code></pre>
<p>That is also much faster than using <code>:filter</code>, because <code>:min_key</code> and <code>:max_key</code> avoid loading unnecessary entries from disk entirely. You can of course combine it with a filter, if you want to apply further restrictions that cannot be expressed by <code>:min_key</code>/<code>:max_key</code> (e.g. only take messages matching a certain subject).</p>
<aside class="quote no-group" data-username="Qqwy" data-post="45" data-topic="23397">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/qqwy/48/1349_2.png" class="avatar"> Qqwy:</div>
<blockquote>
<ol start="2">
<li>Is it possible to (lazily) stream responses from a <code>select</code> ?</li>
</ol>
</blockquote>
</aside>
<p>Yes <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"> When you use <code>select/3</code> with the <code>:pipe</code> option, the entries are in fact lazily streamed through the pipeline operations:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">CubDB.select(db, [
  min_key: {:messages, 10},
  max_key: {:messages, 10, nil},
  pipe: [
    filter: fn {_key, %Message{ subject: subject }} -&gt;
      String.contains?(subject, ["error", "1202"])
    end,
    map: fn {_key, %Message{ subject: subject }} -&gt;
      subject
    end
  ]
])
</code></pre>
<p>You might wonder why <code>select/3</code> does not simply return a lazy stream. The reason is that, internally, <code>CubDB</code> has to keep track of all open readers and the data file that they reference. Upon a compaction operation, a new compacted data file is created, and the old one is only removed after no reader is referencing it anymore. This way, readers can safely operate concurrently with other readers, writers, and compactions, with none being blocked.</p>
<p>Using the <code>:pipe</code> options, <code>select/3</code> takes care of the bookkeeping for you. If it gave direct access to the stream, you would have to manually “checkout” the reader after you are done using it, also in case of an exception, etc.</p>
<p>I hope this explains it well, and gives you some tools to model your case.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="137735" data-batch-url="/posts/batch_likers">
                        4
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/cubdb-a-pure-elixir-embedded-key-value-database/23397/46">Post #45</a>
	                </div>
	            </div>
              <div id="likers-container-137735" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="137735"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #45"></div>
  </section>
</div>
    <div class="postbit" id="138305" data-post-id="138305">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Qqwy" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Qqwy/120/1349_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Qqwy
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>TypeCheck Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I want to take the time to thank you for your very insightful post!</p>
<p>I am now a couple of days down the road, and I have used CubDB in the ways you suggested: Having one database  containing multiple datastructures so they can be used transactionally across different kinds of data, and I use the <code>min_key</code>/<code>max_key</code> tips you suggest <img src="https://forum.elixirforum.com/images/emoji/apple/smile.png?v=15" title=":smile:" class="emoji" alt=":smile:" loading="lazy" width="20" height="20">.</p>
<p>Also, kudos for the way you run streams over the selected records <img src="https://forum.elixirforum.com/images/emoji/apple/+1.png?v=15" title=":+1:" class="emoji" alt=":+1:" loading="lazy" width="20" height="20">. The code looks very clean, and I am very happy that memory usage while running a <code>select</code> with a reducer is essentially constant (rather than reading in all records before doing something with them).</p>
<hr>
<p>I now do came across a bit of an issue. I am using CubDB on my Nerves device, but it seems that not all data is properly kept track of, and some data is lost during reboots:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">iex&gt; CubDB.select(MyApp.DB, reduce: {0, fn x, acc -&gt; acc + 1 end})
{:ok, 3543}
iex&gt;  Toolshed.Nerves.reboot
# Wait for Nerves to restart and come back up
iex&gt; CubDB.select(MyApp.DB, reduce: {0, fn x, acc -&gt; acc + 1 end})
{:ok, 1871}
</code></pre>
<p>It seems like many records are lost. What is going on here?</p>
<p>The database server is started as follows, and is part of my supervision tree:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">CubDB.start_link("/root/data/my_db", [auto_file_sync: true, auto_compact: true], [name: MyApp.DB])
</code></pre>
<p>(Or to be exact, the app contains a module which has the following child_spec definition to allow it to be added to the supervisor using just <code>MyApp.DB</code>:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule MyApp.DB do
  def child_spec(_) do
    %{id: __MODULE__, start: {CubDB, :start_link, [Application.get_env(:my_app, :my_db_location, "data/my_db"), [auto_file_sync: true, auto_compact: true], [name: __MODULE__]]}}
  end

  # ... some other helper methods that use CubDB.get/fetch/put under the hood.

end
</code></pre>
<p>)</p>
<p><em><strong>EDIT</strong>: This particular code snippet is outdated as newer versions of CubDB expect different arguments to <code>start_link</code>. <a href="https://forum.elixirforum.com/t/cubdb-a-pure-elixir-embedded-key-value-database/23397/78" rel="nofollow">@BrightEyesDavid posted an updated snippet below</a>.</em></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="138305" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/cubdb-a-pure-elixir-embedded-key-value-database/23397/47">Post #46</a>
	                </div>
	            </div>
              <div id="likers-container-138305" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="138305"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #46"></div>
  </section>
</div>
    <div class="postbit" id="138307" data-post-id="138307">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lucaong" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lucaong/120/21794_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lucaong
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi <a class="mention" href="/u/qqwy" rel="nofollow">@Qqwy</a>,<br>
Thanks a lot for reporting this. It sounds like a serious issue, and one that I didn’t encounter yet. It looks especially strange given that you are already using auto file sync.</p>
<p>Could you provide any more input, e.g. on how you fill up the db? If you manage to have a reproducible setup, I’ll pick it up from there and make sure to fix it before <code>v1.0</code>.</p>
<p>Also, does it make any difference if you call `CubDB.file_sync(db) before restarting? This one test is to check if maybe there is a bug in the auto sync logic.</p>
<p>Thanks a lot</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="138307" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/cubdb-a-pure-elixir-embedded-key-value-database/23397/48">Post #47</a>
	                </div>
	            </div>
              <div id="likers-container-138307" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="138307"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #47"></div>
  </section>
</div>
    <div class="postbit" id="138309" data-post-id="138309">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lucaong" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lucaong/120/21794_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lucaong
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Also, is it possible that some write or delete operation completes after the last select? Writes and reads do not block each other, so a select sees an immutable snapshot of the db at the moment that the operation started. If a write is performed concurrently, it won’t be visible by that select.</p>
<p>Sounds unlikely in your case, but I am trying to narrow down the possibilities.</p>
<p>Another useful test would be to disable the auto compaction, to see if that’s what’s causing the issue.</p>
<p>Thanks a lot for helping on this.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="138309" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/cubdb-a-pure-elixir-embedded-key-value-database/23397/49">Post #48</a>
	                </div>
	            </div>
              <div id="likers-container-138309" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="138309"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #48"></div>
  </section>
</div>
    <div class="postbit" id="138406" data-post-id="138406">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="Qqwy" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/Qqwy/120/1349_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  Qqwy
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>TypeCheck Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>It might be that this behaviour happens especially because it is running on an embedded device. One of the things I will try to find out to make it easier to investigate this issue, is what size Nerves’ read/write partition has by default, and what happens if it were to get full.</p>
<p>How much is the overhead of CubDB’s internal tree structure?</p>
<p>I will try out if disabling the auto compaction helps, and I’ll build and share a minimal example that has the same behaviour as my real application (whose source I unfortunately cannot share).</p>
<p>In this case, I am saving a new value, which is an Elixir struct with about eight keys, containing some integers, strings and floats, under the key <code>{:telegram "some_timestamp"}</code> (where <code>some_timestamp</code> has the format  <code>"YYYYMMDDHHmmss"</code>).</p>
<p>Thank you very much for your responses <img src="https://forum.elixirforum.com/images/emoji/apple/+1.png?v=15" title=":+1:" class="emoji" alt=":+1:" loading="lazy" width="20" height="20">.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="138406" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/cubdb-a-pure-elixir-embedded-key-value-database/23397/50">Post #49</a>
	                </div>
	            </div>
              <div id="likers-container-138406" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="138406"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #49"></div>
  </section>
</div>
    <div class="postbit" id="138416" data-post-id="138416">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="lucaong" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/lucaong/120/21794_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  lucaong
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>If the entries are small, the biggest overhead is due to the fact that headers are written only at page boundaries, so each write will take a minimum of 1024 bytes before compaction (each atomic operation writes a header).</p>
<p>Embedded device, and especially Nerves, are one of the primary targets of CubDB (and the initial motivation for the project), so I am especially interested in investigating possible bugs there.</p>
<p>I will soon setup a test device on a Rpi to exercise extensively conditions like sudden loss of power.</p>
<p>I am still puzzled by the issue you are facing, as I never encountered in automated tests nor in deployed Nerves devices. Any further insight you might discover is very valuable for me.</p>
<p>Thanks a lot for dedicating time to this!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="138416" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/cubdb-a-pure-elixir-embedded-key-value-database/23397/51">Post #50</a>
	                </div>
	            </div>
              <div id="likers-container-138416" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="138416"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #50"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/23397/load_more?page=6">Load more posts (74 remaining)</a>
</div></template></turbo-stream>