# Block cache size usage

**URL:** https://discuss.dgraph.io/t/block-cache-size-usage/710
**Category:** Users
**Created:** [August 22, 2016, 3:28pm UTC](https://discuss.dgraph.io/t/block-cache-size-usage/710 "2016-08-22T15:28:42Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![jchiu](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jchiu/32/301_2.png) [@jchiu](https://discuss.dgraph.io/u/jchiu)
#### Post date: [August 22, 2016, 3:28pm UTC](https://discuss.dgraph.io/t/block-cache-size-usage/710/1 "2016-08-22T15:28:42Z")

</div>

When I do table\_options.block\_cache-\>GetUsage() according to [this page](https://github.com/facebook/rocksdb/wiki/Memory-usage-in-RocksDB), I keep getting block\_cache being null (it is a shared pointer).

I then trace the cache constructors and destructors to [lru\_cache.cc](https://github.com/facebook/rocksdb/blob/72f8cc703ccf8a0d83041930cf8ce7645ac35ead/util/lru_cache.cc). With some printfs, what I find is that this object defined around [here](https://github.com/facebook/rocksdb/blob/e70020e4f64b7ce190006ab812a1371dbd690eea/include/rocksdb/table.h#L103) gets constructed and destroyed many times.

I am not sure if this is due to gorocksdb & garbage collection or everything is working as desired — the block cache is just a short-lived object.

I have run “dgraph” and “dgraphloader” and “dgraphassigner”.

In any case, according to [comments](https://github.com/facebook/rocksdb/blob/e70020e4f64b7ce190006ab812a1371dbd690eea/include/rocksdb/table.h#L102), and the [code](https://github.com/facebook/rocksdb/blob/e70020e4f64b7ce190006ab812a1371dbd690eea/table/block_based_table_factory.cc#L36), it seems that the size of the block cache is capped at 8M, which is tiny. I don’t think we should worry too much about it?

---

<div class="post-metadata">

### Author: ![pawan](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/pawan/32/1946_2.png) [@pawan](https://discuss.dgraph.io/u/pawan)
#### Post date: [August 23, 2016, 1:44am UTC](https://discuss.dgraph.io/t/block-cache-size-usage/710/2 "2016-08-23T01:44:32Z")

</div>

Good work with the 8MB finding @jchiu.

gotecbot has an [API](https://github.com/tecbot/gorocksdb/blob/master/options_block_based_table.go#L80) for setting BlockCache which has a default value of false. So maybe because it’s false, block cache isn’t even set?

---

<div class="post-metadata">

### Author: ![jchiu](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/jchiu/32/301_2.png) [@jchiu](https://discuss.dgraph.io/u/jchiu)
#### Post date: [August 23, 2016, 2:25am UTC](https://discuss.dgraph.io/t/block-cache-size-usage/710/3 "2016-08-23T02:25:58Z")

</div>

Thanks @pawan. I am experimenting with setting cache and compressed cache explicitly. But I am still getting cache usage = 0. But when I printf in Insert calls to cache (shard), usage is not zero. I am puzzled. Need more digging.

---

<div class="post-metadata">

### Author: ![mrjn](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/mrjn/32/775_2.png) [@mrjn](https://discuss.dgraph.io/u/mrjn)
#### Post date: [August 23, 2016, 12:03pm UTC](https://discuss.dgraph.io/t/block-cache-size-usage/710/4 "2016-08-23T12:03:59Z")

</div>

Based on [https://github.com/facebook/rocksdb/wiki/Memory-usage-in-RocksDB:](https://github.com/facebook/rocksdb/wiki/Memory-usage-in-RocksDB:)

So decreasing block cache doesn’t really increase the disk I/O. It only means more space for page cache – raw compressed blocks. For our purposes, the block cache isn’t that useful. Because when we read a posting list, we keep that in memory for a while. So, there’s no need to read the uncompressed value again from RocksDB for a while, because we already have that cached in Go space.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/2/2b38fdece2abe5814f2e51bee69d1e67fc304b0a.png) [@system](https://discuss.dgraph.io/u/system)
#### Post date: [November 28, 2017, 1:00am UTC](https://discuss.dgraph.io/t/block-cache-size-usage/710/5 "2017-11-28T01:00:33Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
