Hey there,
now, with bukkit it is possible to crash a server by using a plugin and typing something like this:
while(true) {
//Spawning an entity, etc.
}
So, is it possible to add something disabling plugins if the take to much CPU usage, or generally adding a CPU limit per plugin?
If the server is slow, it takes quit long to search for the plugin doing somthing wrong and slowing down everything.
I really hope this idea is possible,
Tobi
EDIT: DISABLING PLUGINS IS BAD, read everything before posting this again
It isn’t possible just like that. Also, it shouldn’t be a thing. (Except as a plugin).
I wouldn’t want the grief prevention to suddenly turn off cause of high CPU usage. And if you’re gonna use a plugin that has something like this:
while(true) {
//Spawning an entity, etc.
}
Then you already have other issues, because that’s gotta be made to create lag
(Also, it isn’t really possile to track the CPU usage of a single plugin)
Hypothetically speaking I do think though that if the server would warn operators or high permission groups about large resource usage by plugins, this would be good. An automatic shutdown of the plugin would be risky because then next thing you know WorldGuard and LogBlock are both disabled and a griefer calls in his squad on your spawn. However, if there was a way to import results from a CPU stress test (that you would do externally on your system), store it in a config, and then see if the CPU time of your server or a plugin comes close to the stress test results, launch warnings, that would be really cool I think. RAM would be easy because that’s just a physical property that can be fetched with a few methods,
The only thing I can think Sponge can do without risking messing up plugins it some sort of rate limiting on known “expensive” methods. Not sure whether that would be a good idea but maybe allow say spawnEntity to be called at most once every 5 ticks for example.
allowing spawnEntity just every 5 ticks would just limit features, and wouldnt make any sense. I see, disabling plugins is a bad idea, but warnings would also make it. To come back to the ticks limit, warnings could also been send, if a plugin uses spawnEntity too much.
Another thing would be regulation for CPU usage (I dont know wether its possible). There could also be added a configuration file or something like priorities.
If spawnEntity were limited by ticks, then how would you expect the Essentials command /spawnmob zombie 50 to work?
I think the key to the thread topic lies in multithreading and multi core usage, but if vanilla can’t even use two cores, how is a Forge mod supposed to make it happen.
I think what your asking is waste of time. If a server software needs to disable plugins to keep your server running. The problem is somewhere else:
Your server hardware is sh*t
You have to many plugins
etc
Also lets say worldguard is lagging your server because some hacked client is sending 1B of break packets. Than it would disable worldguard to stop lagging the server … .
Before anyone else posts a “Why disabling is bad…” It’s already stated 3 times that it is, a per plugin CPU monitor could be useful, even on the best of hardware(#OVH64GBserversArePrettyNice)
Disabling is overkill and dangerous, as previously stated disabling a plugin that has a lag spike or is getting spammed could result in serious security vulnerabilities. Reporting seems good though, especially if you could define levels at which it would report to certain people.
As a sub idea I haven’t seen mentioned yet would be to have a configuration file. For example defaultly plugins aren’t disabled, so this way things like logblock, worldedit, etc won’t be affected. However users who are conscious about these things can set maximum amount of usage.
[EDIT]
Or have a command to limit? Or check if something is using to much?
So, to make this clear:
first, I dont want a function showing the CPU usage by the hole server.
I want a function to show the cpu usage from every plugin
second, I dont want to diable plugins, as it can be seen some posts above, it would be too much a security risk! (so logblock might be disabled then, so its not e good idea )
but as LordLambds said, this might be solved with a configuration file, or as another idea, you can set an entry in the plugin.yml (i dont know the name of that in sponge) that this plugin musnt be disabled.
The reason we are talking about the CPU usage of the whole server is because it is highly unlikely to have a way to do this, without itself making everything more CPU heavy. I personally subscribe to the idea that “The best way to prevent a CPU overload is by not doing crazy things”.
The closest I think we will get to a CPU limiting sort of function is plugins themselves being conscious of how hard they are running. WorldEdit, for example, if you try to edit a million blocks, might say “k den lets take this nice and slow” instead of the Bukkit version’s protocol of “nom nom nom main thread nom nom nom”. Or the Essentials spawnmob command could see that you are trying to spawn a thousand giants in one square and say “okay, when there aren’t 100 still chilling out on that block, I’ll spawn in the next 100”.
However, I will not discount the idea that some sort of plugin metrics are not possible. Provided it were used properly and not abused by clueless developers, a sort of ping system could be used by plugins to indicate iterations, or things that are known to be CPU heavy. Some pseudocode for reference:
private PluginContainer pl;
public EventListener(PluginContainer pl) {
this.pl = pl;
}
@Subscribe
public void onPlayerJoin(PlayerJoinEvent event) {
for (Player player : Server.getPlayers()) {
//Some people don't like enums, but this is an example. Get over it for now.
this.pl.cpuPing(CpuPing.iterate);
player.sendMessage(event.getPlayer().getName() + " has joined!");
this.gratuitousFireworks();
}
}
public void gratuitousFireworks() {
this.pl.cpuPing(CpuPing.heavy);
for (int i = 0; i < 100; i++) {
this.pl.cpuPing(CpuPing.iterate);
//Lets just assume for the example that this location is defined somewhere
world.setFireworks(magicLocation);
}
}
If the server sees that a plugin has had too many iterations in a short time, it could then do something to respond. But this is the part where I lose my grasp on it and will need someone with a bit more knowhow to pick this up or smash it to pieces.