OSC Receiver Performance Issue

Dear JUCE team,

thanks for the new OSC feature, very useful!

While testing it I realized the OSCReceiver thread fills up pretty much all of a CPU core because it constantly tries to read data from the socket, even though no new data arrived.

I don't know wheter the following is the right approach to fix it, but adding a socket->waitUntilReady(true, 1000) in juce_OSCReceiver.cpp does the job for me.

Best, Matthias


void run() override
    {
        while (! threadShouldExit())
        {
            jassert (socket != nullptr);
            char buffer[oscBufferSize];
            socket->waitUntilReady (true, 1000);
            
            const int bytesRead = socket->read (buffer, (int) sizeof (buffer), false);
            if (bytesRead >= 4)
                handleBuffer (buffer, bytesRead);
        }
    }

 

Hi,

Interesting. Could you please try instead the following code and tell us if that does the job, too?

void run() override
{
    while (! threadShouldExit())
    {
        jassert (socket != nullptr);
        char buffer[oscBufferSize];

        const int bytesRead = socket->read (buffer, (int) sizeof (buffer), true);

        if (bytesRead >= 4)
            handleBuffer (buffer, bytesRead);
    }
}

Hi Timur,

no, this does not work as read in this case only returns if the received OSC message is the size of oscBufferSize, which is practically never.

I tested the behavior of the original code under OSX and Windows on different machines, and it fills up one cpu core on both machines. (This is for the included examples as well as my own application.) Therefore currently unusable, or am I the only one having this problem?

Best, Matthias

OK, I fixed the issue now, please update to the newest tip.