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

Transactions take a long time to load #85

Closed
WhoSoup opened this issue Jan 15, 2019 · 1 comment
Closed

Transactions take a long time to load #85

WhoSoup opened this issue Jan 15, 2019 · 1 comment

Comments

@WhoSoup
Copy link
Member

WhoSoup commented Jan 15, 2019

I was tasked to investigate why the "Transactions" page is fairly slow to load, and I tracked down the error to the GetTXRange function:

factom/wallet/txdatabase.go

Lines 207 to 216 in 27c6cd7

txs, err := db.GetAllTXs()
if err != nil {
return nil, err
}
for _, tx := range txs {
if s <= tx.GetBlockHeight() && tx.GetBlockHeight() <= e {
filtered = append(filtered, tx)
}
}

In order to get a range of transactions by height, the code first gets every single transaction via txs, err := db.GetAllTXs() (by scanning through all 170k+ Factoid Blocks) and then loops through all transactions to filter out the ones with the desirable height. This is obviously not very efficient and caused the function GetRelatedTransactions to perform very poorly, taking an average of ~5seconds to execute on my pc.

This function locks a mutex.
https://github.com/FactomProject/enterprise-wallet/blob/7819099c274a1bedaa9d677371c0b29079931f2a/wallet/walletDB.go#L390-L391

The mutex remains locked as long as the function runs in the background and it's automatically scheduled to execute every 10 seconds, which prevented the "Transactions" page from loading as it waited for that mutex to be released.

This can be fixed by rewriting the GetTxRange function to only cycle from the head down to the desired height and grabbing the related transactions instead of all 170k+ factoid blocks, which drove down execution time to ~250ms on my pc.

Proposed fix: WhoSoup@e0e9e5d

(note: the new code is substantially copy/pasted from GetAllTxs)

@Cahl-Dee
Copy link

Cahl-Dee commented Sep 9, 2019

This is addressed in #88 and is pulled over to EW in: FactomProject/enterprise-wallet#35

Therefore closing this.

@Cahl-Dee Cahl-Dee closed this as completed Sep 9, 2019
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

No branches or pull requests

2 participants