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

Optimize block processing - Part 3 #802

Merged
merged 16 commits into from
Sep 26, 2024

Conversation

heifner
Copy link
Member

@heifner heifner commented Sep 18, 2024

Part 3 of 3 of #529. See #688 for part 2 and #619 for part 1.

  • Add optional handler id to app().executor().post().
    • If handler id is provided and a existing function with the same handler id has already been posted with the same priority the function is not posted.
    • This allows for deduplication of redundant posts.
    • Specifically if an existing on_incoming_block() has been posted to the main thread, then another does not need to be added as the on_incoming_block will execute any blocks ready from the fork database.

Resolves #529

@heifner heifner added the OCI Work exclusive to OCI team label Sep 18, 2024
@ericpassmore
Copy link
Contributor

Note:start
category: Other
component: Internal
summary: Optimize block processing - Part 3: deduplication of redundant posts.
Note:end

Comment on lines 116 to 119
for (; i != end; p = i, ++i) {
if ((*i)->priority() != priority)
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems wrong to me. Shouldn't we want to skip handlers which have the same priority, but a different id?

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 idea is the find the last posted function. If it same as you are attempting to post, don't bother.

Comment on lines 113 to 122
if (i != end) {
// ordered iterator appears to only be a forward iterator
auto p = i;
for (; i != end; p = i, ++i) {
if ((*i)->priority() != priority)
break;
}
if ((*p)->priority() == priority && (*p)->id() == id)
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could it be as simple as this?

Suggested change
if (i != end) {
// ordered iterator appears to only be a forward iterator
auto p = i;
for (; i != end; p = i, ++i) {
if ((*i)->priority() != priority)
break;
}
if ((*p)->priority() == priority && (*p)->id() == id)
return;
}
if (i != end) {
// ordered iterator appears to only be a forward iterator
for (; i != end && (*i)->priority() == priority; ++i)
if ((*i)->id() == id)
return;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

No. You have to find the last posted handler with the same priority and see if that one has the same id.

Copy link
Contributor

@greg7mdp greg7mdp Sep 24, 2024

Choose a reason for hiding this comment

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

Why does it has to be the last posted one? Why does it matter if something else was posted later with the same priority?

Copy link
Member Author

Choose a reason for hiding this comment

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

This goes with the more conservative approach of only de-dup on matching id for a given priority when it was the last id posted.

Say you have items in the queue, u=unique, pb=process_incoming_block
q9(u) q8(pb) q7(u)

Say you want to post a q6(pb), it is possible this is not safe to de-dup because if q7(u) does something that needs q6(pb) to run then you end up with q6(pb) not running. So this goes with the more conservative route of only de-dup if q7(u) is a pb. Granted we could argue that q7(u) should post a pb if needs that to happen.

Copy link
Contributor

Choose a reason for hiding this comment

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

The code I sent dedups only if it is the same id (pb) at the same priority, so in your example posting q6(pb) would not dedup as there is no other q6(pb) in the queue. Or am I missing something?

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 9,8,7 are just order numbers. They are all the same priority.
q9(u) q8(pb) q7(u)
So your code would find q8(pb) and return (de-dup). Want to only compare to q7(u) and then non-dedup.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason for this requirement, i.e would the code not work if we didn't check that it was the last posted? It seems to me that either we want to dedup, and then we should just do it, or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

Been thinking about this. Maybe I am being too conservative. If the last item running needs to have a follow non-unique item it should post it.

@greg7mdp
Copy link
Contributor

What was the rationale for not using unique_ptr anymore in the prio_queue?

@heifner
Copy link
Member Author

heifner commented Sep 24, 2024

What was the rationale for not using unique_ptr anymore in the prio_queue?

boost::heap doesn't support them. It uses copy in some places.

@greg7mdp
Copy link
Contributor

boost::heap doesn't support them. It uses copy in some places.

annoying. Maybe it would be better to use shared_ptr, which would make it easier to be confident that there are no memory leaks (although there aren't now).

Base automatically changed from GH-529-optimize-block-processing-part2 to main September 26, 2024 18:44
@heifner heifner merged commit d589ea5 into main Sep 26, 2024
36 checks passed
@heifner heifner deleted the GH-529-optimize-block-processing-part3 branch September 26, 2024 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCI Work exclusive to OCI team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize processing of incoming blocks
4 participants