Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Sim2h gossip improvements #1884

Merged
merged 35 commits into from
Nov 23, 2019
Merged

Sim2h gossip improvements #1884

merged 35 commits into from
Nov 23, 2019

Conversation

lucksus
Copy link
Collaborator

@lucksus lucksus commented Nov 19, 2019

PR summary

  1. Don't try to fill missing aspects by asking an agent that also doesn't have those aspects (which is bound to create an EntryNotFoundLocally error on that node)
  2. Merge authoring list into gossip list so sim2h has authoring nodes as sources for gossiping newly authored data (as it wouldn't ask those nodes otherwise with 1.)
  3. Clear cached missing entry data when agent leaves and drop all cached data about space when the last agents leaves the space.

testing/benchmarking notes

If a large number of nodes enter into a network at the same time (as tested in our stress-tests), the assumption that was underlying the current gossip-mock code in sim2h doesn't apply: if a node is missing an entry aspect, sim2h assumes all other nodes to have it and picks one randomly. But if 50 nodes come on at the same time, all of them is missing entry aspects (namely agent_id and chain headers of the other 49 nodes). But only one of those other nodes actually has that data - drawing one from the whole pool with uniform distribution leads to a gossip failure in 98% of cases.

The changes in this branch might reduce the network load in our stress-tests substantially.

followups

( any new tickets/concerns that were discovered or created during this work but aren't in scope for review here )

changelog

  • if this is a code change that effects some consumer (e.g. zome developers) of holochain core, then it has been added to our between-release changelog with the format
- summary of change [PR#1234](https://github.com/holochain/holochain-rust/pull/1234)

documentation

@lucksus lucksus changed the title Sim2h improvements Sim2h gossip improvements Nov 20, 2019
@lucksus lucksus marked this pull request as ready for review November 21, 2019 21:30
crates/sim2h/src/cache.rs Outdated Show resolved Hide resolved
crates/sim2h/src/lib.rs Outdated Show resolved Hide resolved
@lucksus lucksus added the NEEDS REVIEW This PR requires peer code review label Nov 22, 2019
Copy link
Member

@zippy zippy left a comment

Choose a reason for hiding this comment

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

This all looks good, but It seems to me that one thing we are missing is cleaning up this data when an agent disconnects in the remove_agent() function in cache, or at least we should be marking that an agent isn't available and should be filtered out of the possible agents to get things from.

crates/sim2h/src/cache.rs Outdated Show resolved Hide resolved
crates/sim2h/src/cache.rs Outdated Show resolved Hide resolved
crates/sim2h/src/cache.rs Outdated Show resolved Hide resolved
crates/sim2h/src/cache.rs Outdated Show resolved Hide resolved
Copy link
Member

@maackle maackle left a comment

Choose a reason for hiding this comment

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

Some performance suggestions and more places we can use HashSet

crates/core/src/network/handler/lists.rs Outdated Show resolved Hide resolved
crates/core/src/network/handler/lists.rs Outdated Show resolved Hide resolved
&self,
agent_id: &AgentId,
entry_hash: &EntryHash,
aspects: &Vec<AspectHash>,
Copy link
Member

Choose a reason for hiding this comment

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

This should also be a HashSet, and then we can use set operations to answer the question this function asks

Comment on lines +103 to +107
for aspect in aspects {
if !missing_aspects_for_entry.contains(aspect) {
return false;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

FYI we could use HashSet::difference() for this, but I'm not sure if the speed gain is worth it

Comment on lines 637 to 643
agent_pool
.iter()
// We ignore all agents that are missing all of the same aspects as well since
// they can't help us.
.filter(|a| !space_lock.agent_is_missing_all_aspects(*a, entry_hash, aspects))
.collect()
};
Copy link
Member

Choose a reason for hiding this comment

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

This could get slow as we scale up the number of agents, since we are iterating over all agents and calculating which are missing aspects. Since we ultimately only want one agent that meets the criteria, a faster way would be to generate a random permutation of vec indices so we can iterate over the agents randomly, and return the first one that doesn't have missing aspects.

Can use: https://docs.rs/rand/0.6.5/rand/seq/trait.SliceRandom.html#tymethod.shuffle

zippy and others added 5 commits November 22, 2019 16:19
- Shuffle the agent pool (O(1)) before conducting search so we don't
have to filter the entire agent pool
- Avoid an extra clone + iteration of the agent pool by including the agent ID
sameness check at the same time as doing the missing aspects check
Copy link
Member

@maackle maackle left a comment

Choose a reason for hiding this comment

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

Just one thing to fix which I'm working on now

crates/core/src/network/handler/lists.rs Outdated Show resolved Hide resolved
@zippy zippy requested a review from maackle November 22, 2019 18:04
@lucksus lucksus merged commit dd6f131 into develop Nov 23, 2019
@neonphog neonphog deleted the sim2h-improvements branch March 6, 2020 00:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
NEEDS REVIEW This PR requires peer code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants