FIX for high cpu usage


#1

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))
                        ewh.WaitOne();

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());
ewh.Set();

and


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

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


#2

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


#3

I’ve installed 1.4 and it’s using 36-45% of my cpu, even when I’m not playing any music. I also don’t see any recent activity on the Forum. If Sebastien is no longer doing development, perhaps “slash” above could produce a version with the fix?


#4

same here : SWYH using 35% of CPU, resulting in music played sometimes freezing or lagging
do you have a fix for that that us newbies could use ?
thanks in advance:)