Skip to content

Implement concurrent partitions - #246

Merged
JonoPrest merged 10 commits into
mainfrom
release-concurrent-partitions
Oct 7, 2024
Merged

Implement concurrent partitions#246
JonoPrest merged 10 commits into
mainfrom
release-concurrent-partitions

Conversation

@JonoPrest

Copy link
Copy Markdown
Collaborator

This to allow indexers with lots of partitions to do concurrent requests to hypersync.

Currently it's experimental and seems like it could contain a memory leak so the idea is to have a side release that I can test a deployment.

@JonoPrest
JonoPrest requested a review from JasoonS October 2, 2024 14:47
@JonoPrest

Copy link
Copy Markdown
Collaborator Author

@JasoonS this is working well on the hosted service and I've added tests. Could you review?

Comment thread .github/workflows/release.yml
Comment thread .github/workflows/release.yml
fn is_valid_release_version_number(version: &str) -> bool {
let re_version_pattern = Regex::new(r"^\d+\.\d+\.\d+(-rc\.\d+)?$")
.expect("version regex pattern should be valid regex");
re_version_pattern.is_match(version) || version.starts_with("0.0.0-main-")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Now starts with 2.0.0 so just checking that it contains "-main"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Interesting. So this code actually won't, for example, match on release. It will only match on releases or those with RC on them?

Eg this won't match: 2.0.0-release-concurrent-partitions-20241004091855-c02f47f9

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is just for contract import, I think we can improve it, it was a bit of a hack #244

Comment on lines +84 to +95
let currentWrite = ref(Promise.resolve())
let schedule = ref(() => Promise.resolve())

let saveToCacheFile = data => {
let json = data->S.serializeToJsonStringOrRaiseWith(Data.schema)
NodeJsLocal.Fs.Promises.writeFile(~filepath=cacheFilePath, ~content=json)->ignore
let write = () => {
let json = data->S.serializeToJsonStringOrRaiseWith(Data.schema)
NodeJsLocal.Fs.Promises.writeFile(~filepath=cacheFilePath, ~content=json)
}
schedule := write
let _ = currentWrite.contents->Promise.thenResolve(_ => {
currentWrite := schedule.contents()
})

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Stops concurrent writes/corrupted files.

}

let addBlockRangeFetched = (
~stats: ChainWorker.blockRangeFetchStats,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Caused dependency cycle

Comment on lines +31 to +32
let maxPartitionConcurrency =
envSafe->EnvSafe.get("ENVIO_MAX_PARTITION_CONCURRENCY", S.int, ~fallback=10)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Allows multiple partitions to fire off hs queries simultaneously. We can experiment with increasing/decreasing this.

Comment on lines +181 to +188
/**
Retrieves an array of partitions that are most behind with a max number based on
the max number of queries with the context of the partitions currently fetching.

The array could be shorter than the max number of queries if the partitions are
at the max queue size.
*/
let getMostBehindPartitions = (

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Read this description to help give context to the function

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hmm, this function is definitely a little bit challenging to follow, but starting to get it. At least there are tests 😬

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sorry it's probably because of the loop fn. The main reason to do that over just iterating is that you can model an early exit for control flow. Let me add some more comments to it.

Comment on lines +243 to +249
let getNextQueriesOrThrow = (
self: t,
~eventFilters=?,
~currentBlockHeight,
~maxPerChainQueueSize,
~partitionsCurrentlyFetching,
) => {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This now returns an array of queries to make based on max concurrency, partitions currently fetching and which partition is most behind

@JonoPrest
JonoPrest force-pushed the release-concurrent-partitions branch from d649fd1 to c02f47f Compare October 4, 2024 09:18
@JonoPrest
JonoPrest force-pushed the release-concurrent-partitions branch from c02f47f to f39bd58 Compare October 4, 2024 14:41

@JasoonS JasoonS left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me - I want to fiddle a bit with the getNextQueriesOrThrow function a bit more, but shouldn't block this

@JonoPrest
JonoPrest merged commit 6c2261f into main Oct 7, 2024
@JonoPrest
JonoPrest deleted the release-concurrent-partitions branch October 7, 2024 08:58
DenhamPreen pushed a commit that referenced this pull request Oct 22, 2024
* Add benchmark for partition count

* Schedule async fs writes with benchmarks

* Implement concurrency between partitions

* Fix tests

* include aarch64-unknown-linux-gnu in non release builds for hosted service

* Upgrade version of dev releases and main releases

* Fix over-filled partitions

* Update benchmarks to separate fetchtime by partition id

* Add test for partitioned fetch state getMostBehindPartitions

* Add description to getMostBehindPartitions function
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.

2 participants