serversigns / ServerSigns

ServerSigns (SVS) provides the ability to bind player-dispatched and server-disptached commands, messages and actions to signs and every other block in Minecraft.
https://dev.bukkit.org/projects/serversigns
GNU Affero General Public License v3.0
13 stars 13 forks source link

Lag spike after clicking on serversign #22

Closed John-H-Smith closed 4 years ago

John-H-Smith commented 4 years ago

After a user clicks on a serversign with a command added like *gamemode 1, a big lag spike hits the server. This is caused by normal users and admins or ops too. Here's a screenshot of the ServerSigns data from a timings-report: image Maybe the PlayerInteractEvent-checks have to be asynchronuos? I would be glad if you could give me a hint what is causing this error and how I could prevent it.

EpiCanard commented 4 years ago

It's recent the use of ServerSign on your server ? Because I didn't make big changes in this part. Maybe not all the playerInteractCheck because so verification must be synchronous but maybe the sign execution.

Do you have more details timing to know what exactly create this lag and not only the entry point ?

John-H-Smith commented 4 years ago

@EpiCanard Yeah, it's a recent version. But this issue exists since a longer time for me, no update ever patched that.

So should I record timings longer?

EpiCanard commented 4 years ago

ok, what is the setup of your server ? launcher (bukkit, spigot, etcc), minecraft version, ram assigned to server ?

which tool do you use for your timings ?

John-H-Smith commented 4 years ago

@EpiCanard I am running git-Spigot-a03b1fd-fc318cc, so its one of the latest Spigot 1.15.2 versions. The Server has 8GB RAM assigned. My timings are made by the default spigot timings.

EpiCanard commented 4 years ago

ok, thanks for the information. I will investigate to optimize the command execution.

EpiCanard commented 4 years ago

@John-H-Smith what do you have on your sign to create so much lag ? can you send me your /svs info ?

EpiCanard commented 4 years ago

I tried to make the sign execution asynchronous but it came with issues that don't make it possible.

First, the cancel mode must wait the end of execution (see wiki for more details) so if it is asynchronous it is not possible Second, all action that interact with spigot must be done synchronously so the impact on the code is huge (can create a lot of unwanted bugs).

I tried also to make the execution asynchronous and wait the end of this execution to continue but the performance are the same and the second point above is still true.

John-H-Smith commented 4 years ago

@EpiCanard This is independent of the command on the server sign. Even *gamemode creative is causing lag.

Maybe this is caused because of the slow read/write speed of writing in files? Then it would be a great idea for adding database support (like mentioned in https://github.com/serversigns/ServerSigns/issues/17#issue-553076971) or maybe the option to store the signs in a sqlite database.

For the second point in your last comment, you can create a new synchronous task in an existing asynchronous task like

Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
    @Override
    public void run() {
        Bukkit.getScheduler().runTask(plugin, new Runnable() {
            @Override
            public void run() {
                //Synchronous request
            }
        });
    }
});

This should work I think.

EpiCanard commented 4 years ago

@John-H-Smith I don't know if SQL will change that much performances.

I didn't say that I don't know how to do it, I said it will have a huge impact because I have to make all call to Spigot Api in sync.

I made a version with save of files asynchronously, it doesn't affect CancelMode. Tell me if it improve your performances. ServerSigns.zip

John-H-Smith commented 4 years ago

Sadly, this does not resolve this issue. For testing purposes I set up a completely fresh server and added serversigns. But this error still persists. On my production server this is causing some problems, I have many users so all few seconds a serversign is clicked. The lag spike all few seconds is not very good. Do you have any further ideas about this?

EpiCanard commented 4 years ago

I don't any further ideas :/ All what is done synchronously is just comparison but nothing really consuming. Maybe you can try to use paperSpigot instead of spigot ? It is a fork fully compatible and way more optimized.

John-H-Smith commented 4 years ago

@EpiCanard I already tried that, but it doesn't changed anything. Am I the first person having this problem?

EpiCanard commented 4 years ago

Since I maintain this plugin yes but maybe before someone had the problem. @CalibeR50 has maybe a solution to track memory consuming, I will try and tell you.

EpiCanard commented 4 years ago

Can you try this plugin: https://www.spigotmc.org/resources/spark.57242/

John-H-Smith commented 4 years ago

@EpiCanard Thank you! Here is the link: https://spark.lucko.me/#vrGhKa6t4x

EpiCanard commented 4 years ago

What is the CPU you have on your computer/server ? Because I see a usage of 17% of your CPU just to do CraftPlayer.setOp()

John-H-Smith commented 4 years ago

Right now I am using a AMD FX-6300. But the server is on an Intel Core i7-4770 CPU with 3.40GHz where the issue also exists.

EpiCanard commented 4 years ago

Hum ok. Can you try to replace in your sign the *your_command by <server> your_command and try again the process above ?

With 1.15, there are a lot of performance issues that come with it and I don't know if it is fixable but if you can try the process. It would be nice if we could find an alternative.

John-H-Smith commented 4 years ago

Wow, this removes the delay! Console outputs instantly! Here you go: https://spark.lucko.me/#O6niy8XhjT Any further advice?

EpiCanard commented 4 years ago

Perfect :) No, just continue to use <server> instead of op operator * except when you have no other choice.

Even if you haven't seen it, thanks to @CalibeR50 and @Exloki who helped me in the background ^^

Can I close this issue ?

John-H-Smith commented 4 years ago

One further question: Not all of my commands are made to be executed by console. For example, the /home command. I cannot bind it to a sign because it have to be executed by a player. Is there a way to archive that without the op command? Maybe using grants or something?

EpiCanard commented 4 years ago

You can simply do /svs add home Every command that is not of format <type> or *command are considered as a player command

John-H-Smith commented 4 years ago

Thats clear. But there are some commands too which the player shoudn't execute directly so they don't have the permissions, but only by clicking onto a serversign. Because of this I added the op command to the signs.

EpiCanard commented 4 years ago

you can maybe try to give the permission, execute the command and remove the permission ? If it create less lag than op command

John-H-Smith commented 4 years ago

I will give it a try. Give me a few hours.

EpiCanard commented 4 years ago

Take all the time you need ^^

John-H-Smith commented 4 years ago

Seems to work. Its not the best solution, but will work.

Thanks for the great help! If you have any ideas in the future please let me know!

EpiCanard commented 4 years ago

Not the most beautiful solution but if it works without lag maybe the best. Hoping it will be improved in 1.16.

Unfortunately, I have no better idea to give you. If you have no other lag issues, I close this issue.