facebookarchive / RakNet

RakNet is a cross platform, open source, C++ networking engine for game programmers.
Other
3.29k stars 1.02k forks source link

Nat Type Detection excessive CPU usage #107

Open C0lumbo opened 7 years ago

C0lumbo commented 7 years ago

Description

Nat type detection involves 4 extra ports on the server and 1 extra port on the client. This bug uses the naming conventions from NatTypeDetectionServer.h (S1P2, S2P3, S3P4, S4P5, C2) to help describe the issue.

In all the server has 5 threads spinning on a RakSleep(0), none of which are necessary.

Suggested fix:

  1. C2 and S3P4 should be created as blocking sockets
  2. The redundant call to CreateRecvPollingThread in RakNet::CreateNonblockingBoundSocket should be removed.

Remarks

The extra CPU usage here is pretty harmless for the client because the C2 socket is so short-lived. It's also relatively harmless for the server if you're running on a dedicated machine as the spinning threads will just be consuming spare cycles (and wasting power). However, if you're running the detection server on a system where you pay extra for CPU utilization (e.g. AWS) then it is worth fixing.

Hakunametata commented 6 years ago

it works!