MirageNet / WebsocketNG

Websocket transport for MirrorNG
MIT License
1 stars 1 forks source link

High CPU usage when using ClientRPC #9

Open OneFirefly opened 3 years ago

OneFirefly commented 3 years ago

mutex_eating_cpu

I just profiled my application in server only mode with 4 remote clients ClientRPCs seem to be blocking due to mutexes (see image) - The profiled Ping method is a ClientRPC and there are others like this that block > 3ms. Those ClientRPCs usually have not more than 1 primitive parameter (e.g. int)

OneFirefly commented 3 years ago

Fix is:

replace: https://github.com/MirrorNG/WebsocketNG/blob/616049c7a860a7bb1a753af9ab38c0bbe79b5b99/Assets/Mirror/Websocket/Common/SendLoop.cs#L20-L22 with:

if (queue.Count > 0) {
    MemoryStream msg = queue.Take(cancellationToken);
    stream.Write(msg.GetBuffer(), 0, (int)msg.Length);
}