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

fix(BlocksService): refactor api.derive for performance, and add historicApi to BlocksService #699

Merged
merged 15 commits into from
Oct 11, 2021

Conversation

TarikGul
Copy link
Member

@TarikGul TarikGul commented Oct 7, 2021

rel: #698
rel: #693

Performance bump

Benchmarks were done against /blocks where the main known regression took place. There are 3 versions we are testing here: v9.1.9, v9.2.0, and this current branch which I will denote as 'beta'.

// This benchmark reflects sidecar with an empty cache in all respects
4 threads 12 connections 2 mins
v9.1.9 -> Completed Reqs: 162, Avg Latency: 8.61s
v9.2.0 -> Completed Reqs: 24, Avg Latency: 45.08s
beta -> Completed Reqs: 55, Avg Latency: 22.75s

// The below benchmarks reflects sidecar with a filled cache
4 threads 6 connections 2 mins
v9.1.9 -> Completed Reqs: 239, Avg Latency: 1.98s
v9.2.0 -> Completed Reqs: 71, Avg Latency: 7.86s
beta -> Completed Reqs: 147, Avg Latency: 3.86s

4 threads 4 connections 2 mins
v9.1.9 -> Completed Reqs: 255, Avg Latency: 1.88s
v9.2.0 -> Completed Reqs: 107, Avg Latency: 5.94s
beta -> Completed Reqs: 211, Avg Latency: 2.28s

Api.at()

Local Benchmarks were also ran against instantiating api.at(). Initially for a particular runtime if the information isn't cached inside of the api it will take about 3 seconds too initialize. But after its cached it usually takes 1-50 milliseconds to recall.

All instances of api.query....at() in BlocksService are now using a historicApi to get any information, regarding api.query. During this I found a bug where we were getting the wrong transactionByteFee for historic runtimes because the api was always using the latest metadata. This is also now fixed, and all e2e tests for kusama reflect this change.

api.derive

I noticed api.derive was a large area of regression for sidecar while doing local isolated benchmarks, therefore I took the method apart and abstracted the things we need from it in order to speed the request time up.

extra notes

I fixed the mockApi for tests in PalletsStakingProgressService.spec.ts. Moving forward until all services are switched to using the historicApi the mockApi enviornment will be going through some adjustments. Once the final Service is fixed up, the mockApi will be readjusted to have a generated historicApi, as well as mockApi.

Part 2: #702

@@ -496,13 +507,13 @@ export class BlocksService extends AbstractService {
}

const multiplier =
await api.query.transactionPayment?.nextFeeMultiplier?.at(parentHash);
await historicApi.query.transactionPayment?.nextFeeMultiplier();
Copy link
Contributor

Choose a reason for hiding this comment

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

From what I understand we may actually need (await api.at(parentHash)).query.transactionPayment?.nextFeeMultiplier()

Copy link
Contributor

Choose a reason for hiding this comment

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

In order to make sure we are fetching at the paren block

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh yes, you are totally correct! good catch

Copy link
Member Author

Choose a reason for hiding this comment

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

sweet, I actually reverted this bit to its original form, as I cant instantiate another api.at, without throwing a ton of websocket errors in our tests.

@emostov
Copy link
Contributor

emostov commented Oct 8, 2021

Left a few questions but will come back for a full review

All instances of api.query....at() in BlocksService are now using a historicApi to get any information, regarding api.query. During this I found a bug where we were getting the wrong transactionByteFee for historic runtimes because the api was always using the latest metadata. This is also now fixed, and all e2e tests for kusama reflect this change.

Is api.at only helpful for querys or does it also help for metadata consts and rpc calls?

@emostov emostov self-requested a review October 8, 2021 23:24
@TarikGul
Copy link
Member Author

TarikGul commented Oct 8, 2021

Left a few questions but will come back for a full review

All instances of api.query....at() in BlocksService are now using a historicApi to get any information, regarding api.query. During this I found a bug where we were getting the wrong transactionByteFee for historic runtimes because the api was always using the latest metadata. This is also now fixed, and all e2e tests for kusama reflect this change.

Is api.at only helpful for querys or does it also help for metadata consts and rpc calls?

Thanks!

So yea api.at does not have an rpc methods decorated in it. This is the ApiDecoration<ApiType extends ApiType> type for the historicApi

@@ -148,7 +148,7 @@
"info": {
"weight": "195000000",
"class": "Normal",
"partialFee": "3333333"
"partialFee": "166666666"
Copy link
Member

Choose a reason for hiding this comment

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

why is this partialFee changed?

I guess because the historialApi is used or the calculate fee bug....

Copy link
Member Author

@TarikGul TarikGul Oct 11, 2021

Choose a reason for hiding this comment

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

Yup so I found a bug for calculating fees in regards to historic blocks. I fixed it in this PR thats why I changed the e2e tests too for partialFee responses.

Copy link
Member

@niklasad1 niklasad1 left a comment

Choose a reason for hiding this comment

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

LGTM

api,
parentHash
);
this.blockWeightStore[specVersion] ||= this.getWeight(historicApi);
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL OR assignments are a thing

Copy link
Contributor

@insipx insipx left a comment

Choose a reason for hiding this comment

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

LGTM, have the same question as niklasad1 though

@TarikGul TarikGul merged commit 5861cb1 into master Oct 11, 2021
@TarikGul TarikGul deleted the tarik-refactor-derive branch October 11, 2021 14:37
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