Giter Site home page Giter Site logo

UDP Sockets about pipelines.sockets.unofficial HOT 23 OPEN

mgravell avatar mgravell commented on September 21, 2024 1
UDP Sockets

from pipelines.sockets.unofficial.

Comments (23)

mgravell avatar mgravell commented on September 21, 2024

from pipelines.sockets.unofficial.

softworkz avatar softworkz commented on September 21, 2024

I did.

To make it work in general it requires just a single line change:

var buffer = _receiveFromSocket.Writer.GetMemory(1);

Needs to be changed to this:

var buffer = _receiveFromSocket.Writer.GetMemory(this._receiveOptions.MinimumSegmentSize);

And ZeroLength reads must not be used.

But overall it didn't perform very well due to the frequent flushing (= after each receive).

With UDP, the data doesn't get accumulated in the buffer. You get a single datagram with each receive call. And that causes too many async calls which are becoming a performance issue with high data rates.

from pipelines.sockets.unofficial.

Drawaes avatar Drawaes commented on September 21, 2024

I'll be honest as a big user of UDP and a user of pipelines I had considered it. However as Marc said it doesn't make a lot of sense in this case, you completely lose the framing of the datagram so then you need to implement framing over the top, at which point I question if you are rewriting tcp over UDP.

from pipelines.sockets.unofficial.

softworkz avatar softworkz commented on September 21, 2024

No, the framing doesn't get lost as mentioned above because in case of UDP you always get a single datagram with each receive call. In my case, a datagram contains n packets of size x with x being a global constant. Packets are not sliced across datagrams.

Maybe I should say that this is about media streaming. Several protocols in this area are UDP based and the challenge is to find the most effective implementation.

Arguing about protocol design and choice is a dead end in this case.. :-)

from pipelines.sockets.unofficial.

mgravell avatar mgravell commented on September 21, 2024

To me, UDP seems more like a Channel<ReadOnlySequence<byte>>. Perhaps that's something that we could implement with minimal work, giving you all the benefits without the pain, and respecting the framing differences between UDP and TCP.

Happy to explore that area. I've mostly been TCP focused, but I love expanding my horizons...

from pipelines.sockets.unofficial.

Drawaes avatar Drawaes commented on September 21, 2024

Which was exactly the discussion I had with Fowler around UDP. I suspect it's not on the pipelines asp.net radar yet either (maybe quic will change that)

from pipelines.sockets.unofficial.

softworkz avatar softworkz commented on September 21, 2024

What do you mean by Channel<ReadOnlySequence> ?
Wasn't 'Channel' the initial term before it became 'Pipeline'?

from pipelines.sockets.unofficial.

Drawaes avatar Drawaes commented on September 21, 2024

System.Threading.Channels made around the same time as pipelines (which maybe why pipelines was renamed... But that's just a rumour 😀)

from pipelines.sockets.unofficial.

mgravell avatar mgravell commented on September 21, 2024

Channel<T> is the high perf reader-writer async queue thing. Yes, the name was also the early name of pipelines, but pipelines lost and became pipelines. Related and overlapping topic, and I do think it would make a good API here, for packet-based rather than stream-based protocols.

from pipelines.sockets.unofficial.

softworkz avatar softworkz commented on September 21, 2024

That sounds really interesting, every time I read about channels somewhere I thought it was about the early pipeline stuff.

Too bad that it doesn't seem to support netstandard2.0 (need to support BSD as well)

from pipelines.sockets.unofficial.

mgravell avatar mgravell commented on September 21, 2024

Channels and pipelines are both netstandard 1.3+; you're fine

from pipelines.sockets.unofficial.

softworkz avatar softworkz commented on September 21, 2024

So, it's not yet documented as such?

Or is that the wrong place: https://docs.microsoft.com/en-us/dotnet/api/system.threading.channels.channel-1?view=dotnet-plat-ext-2.1&viewFallbackFrom=netstandard-2.0

from pipelines.sockets.unofficial.

mgravell avatar mgravell commented on September 21, 2024

Nuget: https://www.nuget.org/packages/System.Threading.Channels/ - click dependencies

from pipelines.sockets.unofficial.

softworkz avatar softworkz commented on September 21, 2024

Thanks a lot, I'll look into it!

from pipelines.sockets.unofficial.

mgravell avatar mgravell commented on September 21, 2024

In fact, maybe a case could be made for IAsyncEnumerable<ReadOnlySequence<byte>> - I will have to play!

from pipelines.sockets.unofficial.

softworkz avatar softworkz commented on September 21, 2024

Think about small packet sizes and a huge amount of them :-)

from pipelines.sockets.unofficial.

softworkz avatar softworkz commented on September 21, 2024

Don't forget to add a running number when sending udp datagrams for testing.
You need to make sure that you're getting them all.

Mine are about 25k size, I tried to get close to half of the maximum allowed (64k).
The smaller I made the datagrams the worse it got (CPU usage).
(it's a real world application - that means: half datagram size => double amount of datagrams per time)

PS: Watch your e-mail, I can provide some more interesting details if you wish

from pipelines.sockets.unofficial.

mgravell avatar mgravell commented on September 21, 2024

Started a spike with this. Looking viable. A running number in the lib would be pointless - it can't tell if it didn't get a packet. Hence IMO any running number must be part of your payload, not the code that makes things work.

If you mean a running number in test code: sure, absolutely.

from pipelines.sockets.unofficial.

softworkz avatar softworkz commented on September 21, 2024

Yes, of course I meant a number inside the payload for testing.

from pipelines.sockets.unofficial.

sebandraos avatar sebandraos commented on September 21, 2024

Did anything come of this discussion? I can see a UDP branch but it doesn't seem like it ever got merged into master. Was an alternative to that branch implemented instead? Thanks

from pipelines.sockets.unofficial.

mgravell avatar mgravell commented on September 21, 2024

from pipelines.sockets.unofficial.

sebandraos avatar sebandraos commented on September 21, 2024

Ok, cool thanks.

from pipelines.sockets.unofficial.

sgf avatar sgf commented on September 21, 2024

The TCP protocol performs very badly in the case of a wide geographical distance around the world.
UDP is controlled by appropriate high-level algorithms to achieve an ideal low latency.

from pipelines.sockets.unofficial.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.