otland / forgottenserver

A free and open-source MMORPG server emulator written in C++
https://otland.net
GNU General Public License v2.0
1.58k stars 1.05k forks source link

[Feature]: Move XTEA encryption from Dispatcher thread to Network thread #4779

Open gesior opened 2 weeks ago

gesior commented 2 weeks ago

By submitting this feature issue, you agree to the following.

Pull Requests or Links to add this feature

No response

Request

What do you want to achieve? Reduce Dispatcher thread CPU usage.

I've tested it on TFS 1.4 with some commits from 1.6 with CMAKE_BUILD_TYPE=Release.

All players online were 30 SQM away from each other, making 2 steps per second with 10-20 monsters on screen of each player. CPU usage by sendAll(bufferedProtocols); before changes from my commit:

100 online: 4.5-5.2%
200 online: 7.7-8.6%
300 online: 9.5-10.8%

After:

100 online: 0.3%
200 online: 0.44%
300 online: 0.52%-0.94%

Most OTS engines report sendAll(bufferedProtocols) in OTS Stats under name functor.

Possible Solutions

https://github.com/gesior/forgottenserver-gesior/commit/ba6df5e7ab5f97cc78d86291b44e2a2a940e10eb

Wirless commented 1 week ago

amazing

ranisalt commented 1 week ago

It's a good idea to free up resources in the dispatcher thread, and the networking code could benefit from multiple threads to receive/send packets.