rust-libp2p icon indicating copy to clipboard operation
rust-libp2p copied to clipboard

feat(swarm): keep Connections on the same Task

Open dignifiedquire opened this issue 3 years ago • 6 comments

We now upgrade a PendingConnection on the same Task, instead of moving it back to the main Task, and spawning another one.

@mxinden this is a first pass at what we talked about, in regards to keeping the connection on a single task once established.

Depends on #2535

dignifiedquire avatar Feb 24 '22 15:02 dignifiedquire

Mind splitting the PR in two? https://github.com/libp2p/rust-libp2p/pull/2536/commits/0c5fa28b5a97276cb4ccbb9335b6588253d551e7 we can merge soon. https://github.com/libp2p/rust-libp2p/pull/2536/commits/88cc599dfde60cecc06dd827dfc1add4c1be54ef I want to give a bit more thought.

mxinden avatar Feb 24 '22 17:02 mxinden

@mxinden https://github.com/libp2p/rust-libp2p/pull/2535

dignifiedquire avatar Feb 24 '22 18:02 dignifiedquire

Thanks @dignifiedquire ! Do you mind adding some rationale on why this is better? :)

Is it supposedly easier to understand? Less susceptible to certain error conditions? Better encapsulation?

thomaseizinger avatar Feb 28 '22 22:02 thomaseizinger

Is it supposedly easier to understand? Less susceptible to certain error conditions? Better encapsulation?

The idea of doing this, arose from me working on trying to integrate rust-libp2p with https://github.com/DataDog/glommio/. With that executor, connections are not necessarily Send, and so I was piece wise figuring out how to avoid moving things between threads. With this change, in theory, a connection can be guranteed to be kept on a single thread after having been spawned (assuming that is what the executor does of course).

dignifiedquire avatar Mar 01 '22 14:03 dignifiedquire

Thanks for that!

I'll have a look with that in mind later :)

thomaseizinger avatar Mar 01 '22 21:03 thomaseizinger

I think in principle, I am okay with this direction.

The idea of doing this, arose from me working on trying to integrate rust-libp2p with DataDog/glommio. With that executor, connections are not necessarily Send, and so I was piece wise figuring out how to avoid moving things between threads.

Does this mean, only the final connection is !Send but the task for creating the connection is Send? With https://github.com/libp2p/rust-libp2p/pull/2652, we will be emitting individual "upgrade" futures from a Transport (and Transport will no longer be Clone). Consequently, there will be a task that polls the underlying transport but the upgrade will be put into its own task which might be on another thread.

thomaseizinger avatar Jun 03 '22 07:06 thomaseizinger

This pull request has merge conflicts. Could you please resolve them @dignifiedquire? 🙏

mergify[bot] avatar Jan 02 '23 00:01 mergify[bot]

This pull request has merge conflicts. Could you please resolve them @dignifiedquire? 🙏

mergify[bot] avatar Mar 04 '23 00:03 mergify[bot]

I guess we can close this as stale.

thomaseizinger avatar May 07 '23 20:05 thomaseizinger