EsotericSoftware / kryonet

TCP/UDP client/server library for Java, based on Kryo
BSD 3-Clause "New" or "Revised" License
1.82k stars 419 forks source link

Server.update() consumes 100% CPU resources #18

Closed ghost closed 10 years ago

ghost commented 10 years ago

From KingSqua...@gmail.com on March 10, 2012 16:44:32

I have noticed that kryonet server is consuming too much CPU time.

When my app is running on my local Tomcat in Windows environment everything is working fine. But after being deployed to a production server which is Debian based it starts to load CPU at 100% even with few users connected. I can see in profiler that kryonet thread called "Server" consumes almost 100% CPU time with executing Server.update() method.

I have found that a lot of NIO-based network libraries had a similar issue due broken NIO Selector implementation on Linux. But I use the latest jdk in wich I suppose this bug should be already fixed.

So is any workarounds to avoid such high CPU load?

Server environment:

uname -a: Linux 2.6.32.46-xenU #1 SMP Thu Oct 27 23:15:48 UTC 2011 i686 GNU/Linux

java -version: java version "1.7.0_03" Java(TM) SE Runtime Environment (build 1.7.0_03-b04) Java HotSpot(TM) Client VM (build 22.1-b02, mixed mode)

Attachment: cpu_samples.png cpu_thread_time.png thread_dump_server.txt

Original issue: http://code.google.com/p/kryonet/issues/detail?id=17

ghost commented 10 years ago

From nathan.s...@gmail.com on April 25, 2012 20:01:35

The latest code in SVN should remedy this problem. I don't know why NIO returns immediately from a select without any channels selected. We now sleep for a short time when this occurs to avoid 100% CPU.

Status: Fixed