Skip to content

Conversation

@lakshya-sky
Copy link
Contributor

@lakshya-sky lakshya-sky commented Dec 11, 2025

** Motivation **
Block execution is sync code and can benefit from using sync version of GenServer that relies on threads.

** Changes **

  • use crossbeam channel instead of std::sync::mpsc which allows cloning.
  • Introduces TrieUpdateWorker and moves thread spawning inside the GenServer::Init.

Closes #5565

@lakshya-sky
Copy link
Contributor Author

Waiting for upstream changes to be accepted lambdaclass/spawned#64.

@lakshya-sky lakshya-sky marked this pull request as ready for review December 11, 2025 01:33
@lakshya-sky lakshya-sky requested a review from a team as a code owner December 11, 2025 01:33
Copilot AI review requested due to automatic review settings December 11, 2025 19:03
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@lakshya-sky lakshya-sky force-pushed the refactor/use-genserver-instead-sync-threads branch from b02dfab to 04b4e2c Compare December 12, 2025 15:28
@lakshya-sky
Copy link
Contributor Author

Hey @ElFantasma, I've pinned the revision of the spawned for now. Might be better to wait for the create to be released.

Comment on lines 2443 to 2444
// NOTE: we don't receive `Store` here to avoid cyclic dependencies
// with the other end of `fkv_ctl`
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's move this as a footnote to the bigger comment. With the changes it looks strange.

Comment on lines 3282 to 3284
let _ = std::thread::spawn(move || {
let mut cancellation_token = handle.cancellation_token();
loop {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused, with the new actor shouldn't this be handled by spawned? I thought the goal would be for the worker implementation to only need to worry about the loop body.

Copy link
Contributor Author

@lakshya-sky lakshya-sky Dec 15, 2025

Choose a reason for hiding this comment

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

Async tasks Genserver uses spawn_listener but here the sync version doesn't have it implemented https://github.com/lambdaclass/spawned/blob/7af72c4ce40eab8b22d33b3302e9da9229319dc0/concurrency/src/threads/stream.rs#L8C1-L17C2 that's why.
Might be a good idea to implement spawn_listener in the upstream. But the function signature of the spawn_listener relies on Stream and the close one I was able to think is IntoInterator. e.g. fn spawn_listener(handle: .., iter: impl IntoIterator<Item = T::CastMsg>) but I was not sure about that change.

Maybe you and @ElFantasma can share some suggestion to implement spawn_listener.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Raised a PR lambdaclass/spawned#66 which should allow to write

fn init(
        self,
        handle: &spawned_concurrency::threads::GenServerHandle<Self>,
    ) -> Result<Self, Self::Error> {
        let handle = handle.clone();
        let rx = self
            .trie_upd_rx
            .clone()
            .into_iter()
            .map(|u| Self::CastMsg::TrieUpdates(u));

        spawn_listener(handle, rx);
        Ok(self)
    }

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.

Use spawned sync (thread) version of GenServer for our synchronic theaded code.

2 participants