# Basic Record Layer query performance and caching strategies

**URL:** <https://forums.foundationdb.org/t/basic-record-layer-query-performance-and-caching-strategies/1801>\
**Category:** Record Layer\
**Created:** [December 3, 2019, 6:37pm UTC](https://forums.foundationdb.org/t/basic-record-layer-query-performance-and-caching-strategies/1801 "2019-12-03T18:37:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![max](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/max/32/585_2.png) [@max](https://forums.foundationdb.org/u/max)\
**Post date:** [December 3, 2019, 6:37pm UTC](https://forums.foundationdb.org/t/basic-record-layer-query-performance-and-caching-strategies/1801/1 "2019-12-03T18:37:24Z")

</div>

In getting up and running I’m seeing basic queries (inserts/lookups/queries) take about 30ms. I think this is an issue with the way I’m reusing (or failing to re-use) the instantiated recordStore instance. I’ve roughly followed the steps from the GettingStarted.md tutorial and I’m starting my queries like so:

```
FDBRecordStore.newBuilder()
    .setMetaDataProvider(recordMetaData)
    .setContext(context)
    .setKeySpacePath(path)
    .createOrOpen();

```

This call alone seems to take ~7ms or so. From the tutorial the “The `FDBRecordStore` object only has the lifetime of a single transaction”. Is it possible to cache some or all of this instantiation to reuse between transactions? Is there possibly something else wrong with my setup (I’m using a local development foundationdb instance)? Any general guidance around what kind of latency I should be expecting from simple queries?

---

<div class="post-metadata">

**Author:** ![max](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/max/32/585_2.png) [@max](https://forums.foundationdb.org/u/max)\
**Post date:** [December 3, 2019, 6:46pm UTC](https://forums.foundationdb.org/t/basic-record-layer-query-performance-and-caching-strategies/1801/2 "2019-12-03T18:46:15Z")

</div>

It seems I might have just missed `FDBRecordStoreStateCache` and the related methods. Would be great to get confirmation that that should handle most of my caching needs.

---

<div class="post-metadata">

**Author:** ![max](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/max/32/585_2.png) [@max](https://forums.foundationdb.org/u/max)\
**Post date:** [December 4, 2019, 1:14am UTC](https://forums.foundationdb.org/t/basic-record-layer-query-performance-and-caching-strategies/1801/3 "2019-12-04T01:14:12Z")

</div>

Hmm, it seems that even when enabling the cache (and seeing a cache hit) I’m still seeing similar delays.

---

<div class="post-metadata">

**Author:** ![max](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/max/32/585_2.png) [@max](https://forums.foundationdb.org/u/max)\
**Post date:** [December 4, 2019, 5:41pm UTC](https://forums.foundationdb.org/t/basic-record-layer-query-performance-and-caching-strategies/1801/4 "2019-12-04T17:41:55Z")

</div>

agh, ok, I take it all back. if I run it outside of Docker For Mac all the numbers drop to low single digit ms. seems this is just an issue with running everything in a constrained vm

---

<div class="post-metadata">

**Author:** ![alloc](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/alloc/32/9_2.png) [@alloc](https://forums.foundationdb.org/u/alloc)\
**Post date:** [December 6, 2019, 4:37pm UTC](https://forums.foundationdb.org/t/basic-record-layer-query-performance-and-caching-strategies/1801/5 "2019-12-06T16:37:59Z")

</div>

Ah, glad you were able to figure it out!

The other somewhat confusing thing about the `MetaDataVersionStampStoreStateCache` is that you have to set the option in the store header to make the meta-data cacheable, but if you saw a cache hit, then that worked. (But just posting here because others might run into a similar issue.)
