itzg / docker-minecraft-server

Docker image that provides a Minecraft Server that will automatically download selected version at startup
https://docker-minecraft-server.readthedocs.io/
Apache License 2.0
9.55k stars 1.56k forks source link

Minecraft: Spigot pegs CPU #80

Closed jbeda closed 5 years ago

jbeda commented 8 years ago

It turns out that spigot will peg the CPU when stdin is disconnected.

See https://www.spigotmc.org/threads/high-cpu-usage-solved.87634/page-2

Turns you you need a --noconsole option.

itzg commented 8 years ago

Thanks for researching that.

itzg commented 8 years ago

So far, local testing seems to confirm the same fixed behavior as the discussion thread:

image

itzg commented 8 years ago

When running without --noconsole, the CPU usage seems to be equivalent for me. @jbeda , can you double check that you ran your container with the -it options, such as:

docker run -it -d --name spigot -e EULA=TRUE -e TYPE=SPIGOT mc

BTW, a workaround for #81 is to docker attach and enter the stop command:

$ docker attach spigot                                                                                      [20:23:28]
stop
[01:23:48 INFO]: Stopping the server
[01:23:48 INFO]: Stopping server
[01:23:48 INFO]: Saving players
[01:23:48 INFO]: Saving worlds
[01:23:48 INFO]: Saving chunks for level 'world'/Overworld
[01:23:49 INFO]: Saving chunks for level 'world_nether'/Nether
[01:23:49 INFO]: Saving chunks for level 'world_the_end'/The End
itzg commented 8 years ago

For now I enhanced the container entry point to pass through any extra args to the server invocation, such as

docker run -it -d --name spigot -e EULA=TRUE -e TYPE=SPIGOT itzg/minecraft-server nogui --noconsole
jbeda commented 8 years ago

Thanks! I'll check it out tomorrow and test. On Sat, May 28, 2016 at 7:11 PM Geoff Bourne notifications@github.com wrote:

For now I enhanced the container entry point to pass through any extra args to the server invocation, such as

docker run -it -d --name spigot -e EULA=TRUE -e TYPE=SPIGOT itzg/minecraft-server nogui --noconsole

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/itzg/dockerfiles/issues/80#issuecomment-222338704, or mute the thread https://github.com/notifications/unsubscribe/AACRvjc9OnYLYOxZdF_f_ahIgEn2DSQxks5qGPXMgaJpZM4IpL4g .

jasmith86 commented 8 years ago

I ran into this problem with Spigot as well. To fix on my server I added --noconsole too /data/bootstrap.txt. I also had to modify the start-minecraft script to pass the parameter to java: https://github.com/itzg/dockerfiles/issues/82.

Edit: Just tried the above recommendation from itzg docker run -it -d --name spigot -e EULA=TRUE -e TYPE=SPIGOT itzg/minecraft-server nogui --noconsole and that worked for me as well.

itzg commented 8 years ago

Oops, might have closed too soon.

The challenge with applying --noconsole by default is that it'll defeat the ability to later docker attach when using -it on container creation.

@jbeda @jasmith86 , do you think it would be sufficient to document the new ability to pass command line args, like --noconsole, but leave the default as-is?

jbeda commented 8 years ago

I think that having a warning (perhaps a big echo block) that you should probably pass --noconsole when using spigot but that docker attach then doesn't work would be good. I'm betting other folks are pegging CPUs and don't have the time/google-fu to figure out what is going on.

On Sat, Jun 4, 2016 at 10:49 AM Geoff Bourne notifications@github.com wrote:

Oops, might have closed too soon.

The challenge with applying --noconsole by default is that it'll defeat the ability to later docker attach when using -it on container creation.

@jbeda https://github.com/jbeda @jasmith86 https://github.com/jasmith86 , do you think it would be sufficient to document the new ability to pass command line args, like --noconsole, but leave the default as-is?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/itzg/dockerfiles/issues/80#issuecomment-223768855, or mute the thread https://github.com/notifications/unsubscribe/AACRvl_fThj-bGvosnTMlmeKhgEFETZ9ks5qIbqkgaJpZM4IpL4g .

kstrauser commented 8 years ago

Could --noconsole be migrated to trigger off an environmental variable, maybe? I'm running mine container on a Synology NAS, and its GUI doesn't expose the ability to add extra arguments. I could run the container by hand but then I'd lose some of the nice management features.

Would something like this work?

