mcl_priv uses a lot of CPU #3368

Open
opened 2023-01-28 00:04:16 +01:00 by atomdmac · 17 comments
Contributor

MineClone2 version: Current master (SHA: 63360bcab2)

What happened?

The mcl_privs mod seems to be using an outsized amount of CPU which is causing lag for clients.

What should happen:

I'm not familiar with everything that mcl_privs does but given it's same, the amount of CPU that it's using seems suspect.

Steps to reproduce

Start a new MC2 map using the commit listed above and notice the lag.

MineClone2 version: Current master (SHA: 63360bcab268c561eca7450806c24118e40f81ab) ### What happened? The `mcl_privs` mod seems to be using an outsized amount of CPU which is causing lag for clients. ### What should happen: I'm not familiar with everything that `mcl_privs` does but given it's same, the amount of CPU that it's using seems suspect. ### Steps to reproduce Start a new MC2 map using the commit listed above and notice the lag.
atomdmac added the
bug
unconfirmed
labels 2023-01-28 00:04:17 +01:00
Author
Contributor

FWIW, if I comment out the entire body of the function here, the lag almost disappears entirely.

FWIW, if I comment out the entire body of the function [here](https://git.minetest.land/MineClone2/MineClone2/src/branch/master/mods/MISC/mcl_privs/init.lua#L7), the lag almost disappears entirely.

That is pretty weird. The code is this:

minetest.register_on_joinplayer(function(player)
	local name = player:get_player_name()
	local meta = player:get_meta()
	if meta:get_int("mcl_privs:fly_changed") == 1 then return end

	local fly = nil
	if minetest.is_creative_enabled(name) then
		fly = true
	end
	local player_privs = minetest.get_player_privs(name)
	player_privs.fly = fly
	minetest.set_player_privs(name, player_privs)
end)

It does not look expensive to me. It only runs when a player joins which is a very rare.

Feels like there is some state issue on the game. I have profiled a lot and I have never seen this being an issue. It feels like players are joining and leaving a lot or this was profiled for a short period when people joined.

That is pretty weird. The code is this: ``` minetest.register_on_joinplayer(function(player) local name = player:get_player_name() local meta = player:get_meta() if meta:get_int("mcl_privs:fly_changed") == 1 then return end local fly = nil if minetest.is_creative_enabled(name) then fly = true end local player_privs = minetest.get_player_privs(name) player_privs.fly = fly minetest.set_player_privs(name, player_privs) end) ``` It does not look expensive to me. It only runs when a player joins which is a very rare. Feels like there is some state issue on the game. I have profiled a lot and I have never seen this being an issue. It feels like players are joining and leaving a lot or this was profiled for a short period when people joined.
Contributor

If minetest.get_player_privs and minetest.set_player_privs do I/O operations on a storage device, it would makes sense for a slow storage devices to cause execution delays. What does the server run on?

If `minetest.get_player_privs` and `minetest.set_player_privs` do I/O operations on a storage device, it would makes sense for a slow storage devices to cause execution delays. What does the server run on?
Member

We really don't have a way of fixing that, as it's minetest, and the server's hardware.

But, the privs need to be set for the player to function.

We really don't have a way of fixing that, as it's minetest, and the server's hardware. But, the privs need to be set for the player to function.
Contributor

If this really is an I/O issue, the privileges for all players can be read in one go and cached in RAM, and written on change. It can't get worse than 100MB RAM for all users, even for large servers.

If this really is an I/O issue, the privileges for all players can be read in one go and cached in RAM, and written on change. It can't get worse than 100MB RAM for all users, even for large servers.

How much ram do you have, and when playing, how much are you using? Is this HDD?

How much ram do you have, and when playing, how much are you using? Is this HDD?
Author
Contributor

If minetest.get_player_privs and minetest.set_player_privs do I/O operations on a storage device, it would makes sense for a slow storage devices to cause execution delays. What does the server run on?

Its running on a Synology 918+ in Docker. Its been upgraded to have 16GB of RAM. Hearing htat its likely an I/O issue makes me wonder if Docker (specifically bind mounts) might be at least partially at fault. I've heard that they can introduce some overhead where that's concerned.

> If `minetest.get_player_privs` and `minetest.set_player_privs` do I/O operations on a storage device, it would makes sense for a slow storage devices to cause execution delays. What does the server run on? Its running on a Synology 918+ in Docker. Its been upgraded to have 16GB of RAM. Hearing htat its likely an I/O issue makes me wonder if Docker (specifically bind mounts) might be at least partially at fault. I've heard that they can introduce some overhead where that's concerned.
Author
Contributor

@ancientmarinerdev

How much ram do you have, and when playing, how much are you using? Is this HDD?

The machine has 16 GB and is free to use as much of it as it wants. I believe the CPU is 4 cores at 1.2Ghz

@ancientmarinerdev >How much ram do you have, and when playing, how much are you using? Is this HDD? The machine has 16 GB and is free to use as much of it as it wants. I believe the CPU is 4 cores at 1.2Ghz

@ancientmarinerdev

How much ram do you have, and when playing, how much are you using? Is this HDD?

The machine has 16 GB and is free to use as much of it as it wants. I believe the CPU is 4 cores at 1.2Ghz

Is it an ssd or hdd?

> @ancientmarinerdev > > >How much ram do you have, and when playing, how much are you using? Is this HDD? > > The machine has 16 GB and is free to use as much of it as it wants. I believe the CPU is 4 cores at 1.2Ghz Is it an ssd or hdd?
Member

Removed the accidental duplicate of the message:

image

Removed the accidental duplicate of the message: ![image](/attachments/cb0f3578-3f57-4200-afd0-62bb5d868b1d)
Author
Contributor

Is it an ssd or hdd?

HDD

>Is it an ssd or hdd? HDD
Member

Is it an ssd or hdd?

HDD

What OS? and what file system? (it does make a difference).

I'm asking because different operating systems and file systems are better at read/writes... and can also prevent file fragmentation, which causes reads / writes to require a lot more cpu time.

Hearing htat its likely an I/O issue makes me wonder if Docker (specifically bind mounts) might be at least partially at fault. I've heard that they can introduce some overhead where that's concerned.

This is also a very solid point. Sadly, also -- due to the way that minetest handles things, external network traffic will also affect it, causing lag for no apparent reason.

> >Is it an ssd or hdd? > > HDD What OS? and what file system? (it does make a difference). I'm asking because different operating systems and file systems are better at read/writes... and can also prevent file fragmentation, which causes reads / writes to require a lot more cpu time. >Hearing htat its likely an I/O issue makes me wonder if Docker (specifically bind mounts) might be at least partially at fault. I've heard that they can introduce some overhead where that's concerned. This is also a very solid point. Sadly, also -- due to the way that minetest handles things, external network traffic will also affect it, causing lag for no apparent reason.
Author
Contributor

What OS? and what file system? (it does make a difference).

Synology uses a Unix-ish OS but I'm not sure of all of the differences. It uses Btrfs as the filesystem.

Within Docker, I'm using the linuxserver/minetest image.

I think my next step is going to be trying to run on a Raspberry Pi 4 without the use of containers to see if that works any better.

> What OS? and what file system? (it does make a difference). Synology uses a Unix-ish OS but I'm not sure of all of the differences. It uses Btrfs as the filesystem. Within Docker, I'm using the [linuxserver/minetest](https://docs.linuxserver.io/images/docker-minetest) image. I think my next step is going to be trying to run on a Raspberry Pi 4 without the use of containers to see if that works any better.
Member

If you can, try it out first on a network only connected to the client, and measure cpu performance. (eliminating external influence.)

But I do think that doing it outside of a docker image might be a good idea. I did a quick check, and it looks like docker images are mini virtual machines, so there's going to be a decent amount of overhead, if I understood it correctly.

Synology uses a Unix-ish OS but I'm not sure of all of the differences. It uses Btrfs as the filesystem.

Was making sure that it wasn't windows (which does a ton of things in the background) and that it was a somewhat modern filesystem, so that we could rule out huge fragmentation of the files. BTRFS is new enough and a good filesystem, but you might check out the journaling that it has enough space, etc., to function properly.

If you can, try it out first on a network only connected to the client, and measure cpu performance. (eliminating external influence.) But I do think that doing it outside of a docker image might be a good idea. I did a quick check, and it looks like docker images are mini virtual machines, so there's going to be a decent amount of overhead, if I understood it correctly. > Synology uses a Unix-ish OS but I'm not sure of all of the differences. It uses Btrfs as the filesystem. Was making sure that it wasn't windows (which does a ton of things in the background) and that it was a somewhat modern filesystem, so that we could rule out huge fragmentation of the files. BTRFS is new enough and a good filesystem, but you might check out the journaling that it has enough space, etc., to function properly.

What OS? and what file system? (it does make a difference).

Synology uses a Unix-ish OS but I'm not sure of all of the differences. It uses Btrfs as the filesystem.

Within Docker, I'm using the linuxserver/minetest image.

I think my next step is going to be trying to run on a Raspberry Pi 4 without the use of containers to see if that works any better.

What profiler do you use for this?

> > What OS? and what file system? (it does make a difference). > > Synology uses a Unix-ish OS but I'm not sure of all of the differences. It uses Btrfs as the filesystem. > > Within Docker, I'm using the [linuxserver/minetest](https://docs.linuxserver.io/images/docker-minetest) image. > > I think my next step is going to be trying to run on a Raspberry Pi 4 without the use of containers to see if that works any better. What profiler do you use for this?
Author
Contributor

@ancientmarinerdev I used the built-in profiler (I think? I didn't realize there were multiple...). Basically, I set profiler.load = true in my minetest.conf, started a map, played for a few minutes, and then used /profile save txt to output the results.

@ancientmarinerdev I used the built-in profiler (I think? I didn't realize there were multiple...). Basically, I set `profiler.load = true` in my `minetest.conf`, started a map, played for a few minutes, and then used `/profile save txt` to output the results.

@ancientmarinerdev I used the built-in profiler (I think? I didn't realize there were multiple...). Basically, I set profiler.load = true in my minetest.conf, started a map, played for a few minutes, and then used /profile save txt to output the results.

if you search jitprofiler on contentDB, it comes highly recommended.

I will check out the built in one on mine too.

> @ancientmarinerdev I used the built-in profiler (I think? I didn't realize there were multiple...). Basically, I set `profiler.load = true` in my `minetest.conf`, started a map, played for a few minutes, and then used `/profile save txt` to output the results. if you search jitprofiler on contentDB, it comes highly recommended. I will check out the built in one on mine too.
ancientmarinerdev added the
performance
label 2023-02-03 02:24:48 +01:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: VoxeLibre/VoxeLibre#3368
No description provided.