[Solved]scheduleSyncRepeatingTask Killing CPU

Discussion in 'Plugin Development' started by Largo Usagi, Feb 22, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Largo Usagi

    So in one of my plugins I need to execute a job on roughly 20 second intervals here is the code that is calling the task.

    Code:
    schedualer.scheduleSyncRepeatingTask(this, new SkinTask(this), 60L, 500L);
    and the class SkinTask

    Code:
    package com.citizenskins.core;
     
    public class SkinTask implements Runnable{
       
        public static CitizenSkins plugin;
       
        public SkinTask(CitizenSkins instance)
        {
            plugin = instance;
        }
       
       
        public void run()
        {
            //plugin.cam.ReloadSkins();
            System.out.println("This message is printed by an async thread");
        }
     
    }
    
    In this state the CPU on the server spikes to about 30% usage even to just print out the simple message in the console so is there something that I am missing here to keep this from happening or is threading with bukkit just this terrible.

    Thanks for any assistance because without a repeating task I will have issues with the plugin im working on.
     
  2. Offline

    Neodork

    Ahm look into this video, I'm yet to use them but this works got GTOT they say.
    Time to start looking: 11:38
     
  3. Offline

    Largo Usagi

    Thanks for the video but after trying to implement the same thing in this fashion I have the same performance problem.

    my server still hits 30% cpu the moment this starts and it idle's at 30% from there on out. This is greatly frustrating because I know many other plugins are using sync tasks and they dont spike the shit out of a servers CPU usage.
     
  4. Offline

    dadaemon

    I use scheduled tasks too. But never experienced these kind of behavior. What is the "schedualer" that your using? Is it a reference to "getServer().getScheduler()" ?

    Also, just something totaly different. Why make plugin public if it's only being used in your scheduled task? :)
     
  5. Offline

    Largo Usagi

    This is where my scheduler is defined.

    Code:
    plugin = this;
           
            config = this.getConfig();
            pdfFile = this.getDescription();
            schedualer = plugin.getServer().getScheduler();
    
    And that is out of habit from other programming languages. Normally i code in C# and write windows applications where I have many .NET dll's and the classes need to be public there to be used in the rest of the code. IE this DLL has the forms, this DLL has the logic etc, and the main executable references all of them making updating a simpler task.

    Thanks for pointing that out.
     
  6. Offline

    Father Of Time

    Well nothing is immediately apparent, so it's time to start speculating...

    Code:
        schedualer.scheduleSyncRepeatingTask(this, new SkinTask(this), 60L, 500L);
    
    Where is this being called? Is it possible that although your one task is doing very little that maybe you are creating many instances of it accidentally?

    If this task is being scheduled from an event or a loop or anything of that nature I would put a print statement before and after it is called so you can identify each time the timer is being created in the console. In heinsight this likely isn't the case because if it was your console would be spammed with your runnable functions print statement...

    Honestly I use task often and never have performance issues, so I simply don't know what else to suggest... Sorry I wasn't much help... :(
     
  7. Offline

    Largo Usagi

    In my onEnable() function I assume that is being called only once.

    Ok so i have no idea why but getting a 32bit version of eclipse and building the code with that solved the problem.

    Any feedback here would be appreciated.

    Thanks
    -Largo

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 24, 2016
  8. Offline

    dadaemon

    I have absolutely no idea. Sorry. But at least you've found the problem!
     
  9. Offline

    Largo Usagi

    Changing title to solved, this was an odd one.
     
  10. Offline

    troed

    I've just had a bug report on my plugin where the user claims it spiked both CPU and memory. Thing is, the plugin is installed on thousands of servers with no such issues reported. It creates two threads, one sync executing once a minute and one async (yes, async is ok for what it does) executing every five hours.

    I remembered having read this thread, and was thinking that there might be some extreme edge case which causes Bukkit scheduling to trip up.

    (I'll get back here and edit this post if/when I've had an opportunity to figure out what could've caused the problem)

    I use IntelliJ (64 bit) on a Mac with Sun Java 6 (64 bit) when building.
     
  11. Offline

    Largo Usagi

    Async is fine for what my plugin does as well but i was using sync but at the time i figured that may have been the reason for shit getting out of hand.
     
  12. Offline

    ferrybig

    Async may delay the server too, when the server-pc has only 1 core, also try the java 64 bits, if your on an 64 pc, that may also solve it
     
  13. Offline

    Largo Usagi

    My pc ans server have 4 cores with 8 physical threads, but the issue was solved by compiling the code with a 32 bit version of eclipse, If some one knows why this would solve the problem when the JVM on both the client, server, and dev PC are 64 bit that would be awsome.
     
  14. Offline

    troed

    Not in any meaningful way. One core CPUs have been running thousands of threads for many many years.
     
Thread Status:
Not open for further replies.

Share This Page