Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(collator): refactor message groups #316

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

serejkaaa512
Copy link
Contributor

No description provided.

@serejkaaa512 serejkaaa512 force-pushed the feature/optimize-messages-groups branch 6 times, most recently from d77124a to e318e94 Compare September 20, 2024 06:21
@serejkaaa512 serejkaaa512 force-pushed the feature/optimize-messages-groups branch 2 times, most recently from 6b35228 to 7e4283d Compare September 21, 2024 15:25
@serejkaaa512 serejkaaa512 force-pushed the feature/optimize-messages-groups branch 2 times, most recently from 3528436 to d16bfa3 Compare September 23, 2024 08:25
@serejkaaa512
Copy link
Contributor Author

serejkaaa512 commented Sep 23, 2024

Test: DEX -n 500 -r 1000. grafana

Result

Block Size (avg):

Old: 15 - 20 MB
New: 10 - 15 MB

Merkle Update (max):

Old: 50 ms
New: 50 ms

Finalize time (max):

Old: 250-750 ms
New: 250-750 ms

Collation time (max):

Old: 750 ms - 1 s
New: 250-750 ms

Block rates:

Old: 2.59
New: 2.59

New state prepare time (max):

Old: 750 ms - 1 s
New: 250-750 ms

Working state wait time (max):

Old: 250-750 ms
New: 250-750 ms

Read existing messages (max):

Old: 250 ms
New: 250 ms

Add messages to group (max):

Old: 50 - 100 ms
New: 10 - 25 ms

@serejkaaa512 serejkaaa512 force-pushed the feature/optimize-messages-groups branch from d16bfa3 to 5a76c5f Compare September 23, 2024 12:33
@serejkaaa512 serejkaaa512 force-pushed the feature/optimize-messages-groups branch 9 times, most recently from 6359340 to 50fbf16 Compare October 1, 2024 07:57
@serejkaaa512 serejkaaa512 force-pushed the feature/optimize-messages-groups branch from 50fbf16 to cc44bf7 Compare October 2, 2024 05:42
@@ -1273,6 +1279,10 @@ impl CollatorStdImpl {
drop(histogram);
self.do_collate(working_state, None).await?;
} else {
if !has_uprocessed_messages && !has_externals {
Copy link
Member

Choose a reason for hiding this comment

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

has_unprocessed_messages

Comment on lines 310 to 346
pub fn extract_merged_group(&mut self) -> Option<MessageGroup> {
let mut messages: Vec<(HashBytes, VecDeque<Message>)> =
self.current_messages.drain().collect();

while let Some((key, val)) = self.new_messages_full.pop_first() {
messages.push((key, val));
}

while let Some((key, val)) = self.new_messages.pop_first() {
messages.push((key, val));
}

if messages.is_empty() {
return None;
}

let group = MessageGroup::new(
messages
.into_iter()
.map(|(h, m)| (h, m.into_iter().map(|m| m.inner).collect()))
.collect(),
self.int_messages_count,
self.ext_messages_count,
);

tracing::debug!(target: tracing_targets::COLLATOR,
"extracted merged message group of new messages from message_groups buffer: buffer int={}, ext={}, group {}",
self.int_messages_count(), self.ext_messages_count(),
DisplayMessageGroup(&group),
);

Some(group)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we update counters in self after moving messages into a new MessageGroup?

Comment on lines +72 to +73
new_messages: BTreeMap<HashBytes, VecDeque<Message>>,
new_messages_full: BTreeMap<HashBytes, VecDeque<Message>>,
Copy link
Member

@0xdeafbeef 0xdeafbeef Oct 2, 2024

Choose a reason for hiding this comment

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

Can't it be changed to IndexMap ?

@@ -204,6 +209,7 @@ pub struct CollatorStdImpl {
anchors_cache: AnchorsCache,
stats: CollatorStats,
timer: std::time::Instant,
accounts_load: BTreeMap<AccountId, u32>,
Copy link
Member

Choose a reason for hiding this comment

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

Can't this be changed to HashMap? It seems like order doesn't matter

@serejkaaa512 serejkaaa512 force-pushed the feature/optimize-messages-groups branch from 22e11bd to 96081e8 Compare October 9, 2024 15:24
Copy link

codecov bot commented Oct 9, 2024

Codecov Report

Attention: Patch coverage is 70.56962% with 93 lines in your changes missing coverage. Please review.

Project coverage is 47.13%. Comparing base (21577f8) to head (f9f488c).

Files with missing lines Patch % Lines
collator/src/collator/message_group_v1.rs 75.86% 49 Missing and 7 partials ⚠️
collator/src/collator/types.rs 56.62% 32 Missing and 4 partials ⚠️
collator/src/collator/mod.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #316      +/-   ##
==========================================
+ Coverage   46.99%   47.13%   +0.13%     
==========================================
  Files         240      241       +1     
  Lines       37403    37530     +127     
  Branches    37403    37530     +127     
==========================================
+ Hits        17578    17688     +110     
- Misses      18909    18924      +15     
- Partials      916      918       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@serejkaaa512 serejkaaa512 force-pushed the feature/optimize-messages-groups branch 3 times, most recently from de646d9 to bbf225b Compare October 9, 2024 17:48
@Rexagon Rexagon force-pushed the feature/optimize-messages-groups branch from bbf225b to f9f488c Compare October 10, 2024 16:29
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants