0

I want to know how to handle qldb sessions in a node.js application.

Should I create one session for the entire scope of the app or should I make a new session before each batch of transactions?

Right now I'm creating a session before each transaction and I'm getting some OCC conflicts when running unit tests (for each test a new session is created).

Alko
  • 672
  • 10
  • 21

1 Answers1

1

You should use as many sessions as needed to achieve the level of throughput required. Each session can run a single transaction, and each transaction has a certain latency. So, for example, if your transactions take 10ms, then you can do 100 transactions per second (1s = 1000ms and 1000/10 = 100). If you need to achieve 1000 TPS, you would then need 10 sessions.

The driver comes with a "pool" of sessions. So, each transaction should request a session from the pool. The pool will grow/shrink as required.

Each session can live no longer than ~15 minutes (there is some jitter). Thus, you should handle the case where using a session throws an exception (invalid session) and retry your operation (get a session, run the transaction).

In terms of OCC, I think that is quite likely unrelated to your usage of sessions. OCC means you read data in your transaction that was changed by the time you tried to commit. Usually this means you haven't setup the right indexes, so your reads are scanning all items in a table.

Marc
  • 928
  • 5
  • 8
  • Actually I'm using the indexes from qldb (using `BY` clause). Should I create my own in any case? – Alko Nov 28 '19 at 09:39
  • 1
    It might be more useful if we can work through an example. Maybe you can link to a file or gist that shows what you're trying to accomplish? – Marc Nov 29 '19 at 21:29