RethinkDb.Driver icon indicating copy to clipboard operation
RethinkDb.Driver copied to clipboard

Use new System.IO.Pipelines API / Project Bedrock

Open bchavez opened this issue 7 years ago • 6 comments

Benefits

  • Pooled memory management reducing allocations.
  • Instead of current message pump design of pulling/pushing bytes out of a NetworkStream and using CancellationTokenSource; we can leverage some of the low-level network code that ASP.NET Core is using.
  • Should allow us to consolidate/delete a lot of code in SocketWrapper.cs.
  • Should help us get the best performance out of the driver from the network when implementing #77.

Disadvantages

  • Requires .NET Core 2.1 (I think)

References

  • ASP.NET Community Standup - May 1, 2018 - SignalR and Project Bedrock with David Fowler https://www.youtube.com/watch?v=ySmUI8O1Rog

  • Microsoft Build 2018: 1:15 PM | Meet the new stack for real-time web communication: ASP.NET Core SignalR https://www.youtube.com/watch?v=u0_vkWYYXRc https://channel9.msdn.com/Events/Build/2018/BRK2147

  • Links: https://blogs.msdn.microsoft.com/dotnet/2018/04/18/performance-improvements-in-net-core-2-1/ https://blog.marcgravell.com/2018/07/pipe-dreams-part-3.html

  • Related #77

bchavez avatar May 09 '18 02:05 bchavez

Pipelines ships out of the box with Core 2.1, but I "think" you can pull in the NuGet package in .NET Standard 2.0 supported projects.

There's this package, but I haven't tried it yet.

cecilphillip avatar May 16 '18 14:05 cecilphillip

Thanks @cecilphillip ! The package link is really helpful. I didn't realize the package was on NuGet already.

After checking the Dependencies section on the NuGet page, I found it really intresting that Pipelines supports .NET Framework 4.6. Do you know if Pipelines really works on .NET Full Framework 4.6? I thought some of these Span<T> and System.IO.Pipeline optimizations required underlying support from the runtime? It would be really cool if it worked on 4.6 Full Framework.

chrome_1615

Thanks for dropping the info Cecil!

:car: :blue_car: "Let the good times roll..."

bchavez avatar May 16 '18 16:05 bchavez

Looks like Span<T> can be made available in 4.6.1 via System.Memory which is a dependency of System.IO.Pipelines.

cecilphillip avatar May 17 '18 00:05 cecilphillip

Thanks @cecilphillip .

Also, found some additional info: http://adamsitnik.com/Span/#how-does-it-work

How does it work? There are two versions of Span:

  • For the runtimes existing prior to Span.
  • For the new runtimes, which implement native support for Spans.

https://github.com/dotnet/corefxlab/blob/master/docs/specs/span.md#designrepresentation

We will provide two different implementations of Span<T>:

  • Fast Span<T> (available on runtimes with special support for spans)
  • Slow Span<T> (available on all current .NET runtimes, even existing ones, e.g. .NET 4.5)

Seems like, as far as the runtime is concerned, there are two versions of Span<T>, 1) one for runtimes that have native Span support (eg .NET Core) and 2) one for older runtimes that don't have native support (eg .NET Full Framework 4.6). I'm guessing having two different Span<T> implementations is how Span<T> is made compatiable with older runtimes.

bchavez avatar May 17 '18 04:05 bchavez

@bchavez Hi Brian, Our project is in .NET framework 4.6.1. So are you stating that System.IO.Pipelines cannot be used in 4.6.1 and works as intended only in .Net core 2.1?

Any inputs would be really helpful. I have been trying a few demos, but all of them stops me at some step where the given method is not available in 4.6.1.

Thanks!

francisminu avatar Aug 01 '18 15:08 francisminu

Hi Minu,

My current understanding is that System.IO.Pipelines should work in both .NET Core and Full Framework (4.6.1). I have not personally tried System.IO.Pipelines in either runtime yet.

The only difference is when your app (or its dependencies) use the namespace System.IO.Pipelines on .NET Core, the runtime is better optimized for System.IO.Pipelines Span operations. The links I've posted above should contain enough background information about the System.IO.Pipelines implementation.

The only thing I can suggest is making sure all your dependencies are up to date. Even go so far as testing Full Framework 4.7.2 and see if it works there. If it still doesn't work then, I wouldn't have the slightest clue... something else must be wrong.

The discussion here is mostly reserved for System.IO.Pipelines as it relates to the C# RethinkDB driver. If you need more help, maybe posting a question on Stack Overflow or .NET's Slack channel might help. But thanks for giving us the heads up to double check the 4.6.1 implementation.

Thanks, Brian

bchavez avatar Aug 01 '18 16:08 bchavez