mojira.dev
MC-43395

MP: Severe lag and memory leak when a lot of new chunks are generated

When I explore a lot (causing a lot of new chunks to be generated), the server's memory and CPU usage rises permanently causing major lag and ultimately the server crashes with an OutOfMemory exception.

During normal play (even with more players online), memory usage never exceeds a few 100 MB and CPU load remains well below 25%.

Under the aforementioned conditions, a single core is fully saturated (CPU load 100%) and memory usage raises until JVM heap limit is hit (already raised to 2 GB in my setup).

Reducing the view distance helped a little, but setting it below 8 did not improve the behaviour further.

Even long before the crash the following symptoms can be observed:

  • lot of "can't keep up" messages on the server console

  • player unable to move, "jittering" and then appearing at a position from several seconds ago

  • almost no hostile mobs spawning at night

  • very slow response to console commands (e.g. time set, tp), I usually have to wait several seconds before the requested action is performed.

How to reproduce

1. Set up a new multiplayer server
2. Walk around a lot (e.g. some 1000 blocks into one direction)
3. Watch server load and memory usage on Linux console (e.g. top)

I assume that new generated chunks are not removed from memory once the are out of the player's range unlike chunks that are loaded from disk.

Update #1 (2013-12-27 21:14): high load and memory usage persists even if the last player has disconnected. Another server instance (same game version, same JRE, same settings) running on the same machine but with a more "standard" workload does not exhibit this behaviour, it can handle 5 simultaneous users without noticeable lag, CPU load or memory consumption.

Comments 9

I've had the same problems, and reported a bug before ( MC-41874 ); I've linked your issue in the description.

On what CPU does the server run ? How much memory has the CPU and how much Java ?

Gregor Kuhlmann

The server is running on a E5200 Pentium Dual-Core w/ 4GB RAM. Not exactly high-end by today's standards, but it should well be able to handle a single vanilla server instance with at most 2 players online simultaneously.
I assigned 2 GB of JVM heap space to this instance after encountering frequent OutOfMemory exceptions. The command line I use is

java -server -Xmx2G -Xincgc -jar minecraft_server.jar nogui

server.properties

generator-settings=
op-permission-level=4
allow-nether=true
level-name=world
enable-query=false
allow-flight=false
announce-player-achievements=true
server-port=25577
level-type=DEFAULT
enable-rcon=false
force-gamemode=false
level-seed=
server-ip=192.168.1.43
spawn-mobs=true
max-build-height=256
spawn-npcs=true
white-list=false
spawn-animals=true
texture-pack=
snooper-enabled=false
hardcore=false
online-mode=true
resource-pack=
pvp=false
difficulty=2
enable-command-block=false
gamemode=0
player-idle-timeout=0
max-players=8
spawn-monsters=true
generate-structures=true
view-distance=9
spawn-protection=16
motd=Vanilla Server

Minecraft uses only one cpu, so you're running on a 1.6 GHz Pentium - that's quite slow.
Assuming an old PC with old chipset and old harddisk, the overall perfomance of that server is bad.
You might try to omit the "-Xincgc", that might help to spread GC peaks but is overall slower than the default GC

Nothing we can do here, this is a technical support issue; this site is for bug reports only. For technical support please use the Mojang Support Center.

Gregor Kuhlmann

FYI the E5200 is running at 2.5 GHz not 1.6GHz.

Unless my understanding of the way Minecraft works is fundamentally wrong, only the chunks in the global spawn area and the chunks around the view-distance of the logged in player(s) should be kept in memory, so if the number of players is constant memory usage should remain more or less constant while playing.

What I am experiencing however is that JVM memory usage rises monotonously while moving through unexplored areas, and remains high even after the last player has logged out. My expectation was that memory usage should drop as unneeded chunks are unloaded from memory, but this does not seem to happen.

As I said in my original post, the same hardware can easily handle another server instance with up to 5 players online simultaneously without any noticeable lag or excessive CPU load and memory load, so I believe we can safely reject the idea that this is merely related to lack of processor power.

Gregor see MC-42088

Gregor Kuhlmann

After we finally found what we were looking for (a Mesa biome) and stopped exploring 1000s of blocks away from our spawn point, the issue does no longer appear. CPU usage when noone is logged in is around 1-2%, though memory usage is still quite high (1.3 GB) which I still believe indicates some kind of memory leak, since it is from a server with no addons or mods and no sophisticated redstone circuitry.

Here are the last few lines from JVM garbage collector log (with -Xincgc setting)

235692,578: [GC 1200181K->1184208K(1331864K), 0,0325270 secs]
235736,077: [GC 1201040K->1185217K(1331864K), 0,0351430 secs]
235740,629: [GC 1202049K->1185927K(1331864K), 0,0242170 secs]
235783,021: [GC 1202759K->1186477K(1331864K), 0,0561370 secs]
235826,078: [GC 1203309K->1188448K(1331864K), 0,0427910 secs]
235831,481: [GC 1205280K->1188646K(1331864K), 0,0157140 secs]
235873,467: [GC 1205478K->1188905K(1331864K), 0,0364540 secs]
235916,152: [GC 1205737K->1191903K(1331864K), 0,0547870 secs]
235922,108: [GC 1208735K->1192606K(1331864K), 0,0254940 secs]
235963,927: [GC 1209438K->1192779K(1331864K), 0,0243430 secs]
236006,566: [GC 1209611K->1195392K(1331864K), 0,0517560 secs]

I never experienced the effect described in MC-42088 much even during periods of extreme lag though.

I created a new hardcore world for SP use today and am experiencing symptoms of this issue. Mobs are lagging horribly, also experiencing issues from the MC-42088 mentioned in the comment above me, but only as I explored the world and loaded new chunks. I took a look at the CPU usage by Java and it is at 1.15 GB. Can provide more information as needed.

EDIT: As I continued to walk about in the world, I checked my CPU usage and it spiked to 80%.

EDIT2: I created a new world, wandered around for some few thousand blocks but didn't experience the same lag as before. I'm guessing the world with the extreme lag was probably corrupted.

Gregor Kuhlmann

(Unassigned)

Unconfirmed

lag, memory-leak, multiplayer, world

Minecraft 1.7.4

Retrieved