Click here to Skip to main content
14,356,475 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
 
GeneralRe: Some thoughts on the .net CLR/CLI Pin
honey the codewitch15-May-19 4:37
memberhoney the codewitch15-May-19 4:37 
GeneralRe: Some thoughts on the .net CLR/CLI Pin
Member 798912215-May-19 4:30
memberMember 798912215-May-19 4:30 
GeneralRe: Some thoughts on the .net CLR/CLI Pin
honey the codewitch15-May-19 4:35
memberhoney the codewitch15-May-19 4:35 
GeneralRe: Some thoughts on the .net CLR/CLI Pin
Member 798912215-May-19 4:39
memberMember 798912215-May-19 4:39 
GeneralRe: Some thoughts on the .net CLR/CLI Pin
honey the codewitch15-May-19 5:05
memberhoney the codewitch15-May-19 5:05 
GeneralRe: Some thoughts on the .net CLR/CLI Pin
johannesnestler15-May-19 5:28
memberjohannesnestler15-May-19 5:28 
GeneralRe: Some thoughts on the .net CLR/CLI Pin
honey the codewitch15-May-19 6:15
memberhoney the codewitch15-May-19 6:15 
GeneralRe: Some thoughts on the .net CLR/CLI Pin
Gerardo Orozco15-May-19 7:32
memberGerardo Orozco15-May-19 7:32 
Hi!

Let me share with you the techniques we have used to go around some of the drawbacks you describe.
Our solution is consuming a LARGE amount of UDP traffic (MPEG2 streams) - over 200Mbps of data. It is also performing some heavy DSP processing and it taxes the garbage collector heavily.

Being UDP and with no retransmission protocol available - we are very sensitive to reading the data on time if we want to keep the quality of the video streams high. Reading the UDP traffic with managed code was a disaster.
Basically, we are taking advantage of the fact that an unmanaged thread is NOT suspended during garbage collection.

1. We used C++/CLI to write the multicast UDP reader code inside a non-managed class. We ensure that the CLR support is disabled for the .cpp file implementing the code that we don't want to be interrupted during garbage collection. This makes sure that the code is compiled to native code, otherwise it may get compiled to IL code and the unmanaged thread may be blocked once it transitions to IL space. Even if using the unmanaged pragma, the compiler creates managed thunks around the unmanaged code and we want to avoid IL completely for this generated code. The unmanaged thread that is reading the UDP traffic (using RIO for higher performance) runs inside this class. Note that unfortunately we can't take advantage of the .Net framework in this class, so we rely on Boost.

2. We keep the unmanaged code as simple as possible, basically we loop reading UDP packets and enqueue them. However, we make sure that we use a lockless queue for this purpose (we use a Boost lockless queue). This is vital because there will be a managed thread consuming the queue, bridging the data onto the managed world. This consumer thread will be suspendend during GC activity and we don't want the thread to be suspended while holding a lock for the queue (otherwise the unmanaged thread may block contending for the lock). Another plus is that using a lockless queue, we become immune to thread priority inversion, so we can boost the producer thread priority to the highest level possible.

3. Using C++/CLI we produce a .net friendly class. This class owns and instantiates the unmanaged class, and also implements the managed queue consumer thread. (It can seamlessly consume the Boost lockless queue and expose the unmanaged memory (the udp packets) in a managed friendly way. Now, no matter if the managed world is suspended, the unmanaged thread will keep filling the lockless queue.

We also tuned some relevant NIC parameters, and by using these techniques, we can proudly say we are losing less than 0.001% of the packets (when we were losing around 8% of the packets with our initial, purely-managed solution).

I think I may actually write an article (my first) on this technique. It may be useful to others.
Feel free to contact me if you want to try this approach!
Cool | :cool:
GeneralRe: Some thoughts on the .net CLR/CLI Pin
honey the codewitch15-May-19 9:05
memberhoney the codewitch15-May-19 9:05 
Generalstuck with .NET Core Pin
honey the codewitch14-May-19 3:22
memberhoney the codewitch14-May-19 3:22 
GeneralRe: stuck with .NET Core Pin
OriginalGriff14-May-19 3:34
protectorOriginalGriff14-May-19 3:34 
GeneralRe: stuck with .NET Core Pin
honey the codewitch14-May-19 3:38
memberhoney the codewitch14-May-19 3:38 
GeneralRe: stuck with .NET Core Pin
OriginalGriff14-May-19 3:53
protectorOriginalGriff14-May-19 3:53 
GeneralRe: stuck with .NET Core Pin
honey the codewitch14-May-19 4:00
memberhoney the codewitch14-May-19 4:00 
GeneralRe: stuck with .NET Core Pin
Eddy Vluggen14-May-19 5:17
mveEddy Vluggen14-May-19 5:17 
GeneralRe: stuck with .NET Core Pin
honey the codewitch14-May-19 5:22
memberhoney the codewitch14-May-19 5:22 
GeneralRe: stuck with .NET Core Pin
Sander Rossel14-May-19 10:10
professionalSander Rossel14-May-19 10:10 
GeneralRe: stuck with .NET Core Pin
RickZeeland14-May-19 3:34
mveRickZeeland14-May-19 3:34 
GeneralRe: stuck with .NET Core Pin
Kornfeld Eliyahu Peter14-May-19 3:40
mveKornfeld Eliyahu Peter14-May-19 3:40 
GeneralRe: stuck with .NET Core Pin
honey the codewitch14-May-19 3:43
memberhoney the codewitch14-May-19 3:43 
GeneralRe: stuck with .NET Core Pin
OriginalGriff14-May-19 3:55
protectorOriginalGriff14-May-19 3:55 
GeneralRe: stuck with .NET Core Pin
honey the codewitch14-May-19 3:58
memberhoney the codewitch14-May-19 3:58 
GeneralRe: stuck with .NET Core Pin
OriginalGriff14-May-19 4:28
protectorOriginalGriff14-May-19 4:28 
GeneralRe: stuck with .NET Core Pin
honey the codewitch14-May-19 4:32
memberhoney the codewitch14-May-19 4:32 
GeneralRe: stuck with .NET Core Pin
OriginalGriff14-May-19 5:05
protectorOriginalGriff14-May-19 5:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.