locked
Inter process communication using Windows service and named pipes (slow, memory not disposed, high CPU load)? RRS feed

  • Question

  • I created a Windows service that opens a named pipe to receive data from an external application. Latter one connects and transfers up to 250 MB of data via a named pipe after it serialized a LIST of objects.

     

    My windows service deserializes the data back into a LIST of objects, processes them and outputs the entire list into a file.

     

    My issues are:

     

    1. The data transfer is extremely slow! 200 MB take about 7 minutes via named pipe vs. 20 seconds if a file is used. 
      QUESTION: is it possible to speed up the data transfer somehow?
    2. After my Windows service based processing is done I dispose the named pipe, clear the list and even call GC.Collect() but still my service is not releasing the memory.
    3. Also I continue to have very high CPU load (98%) on all cores (2xQuad-core) although the service is not doing anything.

     

    It would be great if somebody could advise me on some of the points.

    Thanks,

    Dirk

     

    Thursday, September 23, 2010 2:52 PM

All replies

  • Hi DirkLX,

     

    Welcome to MSDN forums!

    I think the speed of Windows Service may relate to resources on your computer, simplistically there are four types of resources that can affect your overall ability to get work done:

    1. Memory (RAM)

    2. CPU

    3. Disk I/O

    4. Network I/O

    About Windows Service question, I hope you have read this article:

    http://msdn.microsoft.com/en-us/library/d56de412(v=VS.100).aspx

    A service goes through several internal states in its lifetime. First, the service is installed onto the system on which it will run. This process executes the installers for the service project and loads the service into the Services Control Manager for that computer.

    A running service can exist in this state indefinitely until it is either stopped or paused or until the computer shuts down.

    You can pause, stop, or resume a service from the Services Control Manager, from Server Explorer, or by calling methods in code. Each of these actions can call an associated procedure in the service (OnStop, OnPause, or OnContinue), in which you can define additional processing to be performed when the service changes state.

     

     

    Hope these helps, if you have any problems, please feel free to let me know.

     

    Best Regards,

    Alan Chen

    ________________________________________

    Please remember to mark the replies as answers if they help and unmark them if they provide no help

    • Marked as answer by Alan_chen Wednesday, October 6, 2010 1:02 AM
    • Unmarked as answer by DirkLX Wednesday, October 20, 2010 10:45 AM
    Monday, September 27, 2010 5:51 AM
  • please post a sample of your project to let us provide u  with  the right solution
    A man's dreams are an index to his greatness
    Monday, September 27, 2010 7:16 AM
  • please post a sample of your project to let us provide u  with  the right solution
    A man's dreams are an index to his greatness

    All right then, here it comes. Please see my comments as well and thanks for your help!
    Dirk

     

      // this is part of my Windows Service. I want latter one to sit and wait for data which is crunched afer retrieval.
      // it should be possible to transfer 250MB or more without problesm or else named pipes are not for me
      // also I can write and read a 250MB text file in about 50 seconds so I would like to get similar performance form pipes
      // afterall I tried to come up with a more elegant solution then transfering files.
      public PipeClient(string ServiceDirectory)
      {
    
        var pipeClient = new NamedPipeClientStream(".", "pipe", PipeDirection.In, PipeOptions.WriteThrough);
        try
        {
    
          //no timeout causes hight CPU load, timeout makes for only one connection?
          pipeClient.Connect();
    
          // it does not create the CPU load if called with timeout e.g. 
          // pipeClient.Connect(5000) but in that case only runs 1 time?
    
          var fmt = new BinaryFormatter();
          ResultCollection = (List<DTTimeSeries>)fmt.Deserialize(pipeClient);
    
    
          if (ResultCollection != null)
            CreateAnalysis();
    
    
          string tag = DateTime.Today.Year.ToString() + DateTime.Today.Month.ToString() +
                  DateTime.Today.Day.ToString() + DateTime.Now.Hour.ToString() +
                  DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
    
    
          ExportTimeSeriesData(String.Format("{0}\\Out_{1}.txt", ServiceDirectory, tag));
    
    
        }
        catch (IOException e)
        {
          pipeClient.Close();
          pipeClient.Dispose();
        }
        finally
        {
          if (pipeClient != null)
          {
              
            pipeClient.Close();
            pipeClient.Dispose();
          }
        }
      }
    
    
    // TEST case
    //*******
        var pipeServer = new NamedPipeServerStream("pipe", PipeDirection.Out, 1, PipeTransmissionMode.Byte, PipeOptions.WriteThrough, 64000, 64000);
        try
        {
    
          pipeServer.WaitForConnection();
          Console.WriteLine("Client connected.");
    
          ImportTimeSeriesData("C:\\DEV\\CoreServices.ExternalProcessing\\Data\\8000.txt", '\t');
    
    
          var fmt = new BinaryFormatter();
          fmt.Serialize(pipeServer, ResultCollection);
    
          Console.WriteLine("received it");
          pipeServer.Close();
        }
        finally
        {
          if (pipeServer != null)
          {
            pipeServer.Close();
            pipeServer.Dispose();
          }
        }
      
      }
    
    
    Monday, September 27, 2010 10:15 AM
  • Hi DirkLX,

    I write a service program about IPC using mailslot,but it does not work.Do you know how to solve it,the problem description in this link:http://social.msdn.microsoft.com/Forums/en-US/a39f8925-f228-43e3-8e19-0412102e4b36/how-to-write-a-windows-service-program-that-can-communicate-with-another-process-using-mailslot?forum=wcf

    Thursday, May 22, 2014 3:46 AM