Skip to content
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

feat!: improve performance of HandleTransactionGet, by requesting all transactions from InvMsg at once #25

Merged
merged 3 commits into from
Jul 5, 2024

Conversation

kuba-4chain
Copy link
Collaborator

@kuba-4chain kuba-4chain commented Jul 3, 2024

What has been done

Method
HandleTransactionGet(msg *wire.InvVect, peer PeerI) ([]byte, error)
was changed to
HandleTransactionsGet(msg []*wire.InvVect, peer PeerI) ([][]byte, error).

This change allows for more efficient transaction getting, because it bundles all tx requests from the InvVect message, instead of asking for transactions one-by-one.

Why I modified this method, instead of leaving it as it was and adding another one?

  1. The method was used only in one place, therefore adding another method would make the first one unused.
  2. It doesn't change the logic of sending transactions to the peer, it just changes the logic of retrieving transactions from database from a client of go-p2p.

Potential downsides

  1. Breaking changes. Current clients of go-p2p need to adapt to this change, but I believe it's a useful and efficient change.
  2. Less information about errors for particular transactions. In previous approach, an error from getting each transaction was logged, and another transaction was requested. In new approach, if an error occurs by getting all transactions from InvVect message, no transactions are broadcasted.

peer.go Outdated Show resolved Hide resolved
peer.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@shotasilagadzetaal shotasilagadzetaal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't understand how the change speeds up the processing. As I see, you simply moved for loop from one function to another.

It doesn't call the function for each hash but passes those hashes together as a slice. But the work in the next function is the same - you go through all the hashes/txs and do the same operation. So the only change here is the place of the for loop.

Am I missing something here ? 🤔

peer.go Outdated Show resolved Hide resolved
@arkadiuszos4chain
Copy link
Contributor

I still don't understand how the change speeds up the processing. As I see, you simply moved for loop from one function to another.

It doesn't call the function for each hash but passes those hashes together as a slice. But the work in the next function is the same - you go through all the hashes/txs and do the same operation. So the only change here is the place of the for loop.

Am I missing something here ? 🤔

Not really. With this change we can limit database round trips as we request for few transactions in one call.

@shotasilagadzetaal
Copy link
Collaborator

I still don't understand how the change speeds up the processing. As I see, you simply moved for loop from one function to another.
It doesn't call the function for each hash but passes those hashes together as a slice. But the work in the next function is the same - you go through all the hashes/txs and do the same operation. So the only change here is the place of the for loop.
Am I missing something here ? 🤔

Not really. With this change we can limit database round trips as we request for few transactions in one call.

I still don't understand how the change speeds up the processing. As I see, you simply moved for loop from one function to another.
It doesn't call the function for each hash but passes those hashes together as a slice. But the work in the next function is the same - you go through all the hashes/txs and do the same operation. So the only change here is the place of the for loop.
Am I missing something here ? 🤔

Not really. With this change we can limit database round trips as we request for few transactions in one call.

Where is the decrease of DB calls in here? What do you mean? I still don't see it

@arkadiuszos4chain
Copy link
Contributor

arkadiuszos4chain commented Jul 4, 2024

I still don't understand how the change speeds up the processing. As I see, you simply moved for loop from one function to another.
It doesn't call the function for each hash but passes those hashes together as a slice. But the work in the next function is the same - you go through all the hashes/txs and do the same operation. So the only change here is the place of the for loop.
Am I missing something here ? 🤔

Not really. With this change we can limit database round trips as we request for few transactions in one call.

I still don't understand how the change speeds up the processing. As I see, you simply moved for loop from one function to another.
It doesn't call the function for each hash but passes those hashes together as a slice. But the work in the next function is the same - you go through all the hashes/txs and do the same operation. So the only change here is the place of the for loop.
Am I missing something here ? 🤔

Not really. With this change we can limit database round trips as we request for few transactions in one call.

Where is the decrease of DB calls in here? What do you mean? I still don't see it

image

This is the current implementation of PeerHandlerI in ARC metamorph. As you can see, we currently call the database for every transaction in a separate request.

With the new version, the client (e.g., ARC metamorph) can fetch data about all requested transactions in a single trip to the database.

Sample impl:
image

So, this change is not a performance improvement per se, but it provides the possibility for improvement by the library client.

@boecklim boecklim requested a review from ordishs July 4, 2024 08:58
@shotasilagadzetaal
Copy link
Collaborator

I still don't understand how the change speeds up the processing. As I see, you simply moved for loop from one function to another.
It doesn't call the function for each hash but passes those hashes together as a slice. But the work in the next function is the same - you go through all the hashes/txs and do the same operation. So the only change here is the place of the for loop.
Am I missing something here ? 🤔

Not really. With this change we can limit database round trips as we request for few transactions in one call.

I still don't understand how the change speeds up the processing. As I see, you simply moved for loop from one function to another.
It doesn't call the function for each hash but passes those hashes together as a slice. But the work in the next function is the same - you go through all the hashes/txs and do the same operation. So the only change here is the place of the for loop.
Am I missing something here ? 🤔

Not really. With this change we can limit database round trips as we request for few transactions in one call.

Where is the decrease of DB calls in here? What do you mean? I still don't see it

image

This is the current implementation of PeerHandlerI in ARC metamorph. As you can see, we currently call the database for every transaction in a separate request.

With the new version, the client (e.g., ARC metamorph) can fetch data about all requested transactions in a single trip to the database.

Sample impl: image

So, this change is not a performance improvement per se, but it provides the possibility for improvement by the library client.

I see, I was just looking for optimisation in p2p code. That makes sense now. Please consider backwards compatibility. I think it's kinda hard fork with this change.

@boecklim boecklim merged commit 5d6f580 into libsv:master Jul 5, 2024
5 checks passed
@kuba-4chain kuba-4chain deleted the feat/get-txs-batching branch July 6, 2024 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants