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

soroban-rpc: getLedgerEntries: query multiple ledger entries at once #896

Merged
merged 8 commits into from
Aug 25, 2023

Conversation

2opremio
Copy link
Contributor

@2opremio 2opremio commented Aug 24, 2023

This improves the performance of the getLedgerEntries method and also paves the way to querying multiple entries from libpreflight (ahead of the upcoming ledger expiration changes)

@2opremio 2opremio force-pushed the really-do-get-multiple-ledger-entries branch from 7891fd6 to a4818b6 Compare August 24, 2023 10:42
@2opremio
Copy link
Contributor Author

BTW, we should probably limit the number of entries requested at once.

@tsachiherman did you get to add a limit to the size of JSON requests? We should also do that.

@2opremio 2opremio requested a review from tsachiherman August 24, 2023 10:44
@2opremio
Copy link
Contributor Author

2opremio commented Aug 24, 2023

Uhmm .. this PR actually reduces the performance of preflighting. I should look into it before merging.

Before:

goos: darwin
goarch: arm64
pkg: github.com/stellar/soroban-tools/cmd/soroban-rpc/internal/preflight
BenchmarkGetPreflight
BenchmarkGetPreflight/In-memory_storage
BenchmarkGetPreflight/In-memory_storage-12         	    6476	    178607 ns/op
BenchmarkGetPreflight/DB_storage
BenchmarkGetPreflight/DB_storage-12                	    4984	    237336 ns/op
BenchmarkGetPreflight/DB_storage,_restarting
BenchmarkGetPreflight/DB_storage,_restarting-12    	    5192	    231442 ns/op
BenchmarkGetPreflight/DB_storage,_no_cache
BenchmarkGetPreflight/DB_storage,_no_cache-12      	    2744	    428038 ns/op
PASS

After:

goos: darwin
goarch: arm64
pkg: github.com/stellar/soroban-tools/cmd/soroban-rpc/internal/preflight
BenchmarkGetPreflight
BenchmarkGetPreflight/In-memory_storage
BenchmarkGetPreflight/In-memory_storage-12         	    5682	    213653 ns/op
BenchmarkGetPreflight/DB_storage
BenchmarkGetPreflight/DB_storage-12                	    2412	    485964 ns/op
BenchmarkGetPreflight/DB_storage,_restarting
BenchmarkGetPreflight/DB_storage,_restarting-12    	    2457	    459799 ns/op
BenchmarkGetPreflight/DB_storage,_no_cache
BenchmarkGetPreflight/DB_storage,_no_cache-12      	    1750	    678824 ns/op
PASS

@2opremio
Copy link
Contributor Author

2opremio commented Aug 24, 2023

I added a small optimization leading to better times but we are still doing worse than before.

goos: darwin
goarch: arm64
pkg: github.com/stellar/soroban-tools/cmd/soroban-rpc/internal/preflight
BenchmarkGetPreflight
BenchmarkGetPreflight/In-memory_storage
BenchmarkGetPreflight/In-memory_storage-12         	    6856	    175734 ns/op
BenchmarkGetPreflight/DB_storage
BenchmarkGetPreflight/DB_storage-12                	    3008	    367869 ns/op
BenchmarkGetPreflight/DB_storage,_restarting
BenchmarkGetPreflight/DB_storage,_restarting-12    	    3010	    366539 ns/op
BenchmarkGetPreflight/DB_storage,_no_cache
BenchmarkGetPreflight/DB_storage,_no_cache-12      	    2016	    592172 ns/op
PASS

@2opremio 2opremio force-pushed the really-do-get-multiple-ledger-entries branch from fa9e62a to 7ea058e Compare August 24, 2023 12:55
@2opremio 2opremio force-pushed the really-do-get-multiple-ledger-entries branch from 7ea058e to 2e9b9de Compare August 24, 2023 13:23
@2opremio
Copy link
Contributor Author

2opremio commented Aug 24, 2023

After #897 the numbers are much closer!

Before this PR:

goos: darwin
goarch: arm64
pkg: github.com/stellar/soroban-tools/cmd/soroban-rpc/internal/preflight
BenchmarkGetPreflight
BenchmarkGetPreflight/In-memory_storage
BenchmarkGetPreflight/In-memory_storage-12         	    6387	    170649 ns/op
BenchmarkGetPreflight/DB_storage
BenchmarkGetPreflight/DB_storage-12                	    4916	    229133 ns/op
BenchmarkGetPreflight/DB_storage,_restarting
BenchmarkGetPreflight/DB_storage,_restarting-12    	    4990	    226570 ns/op
BenchmarkGetPreflight/DB_storage,_no_cache
BenchmarkGetPreflight/DB_storage,_no_cache-12      	    2793	    424232 ns/op
PASS

After this PR:

goos: darwin
goarch: arm64
pkg: github.com/stellar/soroban-tools/cmd/soroban-rpc/internal/preflight
BenchmarkGetPreflight
BenchmarkGetPreflight/In-memory_storage
BenchmarkGetPreflight/In-memory_storage-12         	    6685	    173606 ns/op
BenchmarkGetPreflight/DB_storage
BenchmarkGetPreflight/DB_storage-12                	    4840	    242125 ns/op
BenchmarkGetPreflight/DB_storage,_restarting
BenchmarkGetPreflight/DB_storage,_restarting-12    	    4810	    242487 ns/op
BenchmarkGetPreflight/DB_storage,_no_cache
BenchmarkGetPreflight/DB_storage,_no_cache-12      	    2492	    476540 ns/op
PASS

@2opremio
Copy link
Contributor Author

I think I am happy with this.

cmd/soroban-rpc/internal/db/ledgerentry.go Outdated Show resolved Hide resolved
Copy link
Contributor

@tsachiherman tsachiherman left a comment

Choose a reason for hiding this comment

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

looks great, please take a note of @tamirms 's comment.

cmd/soroban-rpc/internal/db/ledgerentry.go Outdated Show resolved Hide resolved
cmd/soroban-rpc/internal/db/ledgerentry.go Outdated Show resolved Hide resolved
cmd/soroban-rpc/internal/preflight/pool.go Outdated Show resolved Hide resolved
@tsachiherman
Copy link
Contributor

BTW, we should probably limit the number of entries requested at once.

@tsachiherman did you get to add a limit to the size of JSON requests? We should also do that.

I'm not sure where that would be. But we should definitely add a limit to the number of keys that can be queried in a single getLedgerEntries call.

Adding a limit to the json size request is a bit harder to implement; we might be able to limit the http request size by adding a middleware.

@2opremio
Copy link
Contributor Author

BTW, we should probably limit the number of entries requested at once.

@tsachiherman did you get to add a limit to the size of JSON requests? We should also do that.

@tsachiherman did you note this comments?

@tsachiherman
Copy link
Contributor

BTW, we should probably limit the number of entries requested at once.
@tsachiherman did you get to add a limit to the size of JSON requests? We should also do that.

@tsachiherman did you note this comments?

I agree that we should limit the number of entries requested.

As for the other one, I think that it's doable via a middleware - but it's more work .. with less obvious gain. ( unless it's easy to configure )

@2opremio
Copy link
Contributor Author

2opremio commented Aug 24, 2023

Limiting the size of http requests is a pretty common practice.

Should we limit the number of entries queried to, say, 200?

@2opremio
Copy link
Contributor Author

@2opremio 2opremio enabled auto-merge (squash) August 25, 2023 08:30
@2opremio 2opremio merged commit fa3dd8d into stellar:main Aug 25, 2023
@2opremio 2opremio deleted the really-do-get-multiple-ledger-entries branch August 25, 2023 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants