.NET 2.0 Real Time Requirements

Hi.

Probably .NET 2.0 and realt time requirements shouldnt be on the same sentence.

I'm trying to control a machine that set's me some real time requirements, the machine fires events,  inside those events I have to do some processing. On one of them I have less than 200ms to performs the work that I need. 200ms is already very thight I cant waste more than 180ms. Per minute I have fired at least 120 of these events I have to handle all of them and can't stay on them for longer than 180 ms.

My question is, is the .NET Framework suited to this kind of work

Another thing that I must say to help on the discussion, if I waste more than 180ms the machine stops, and that can't happen I really have to meet the time!!!

Even if I use threads to perform the operations creating 120 threads per minute, they aren't needed after a few miliseconds, wouldn't that put a lot of processing on the CLR Meaning someone have to collect all of that isn't it

Thanks in advance for any help.

Best regards

 

LS

p.s The architecture that I have is a external machine connected to the PC, that machine reads documents, throw events to the PC and the PC have to handle that information and perform some operations per each document.



Answer this question

.NET 2.0 Real Time Requirements

  • casfus

    Hi.

    Thank you for your answer.

    When I mean event, that's whate the device driver do, it sends events.

    I "can't" buffer, because between per each document are fired five events. On the second event I have to tell the device driver that the document have to be sent to a given destination, so I have to perform some processing on at least two of the 5 events. When I have a error I must notify the user :) that's simple.

    Is there a way so that I can see how many threads are executing on a given time I guess that I need a profiler, does anyone know of such a tool for the .net framework, or do I have to use the profiling API and made my own profiling tool

    Thanks in advance for any help.

    Best regards

    Luis de Sousa


  • Jonathan Rajotte

    Hi.
    You wrote about a couple of things that I wasn't aware. The list that you have on the end of the email is very important for me since there were a couples of things that I wasn't aware of.
    I'll try to check my code again to see how can I improve my code.

    The machine operators are not endangered, by this application, so we can use .net and windows. It seems that we have to pay attention to more things, than usually.

    Best regards

    Luis de Sousa

  • cbpd86

    Hi Luis

    The GC will only perform a collection under three conditions:

    1) Allocation exceeds the Gen0 threshold;

    2) System.GC.Collect is called;

    3) System is in low memory situation;

    That means RemoveAt() will not directly trigger a collection, but allocating an object may.

    See http://blogs.msdn.com/maoni/archive/2004/06/15/156626.aspx for more information.

    Hope that helps

    -Chris


  • feby

    You are focusing on the wrong solution here. It doesn't matter how fast the code runs, you can always fix that. What matters is how deterministic it runs. You are dead in the water when your code takes 5 msec 100,000 times in a row but takes 250 msec once. This is going to happen when the garbage collector happens to kick in while processing an event, just as the virus scanner starts a scan, just as the network card receives a burst of traffic, just as the operator bumps the mouse while typing a key.

    You are running a non-deterministic framework on top of a non-deterministic operating system. You'll never be able to guarantee 100% response compliance but you can get to 99.99%. Whether that is acceptable depends on the economic loss. If the machine operators safety is endangered you can absolutely not use .NET nor Windows. To get to 99.99% (or however many nines you need), you'll have to include exhaustive stress testing in your project plan.

    Things you can do to get a lot of nines:
    - Avoid allocating objects while processing events
    - Detect events with a high-priority thread that blocks on a kernel object
    - Isolate the PC from the network with a switch and hardware firewall
    - Remove as much unnecessary software as possible from the OS
    - Lock down the PC so nobody can mess with it.



  • Ranjit Thayyil

    Hi Chris.

    It helped a lot, thanks for the link to the blog, it have a lot of usefull information.
    I would like to thank to all the others that answered on this thread, your post gave me aditional information that I needed.
    Now it's up to me to do my homework and refactor my code.

    Best regards

    Luis de Sousa



  • Martin Odhelius

    Hi again.

    I found a couple of things that need to be changed.

    In order to do the modifications I need to understand how the garbage collector works. What I mean here, is something like this.
    I have a buffer, that's an ArrayList, and in one of the Events I was allocating one position on it.
    I do something like this: myArrayList.Add(MyObject); on one event, this object have a size of lets say, 60KB, but the objects will be bigger, because on larger documents the image will ocupy more space.
    On other Event I know that I must remove the first element of the ArrayList, with something like
    myArrayList.RemoveAt(0);
    In the mean time I know that other items were added to the ArrayList.

    My question is, when I perform the operation to remove the first item from the ArrayList the GC will perform any collect Or it will wait until we don't have free space on the heap to perform this operation I guess that we also must pay attention to some implementation details of the ArrayList, any tips

    Thanks in advance, best regards

    Luis de Sousa

  • Bern McCarty

    I'm a huge fan of .NET, but I'm not sure it's a good solution for this application. What do you mean by saying that the hardware "throws events" to the PC Have you thought about buffering this incoming data rather than trying to process it all in real-time



  • wgwolf

    I used to work with a device that fire ~180 events a second. Each event had a bitmap data ~300kb size that needed to be copy from the h/w to the heap. Then it was processed. I could not affort loss of data at all cost. I did it 4 years ago with .NET 1.0.

    Today with .NET 2.0 it will perform much better.

    You only need to process 5.5 events a second. You defintly can use .NET for this. Farther, you can take a look on mPrest MCore which is a realtime application server based on .NET.

    www.mprest.com

    Best Regards,

    Ido Samuelson

    http://blogs.microsoft.co.il/blogs/samuelson



  • M Parker

    Hi Ido,

    First I would like to thank you for your answer.

    I found very useful information  on your blog about writting a real time application with the .net framework.

    I quoted the text bellow from the article that I found on Rico Marianis blog and I have a question.

    "Interop with Native

    Just a few words here, again you can shoot yourself in the foot

    • Keep your interop under control 
    • Use primitive types in the API whenever possible
      • Marshalling costs are what will kill you
    • Simple calls can be very fast 
      • Desktop CLR can get many millions of calls per second on simple signatures
    • Native Interop is not possible on the Xbox 360"

    A made the sentence with Marshalling Bold, because I have this on my code, since I need to perform some kind of native interop to communicate with the Hardware.

    I give a few samples of we have at this moment:

    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]

    public Int32[] procarg;

    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]

    public UInt16[] Height;

    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]

    public Byte[] ResolutionX;

    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]

    public Byte[] ResolutionY;

    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]

    public Byte[] Brightness;

    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]

    public Byte[] Contrast;

     

    Here I'm using some Marshal, not all the code use this, this is just a sample. Since you point that this can hurt the performance, do you, or anyone have some information of what MasrshalAs actually do

    Should I perform the Native Interope using C++/CLI and try to have some performance increase by doing that

    Once again thanks in advance for the help.

    Best regards

     

    Luis de Sousa

    p.s. I have just one more question regarding your server mPrest MCore, with this you collect the information from the hardware, but you were just collecting it to the computer, or you were also performing more operation while collecting the data, like performing queries, updating a UI


  • .NET 2.0 Real Time Requirements