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

Attempt to recognize "seeding-only" chunks early #537

Merged
merged 1 commit into from May 1, 2024

Conversation

ldmberman
Copy link
Member

Send a distinct reply to POST /chunk.

%% @doc Return true if the given range is covered by the configured storage modules.
has_range(Start, End) ->
{ok, Config} = application:get_env(arweave, config),
Intervals = get_unique_sorted_intervals(Config#config.storage_modules),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm definitely not suggesting we worry about optimizing anything without testing - but subjectively/qualitatively: why do we think that sorting all the intervals on each POST /chunk request won't materially impact performance?

Is it because we believe that almost all the time the number of intervals to be sorted, even for a large-ish miner, isn't that many (i.e. order of thousands rather than millions)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, that's about 10 extra ms, do you prefer to cache it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like has_range is called from is_offset_vicinity_covered which is in turn called once or twice for every call to add_chunk. So we're estimating that this would add 10-20ms every time we write a chunk? Is that correct? Or is only called under certain scenarios when writing a chunk (I couldn't quite trace through all the branches)

If it's every time we write a chunk, it sounds like it could impact the syncing phase runtime. Maybe?

e.g. if we assume 14,400,000 chunks per partition, and 200 concurrent sync jobs. Then we're looking at an increase in time of (14,400,000 / 200) * 10-20ms = 720-1440seconds or 12-24 minutes.

Okay even in that case it actually doesn't sound super problematic. Syncing and packing a full partition on a Ryzen 9 will take 11 hours, so we're adding maybe 2-3%. It's not nothing, but not sure anyone will notice.

Assuming all the math above is correct - what do you think? How hard would it be to cache and is it worth the engineering time and code complexity to save 2-3% of the sync/pack time per partition?

Copy link
Member Author

Choose a reason for hiding this comment

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

There was an extra call (fixed) - so we invoke is_offset_vicinity_covered once per add_chunk. Also, forgot to mention - I assumed ~10k storage modules.

I've made an easy patch which caches the list. It's a bit of a compromise due to some memory-movement overhead - ideally, we create an ordered ets set and use it inside has_range.

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh wait it only adds 10ms for 10k storage modules? In that case no need to cache I don't think!

Copy link
Collaborator

Choose a reason for hiding this comment

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

So at current size it's a fraction of an millisecond, right? I don't think that's something we need worry about then! By the time it takes a long time to search, I'm sure we'll have other, bigger bottlenecks :)

Copy link
Member Author

Choose a reason for hiding this comment

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

What do you think about keeping the cached version anyway?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Does the cache ever need to be invalidated? Like if the weave grows?

Copy link
Member Author

Choose a reason for hiding this comment

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

The configuration (including storage modules) is static at the moment.

@ldmberman ldmberman force-pushed the feature/long-term-chunk-keeping-estimation branch from 8ef211e to c844a19 Compare April 3, 2024 08:21
Copy link
Collaborator

@JamesPiechota JamesPiechota left a comment

Choose a reason for hiding this comment

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

LGTM!

Send a distinct reply to POST /chunk.
@ldmberman ldmberman force-pushed the feature/long-term-chunk-keeping-estimation branch from c844a19 to 80fb925 Compare April 25, 2024 19:16
@ldmberman ldmberman merged commit a9817e4 into master May 1, 2024
58 checks passed
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.

None yet

2 participants