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

Move libp2p,discv5,backfill to workers #4856

Closed
wemeetagain opened this issue Dec 5, 2022 · 9 comments
Closed

Move libp2p,discv5,backfill to workers #4856

wemeetagain opened this issue Dec 5, 2022 · 9 comments
Labels
meta-discussion Indicates a topic that requires input from various developers.

Comments

@wemeetagain
Copy link
Member

During team retreat we discussed the idea of parallelizing work across multiple threads as makes sense.

If anyone has more notes from that session add here please.

Some open questions:

  • how should metrics be handled across workers?
@dapplion
Copy link
Contributor

dapplion commented Dec 6, 2022

how should metrics be handled across workers?

I've been playing around with discv5 on a thread on this is the biggest hurdle I found so far.

Requirements:

  • Functions can't be called directly, everything must be a message / event
  • Metrics server will remain in the main thread, which can have metrics data already available or collect it from somewhere

Solutions:

  • On every metrics call (metric.inc()) fire an event to upstream that data to main thread
  • Collect metrics on worker, and then on scrape collect all of them with a single event

@dapplion
Copy link
Contributor

dapplion commented Dec 6, 2022

Some notes

IMG_20221201_201337
IMG_20221201_201319

@dapplion dapplion changed the title Multithreaded Lodestar Move libp2p,discv5,backfill to workers Dec 6, 2022
@wemeetagain
Copy link
Member Author

Collect metrics on worker, and then on scrape collect all of them with a single event

Yeah thats what I was leaning towards. The worker maintains its own Registry. And the worker exposes a async metrics(): Promise<string> that basically looks like return await registry.metrics()

@wemeetagain
Copy link
Member Author

I've been playing around with discv5 on a thread on this is the biggest hurdle I found so far.

Same 😂

The other weird thing I saw is that the threads library doesn't support the event listener pattern, only "observables". You can create an observable per event to listen on, its just a little weird.

@dapplion
Copy link
Contributor

dapplion commented Dec 7, 2022

The other weird thing I saw is that the threads library doesn't support the event listener pattern, only "observables". You can create an observable per event to listen on, its just a little weird.

I think we should skip the threads library for now. Or connect to the raw's Worker events for events, and use threads for an easy wrapper for direct calls from the main thread

@philknows philknows added the meta-discussion Indicates a topic that requires input from various developers. label Dec 15, 2022
@wemeetagain
Copy link
Member Author

Discv5 done, see #4988

@wemeetagain
Copy link
Member Author

wemeetagain commented Jan 29, 2023

Looking into moving the network into a thread. Some annoyances/hurdles (that could be treated as refactoring prereqs):

  • some consensus objects can't be structuredClone'd. Any BitArray gets converted into an object.
    • convert BitArray methods to functions?
    • build generic ssz type "rehydrator" to recursively convert any BitArray subproperties back into BitArrays?
    • transfer across thread boundary as bytes
      • start with this, only consider ^ solutions if there are problems with this
      • see if bytes can be transferred
  • INetworkOptions can't be structuredCloned. Contains functions / instances
    • refactor so it can be structuredCloned
  • Network submodules contain refs to chain / config
    • worker can own its own config and clock
    • any chain data required for init can be passed in worker data (initial validator count)
    • gossip validation and req/resp handlers can be performed in main thread
    • push chain.getStatus() into network worker on new head calculation
  • libp2p initialized at a higher level and passed into network constructor

@dapplion
Copy link
Contributor

dapplion commented Feb 13, 2023

  • Network worker must deal with ssz serialized bytes only. Handlers for reqresp and gossip must be performed in the main thread.
  • Status handler can either be handled on the main thread on a pull basis, or the main thread forkchoice to push updates to network worker
  • Config and clock should be cloned

@dapplion
Copy link
Contributor

discv5 and libp2p moved to worker. Open dedicated issue to backfill when we implement it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta-discussion Indicates a topic that requires input from various developers.
Projects
None yet
Development

No branches or pull requests

3 participants