Need to prioritize asynchronous socket reading in C #

My application pre-selects a large number of video frames using asynchronous HttpWebRequest Requests. So, if there are 100 frames, the prefetcher will request all 100 frames asynchronously, immediately and process when they return. that is, it makes 100 asynchronous calls at the same time. This may saturate the network but this is normal. I want to maximize network bandwidth.

However, while this prefetching is in progress, the user may want to view one of the frames. So, let's say they want to view frame 56. The problem is that frames 1 - 100 are already requested and are in the pipe, so the request for frame 56 can take a long time to get an answer.

Which would be nice if there is some way to redirect asynchronous requests after they are created. And push the user’s request to the front of the queue.

If I cannot do this, I assume that I will have to request packages in packages so that I can skip my user request between batches and avoid a timeout.

Any ideas on how to do this correctly would be greatly appreciated.

+6
source share
2 answers

This is not a programming issue, but a protocol issue. If you use a greedy protocol that saturates the wire, you actually close even your own parameters using traditional protocols.

If you reserved part of the bandwidth for the second channel, you can use this second channel for individual frames instead of packet frames. To prioritize frames in the second channel in the presence of a saturated network adapter, you need a quality of service or some other level of communication to prioritize traffic.

But we are ahead of ourselves. If you want to have a full-fledged functional application, you need to sit down and determine the real protocol with the advice of the protocol experts: network adapters, switches, protocols, packet sizes, try again, etc. Once you figure it all out, you get a programming problem.

+1
source

And, I would use a priority queue or a bunch to process the "packets" of frames. Since you do not need a timeout, and you also want speed, create frame packets (two in size capacity) and associate them with priority (maybe 0 for not being requested, 1 for the requested user?). Thus, packets with the highest priority (requested by the user) will always be in front of the queue or the top of the heap.

0
source

Source: https://habr.com/ru/post/887987/


All Articles