Fork me on GitHub
#xtdb
<
2023-02-16
>
tatut05:02:33

we had an interesting bottleneck in a write heavy migration code: hikari pool acquire timeout when submitting tx, that’s simple enough to fix but I was wondering if metrics about that could be added to the metrics module easily

tatut05:02:12

looking inside the hikari jar it does seem to have coda hale metrics and prometheus metrics trackers, so I guess you can hook it

refset12:02:30

That's an interesting suggestion, and definitely sounds like something worth doing 👍 Would you like to open an issue to discuss/plan? (or I can if you'd prefer)

tatut13:02:21

I’ll open an issue

tatut05:02:31

also, how much do different queries use the doc store (instead of just data from local indexes), entity call at least does, does pull always?

tatut06:02:40

I can see a performance difference in a simple comparison, querying a single attribute by EAV patterns is faster than pulling a single attribute

tatut06:02:21

afaict pull is fetching the docs, I would expect this to be slower (especially when docstore is a remote jdbc) than local rocksdb

tatut06:02:38

and I guess it needs to fetch the whole doc even if we only need to pull a subset of the attributes

refset12:02:11

pull always fetches (and decodes) whole documents, yep, even if you are only ultimately retrieving a single attribute

refset12:02:35

~It looks like I inadvertently clobbered the line in the docs for the subsequent versions (which I'll fix now~ :man-facepalming:~) - but there's an in-memory LRU document cache you can configure: <https://docs.xtdb.com/storage/1.21.0/jdbc/#:~:text=cache%2Dsize%20(int)%3A%20size%20of%20in%2Dmemory%20document%20cache%20(number%20of%20entries%2C%20not%20bytes)|https://docs.xtdb.com/storage/1.21.0/jdbc/#:~:text=cache%2Dsize%20(int)%3A%20size%20of%20in%2D[…]%20cache%20(number%20of%20entries%2C%20not%20bytes)>~

refset12:02:19

For Kafka users the doc-store is durably replicated into a "local-document-store" which is backed by RocksDB also, so it has faster performance in these scenarios (at the cost of additional local disk usage). In theory we could extend the JDBC module to also utilise this capability, but we've not experimented with that so far

refset12:02:32

Is this looking like a bottleneck for your app?

refset12:02:33

> there's an in-memory LRU document cache you can configure sorry my brain just switched back on, ignore what I wrote about the docs above - although the entry on the page is still rather unclear. Basically there used to be a direct parameter on the JDBC module, but nowadays you need to pass through an appropriately configured xtdb.cache/->cache (otherwise the defaults for this cache module will be used)

tatut12:02:22

unless you are hitting a cache, wouldn’t pulling the docs be slower than checking EAV?

tatut13:02:10

like let’s say I have docs with 20 attributes, and I pull 2 of them, it still needs to fetch and parse the whole docs (if it is not in cache)

tatut13:02:44

I don’t think it is necessarily a bottleneck now, I will need to add more performance tuning… I just noticed this because our SQL connection pool timed out waiting. It is still in the same datacenter, so not far.

👍 2
tatut13:02:36

but for a large query, I would expect local rocksdb to be faster, when you are pulling a small subset of a document’s attributes

tatut13:02:57

I can of course rewrite a pull to EAV (but that is not as nice if there are missing attributes, which pull doesn’t care about)

refset13:02:24

> unless you are hitting a cache, wouldn’t pulling the docs be slower than checking EAV? for small values within documents, yes definitely it is in theory possible to recombine the information stored in the indexes to create the full documents, but that could involve a lot more I/O for large documents (even if it's local), see https://github.com/xtdb/xtdb/issues/1511 Arguably some fast path for dealing will small numbers of attributes in pull using the indexes would be a sensible incremental change that's almost always guaranteed to be faster

👍 2
tatut13:02:09

I was under the wrong impression, that pull would also work from local indexes, that’s why I was quite surprised

tatut13:02:28

but yes, I will probably need to add a bigger document cache and possible rewrite some large queries that use pull, to use eav

tatut13:02:13

if the default is 131kb, then up that to 128mb and see if it helps

tatut13:02:25

read up on the previous link, yes I see the problem that EAV indices don’t have enough information to reconstruct everything

tatut13:02:42

but I do as a programmer, so I could even write something like {:find [(pull e [:foo (:bar :into []) :baz])] :where […]}

tatut13:02:28

that would pull regular single values :foo and :baz and :bar as a multivalue into a vector

tatut13:02:07

I don’t know how you feel about this type of hinting, but the programmer in many cases would know how they want the values

refset15:02:18

> if the default is 131kb, ah sorry, my description still isn't clear enough - that doc cache default size is 131k entries, not bytes (it's backed by a LinkedHashMap)

👍 2
refset15:02:17

I suppose an index-based workaround would be to use get-attr and construct a hash-map, e.g.:

[(get-attr ?e :foo) [foo]]
[(get-attr ?e :bar) [bar]]
[(hash-map :foo foo :bar bar) doc]

refset15:02:49

but I appreciate that's no substitute for pull 🙂

refset15:02:49

thanks for the feedback - we'll try to find the right place in the docs to explain the behaviour / performance implications of the current design

tatut17:02:03

so it is unknown how big the cache will be, I’ll keep, seeing (* 128 1024) as the default size immediately made me think of bytes, but yes doc count makes more sense

tatut17:02:12

but if it’s docs, then it is difficult to know how much memory it will take

refset18:02:24

> if it’s docs, then it is difficult to know how much memory it will take this is true, note that it is also the case that this LRU cache is not heap-aware (so in principle can cause OOMs)

tatut05:02:21

I guess this is one of the trade-offs for having schema vs not, we don’t know attribute cardinality.

👍 2
tatut05:02:10

btw, does the query plan show any information about needing doc store?

refset12:02:05

not currently, the query plan only pertains to the :where, but that's not a bad idea :thinking_face: