-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement inserting transactions into a forming block #131
Comments
If we add a transaction counter to |
Would it work to simply add a |
It would work, but I believe we'll have transaction serialization failures for some requests. I haven't checked how it works in practice, but please take a look on https://www.postgresql.org/docs/9.1/transaction-iso.html Serializable Isolation Level. I believe if we have a couple of those updates running concurrently some of them will fail. But maybe I don't understand it well enough. |
If we put all the changes in a multi (it should be like this anyway) then it shouldn't be an issue right? |
@mederic-p DB will be consistent for sure. I thought we might run into serialization failures because of db transaction ordering issues.
I think the read in 2 might cause serialization problems for concurrent db transactions, meaning only one will execute and the other will rollback. But I might be totally wrong. I'll just code it and show you the code. |
I see, what if, instead of storing a
Does it help? |
That would be perfect. I'll try to do it. |
Some thoughts on calculating transaction index: |
When implementing this I ran into performance issues.
If I do not lock block with
Basically each of this transactions takes couple millliseconds + there is probably some overhead from using |
Perhaps there's a different angle how this could be made. There are two options from your #133, afaik: Correct? |
almost, |
Okay, so there's another step happening after the above. Which is Right? It seems to me that the previous step and this one ( |
I'll check tomorrow if I can merge those two steps, that's a good idea to see how it will work. |
It's true the step into :pending_submission does not happen on every insert, but the select read does. Let's see what it does perf wise.
|
Thanks Ino.
which does not lock and doesn't keep track of |
Just an idea. Reading from the thread/discussion here it seems the performance is to be bottlenecked by tx index incrementation (right?) What if we make tx index flagging async? So we first write tx to DB without index and then wait for the tx index to be batch flagged by another process. Now we decrease the need of lock to how often the process batch flag those tx indexes. The API call can still be synchronised I think. So the flow would be:
The process that batch flags the index probably need to do it every Xms where X is not too big (to make the API call able to return back the data without long waiting time), probably we can try....50 or 100ms +- some jitter (to avoid 2 childchain instance always try to flag at same timing) to see if it helps? |
Thanks @boolafish for the solution, I'm not totally sure that locking+txindex is indeed the bottleneck. To me it feels like postgres is the bottleneck, however if @pgebal could try a POC of your solution and see how it performs it could be great!. |
lol didn't read that @pgebal mentioned: "always insterts 1 as tx_index". But I think in general, what I mean is we can probably batch update everything that this PR is aiming to do on the tx instead. Then we can hope it to be more efficient a bit by having less things locked and batch updating stuff. |
Thanks Andy. Yes, I think we will eventually have to go with doing it async. That introduces a trade-off. Requests will take longer and possibly the job that determines tx_indexes and block number will still have to lock on some db row. But we won't know how it works until we try it. To move forward with the development of childchain we decided with Mederic to merge version that handles around 500-600 submits per second and properly handles concurrent transactions. |
Just to keep everything in context. When we use single transaction insert like currently in master we can handle 5 times more transactions. On my local setup about 2500 per second, compared to 500-600. |
References to state 'forming`: #121 (comment)
Inserting a transaction has to return block number and tx index.
Specs to come.
The text was updated successfully, but these errors were encountered: