Best way to get Server TPS

Discussion in 'Server & Community Management' started by BlueFusion12, Apr 3, 2013.

Thread Status:
Not open for further replies.
  1. I am working on developing a plugin (my first one yay!) and I am trying to find the best way to get the TPS of a server. I have googled this and tried many blocks of code given on the bukkit site, but none of them seem to work effectively.

    My question? What is the best code I can use to get the TPS of my server?

    Also, since I would only be using this for my own server (which runs on spigot), is there any way I can use spigot, which already has a TPS getting function (/tps)?

    Thanks!

    - BlueFusion12
     
  2. Puremin0rez

    Moderator

    I'm not quite sure why you want to make a TPS monitoring plugin - Spigots /tps command will be the most accurate because of the way it works.

    I personally don't know how to monitor TPS codewise but I'm sure it isn't too difficult.
     
    • Friendly Friendly x 1
  3. My goal is not to develop a tps monitoring plugin. My goal is to be able to have variable action as well as response to a certain state of lag on the server (tps). I also have a few other ideas that this would be helpful for.
     
    • Agree Agree x 1
  4. Puremin0rez

    Moderator

    Oh I see, that seems much more sensible

    I'm actually not sure what the best way to accomplish that would be.
     
  5. Still looking for a way to do this. Any help would be appreciated!
     
  6. vemacs

    Artist

    in MyClass.java:

    Code (Text):
    long starttime = System.currentTimeMillis();
    public long endtime = 0;
    Bukkit.getServer().getScheduler().runTaskLater(Bukkit.getPluginManager().getPlugin("<plugin name here"), new TickTask(), 1);
    in TickTask.java:
    Code (Text):
    public class TickTask extends BukkitRunnable {
        public void run() {
        MyClass.endtime = System.currentTimeMillis();
      }
    }
    Now just compare starttime and endtime. 50ms should be exactly 20tps.
     
  7. Maybe md_5 can develop something like this? Once a set TPS is reached, Spigot will perform certain tasks or maybe an option to insert certain commands so it will then do /butcher etc etc.
     
    • Friendly Friendly x 1
  8. joehot200

    Supporter

    I coded a plugin like that called AntiLag. It monitors the TPS, and when it drops does various things, e.g. stopping the mobs..

    Wait a second and ill paste a load of code.. including the code that gets me the TPS.
     
  9. I said once a TPS is reached not once a certain entity is reached. Plus ClearLagg running it's limit scheduler does more lag than what it's worth.
     
  10. joehot200

    Supporter

    ClearLag is total rubbish in my opinion because it removes the drops too...
     
  11. OKAY as you wish, but don't get on me just beause I did not agree with your idea of adding a cmd to be executed upon a TPS drop to spigot
     
    • Agree Agree x 1
  12. joehot200

    Supporter

    TPS getting code:
    Code (Text):

    getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
    {
      long sec;
      long currentSec;
      int  ticks;
      int  delay;
     
      @Override
      public void run()
      {
          sec = (System.currentTimeMillis() / 1000);
       
          if(currentSec == sec)
          {
              ticks++;
          }
          else
          {
              currentSec = sec;
              tps = (tps == 0 ? ticks : ((tps + ticks) / 2));
              ticks = 0;
          }
      }
    }, 0, 1);
    getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable()
    {
     
    Entity removing code: (Removes all entities in the worlds)
    Code (Text):

    {
       @Override
       public void run(){
       for (Entity e : Bukkit.getWorld("world").getEntities()){
       if (e.getType() == EntityType.WOLF){
       if (tps <= 5){
       e.remove();
       }
       }else if (e.getType() != EntityType.DROPPED_ITEM){
       if (!(e instanceof Player)){
       e.remove();
       eremoved++;
       }
       }
       }
       for (Entity e : Bukkit.getWorld("world_nether").getEntities()){
       
       if (e.getType() == EntityType.WOLF){
       if (tps <= 5){
       e.remove();
       }
       }else if (e.getType() != EntityType.DROPPED_ITEM){
       if (!(e instanceof Player)){
       e.remove();
       eremoved++;
       }
       }
       }
       for (Entity e : Bukkit.getWorld("world_the_end").getEntities()){
       if (e.getType() == EntityType.WOLF){
       if (tps <= 5){
       e.remove();
       }
       }else if (e.getType() != EntityType.DROPPED_ITEM){
       if (!(e instanceof Player)){
       e.remove();
       eremoved++;
       }
       }
       }
       Bukkit.getServer().broadcastMessage(ChatColor.GREEN + "[AntiLag] Removed " + eremoved + " Entities");
       eremoved = 0;
       }
       
    }, 0, 3000);
    }
     
     
    • Like Like x 1
  13. Thats the idea :) less drops less lag. Of course it will not affect a small server, but when you got a big server with thounsands of items floating in the world it makes a change. Also, it has the option to alert users before drops get deleted.
     
  14. joehot200

    Supporter

    I think it should have a config option, and i also think it should only do it if it is below a certain TPS. Let me put it like this: out of the last 7 servers i played, only 2 of them i liked, and 3 of them i quit because ClearLagg removed all the diamonds i had just got before dying.
     
  15. joehot200
    I will try your plugin, sounds interesting :)
     
  16. joehot200

    Supporter

    Havent released it to bukkit yet.

    Do you want me to?
    I was busy at the time.
     
  17. Well depends every how much time they get deleted.
     
  18. joehot200

    Supporter

    Most servers have it like, once every 10 mins, i mean, you dont need it once every 10 mins!! You need it like, once per hour! Thats when the entities really start to clog up the server.
     
  19. Has this been tested? And does it work?
     
  20. joehot200

    Supporter

    The code? Its on my server right now. It works.
     
    • Like Like x 1
    • Agree Agree x 1
    • Winner Winner x 1
Thread Status:
Not open for further replies.