diff --git a/minecraft-server/Dockerfile b/minecraft-server/Dockerfile
index 41d2306..fe28bd3 100644
--- a/minecraft-server/Dockerfile
+++ b/minecraft-server/Dockerfile
@@ -40,4 +40,4 @@ ENV UID=1000 GID=1000 \
     MOTD="A Minecraft Server Powered by Docker" \
     JVM_OPTS="-Xmx1024M -Xms1024M" \
     TYPE=VANILLA VERSION=LATEST FORGEVERSION=RECOMMENDED LEVEL=world PVP=true DIFFICULTY=easy \
-    LEVEL_TYPE=DEFAULT GENERATOR_SETTINGS= WORLD= MODPACK= ONLINE_MODE=TRUE
+    LEVEL_TYPE=DEFAULT GENERATOR_SETTINGS= WORLD= MODPACK= ONLINE_MODE=TRUE CONSOLE=true
diff --git a/minecraft-server/start-minecraft.sh b/minecraft-server/start-minecraft.sh
index afd0d0f..8a97584 100755
--- a/minecraft-server/start-minecraft.sh
+++ b/minecraft-server/start-minecraft.sh
@@ -441,10 +441,16 @@ if [ "$TYPE" = "SPIGOT" ]; then
   fi
 fi

+if [[ $CONSOLE = false ]]; then
+  EXTRA_ARGS=--noconsole
+else
+  EXTRA_ARGS=""
+fi
+
 # If we have a bootstrap.txt file... feed that in to the server stdin
 if [ -f /data/bootstrap.txt ];
 then
-    exec java $JVM_OPTS -jar $SERVER "$@" < /data/bootstrap.txt
+    exec java $JVM_OPTS -jar $SERVER "$@" $EXTRA_ARGS < /data/bootstrap.txt
 else
     exec java $JVM_OPTS -jar $SERVER "$@"
 fi
itzg commented 8 years ago

Excellent idea @kstrauser. Go ahead and create a pull request with your changes and I'll merge that ASAP.

kstrauser commented 8 years ago

It's in #106. CI seems to be having issues (or at least I can't identify anything in the failures that looks related to anything but Docker building slowly).

itzg commented 8 years ago

The image sha256:cf6731ecaf28994d6ccce839be205a3ab14cb65485d8307d492efe671b939ba9 is now pushed to Hub with #106 's change.

@kstrauser , when you get a chance can you touch up the README.md via a PR to cover the new environmental option?

a3dbox commented 5 years ago

Hi All, I have pulled the MC docker container last week (thanks btw) but I am still seeing this issues on my server. Java pegged at 100% its been running long enough to have settled down and it's only been me connecting to the server.

My docker-compose file sets CONSOLE: "false" after looking at the patch merged from above, (it's not in the docs) and the logs when the server starts say that there will be no console so setting the environment var seems to be doing what it should.

I don't suppose anyone has any ideas?

Thanks in advance!

Details: Ubuntu 18.04 Server Docker Container:

version: '3.7'

services:
        mc:
                image: itzg/minecraft-server
                environment:
                        EULA: "true"
                        TYPE: PAPER
                        VERSION: 1.14.2
                        COMMAND: --noconsole
                        CONSOLE: "false"
                ports:
                        - 25565:25565
                volumes:
                        - ./mc-data:/data

Docker ps:

CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS                PORTS                                              NAMES
3eb2c55f1389        itzg/minecraft-server   "/start"                 4 days ago          Up 4 days (healthy)   0.0.0.0:25565->25565/tcp, 25575/tcp                minecraft_mc_1_f3decfa148ef

Start of log:

Checking type information.
server.properties already created, skipping
Checking for JSON files.
Copying any mods over...
Copying any Bukkit plugins over...
Setting initial memory to 1G and max to 1G
Starting the Minecraft server...
[00:17:01 INFO]: Starting minecraft server version 1.14.2
[00:17:01 INFO]: Loading properties
[00:17:02 INFO]: This server is running Paper version git-Paper-86 (MC: 1.14.2) (Implementing API version 1.14.2-R0.1-SNAPSHOT)
[00:17:02 INFO]: Console input is disabled due to --noconsole command argument
[00:17:02 INFO]: Server Ping Player Sample Count: 12
[00:17:02 INFO]: Using 4 threads for Netty based IO
[00:17:02 INFO]: Debug logging is disabled

top:

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                                        
 3076 a3dbox    20   0 2777432 1.264g  15420 S 100.0 21.7   6953:09 java  

ps 3076:

  PID TTY      STAT   TIME COMMAND
 3076 ?        Sl   6954:19 java -XX:+UseG1GC -Xms1G -Xmx1G -jar paper_server.jar --noconsole
itzg commented 5 years ago

The newer Spigot versions might have fixed the original issue; however, I also made sure document the CONSOLE=FALSE option that will pass --noconsole:

https://github.com/itzg/docker-minecraft-server#using-noconsole-option