FIX for high cpu usage

Home Forums Forum English (EN) FIX for high cpu usage

This topic contains 1 reply, has 1 voice, and was last updated by  R0G 11 months, 2 weeks ago.

  • Author
  • #11773 Reply


    Hi Sébastien,
    you are using a busy loop and therefore blocking a whole core. See

    private void PageHandler(OpenSource.UPnP.UPnPDevice sender, OpenSource.UPnP.HTTPMessage msg, OpenSource.UPnP.HTTPSession WebSession, string VirtualDir) {
    // ...
    while (!sessionMp3Streams.TryRemove(s.SessionID, out value)) ;;

    A quick fix is to use wait handlers. Change the loop to

    while (!sessionMp3Streams.TryRemove(s.SessionID, out value))

    and declare

    private static EventWaitHandle ewh = new EventWaitHandle(false, EventResetMode.AutoReset);

    After writing to sessionMp3Streams use ewh.Set(); E.g.

    PipeStream stream = sessionMp3Streams.GetOrAdd(WebSession.SessionID, new PipeStream());


    Parallel.ForEach<PipeStream>(sessionMp3Streams.Values, (p, s, l) =>
         p.Write(bufferMp3, 0, bytesRead);

    Now the usage is at most 3% instead of 100%…

    #11802 Reply


    Can this be fixed Sébastien? Experiencing problems as well.

Reply To: FIX for high cpu usage
Your information:

+ 54 = 63

Posted in