Lets explain things not covered by any tutorial or javadocs!

Discussion in 'Resources' started by RawCode, Mar 22, 2014.

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

    RawCode

    It will be nice to share original research results i will start:

    Size of boolean type in java equals to "byte":
    https://github.com/RawCode/UBT/blob/master/src/rc/ubt/smpl/TrueObjectSizeExplained.java

    If only one small (byte or boolean) field declared per type, that field will consume full word, if unlucky - dword.
    Reason is simple - memory allocation rules - objects allined by dword boundary and fields referenced by offsets, offset size is 16.
    This vary for 32 and 64 bit java, but anyway there is no way to allocate field less then byte.
    Also any nonzero boolean field will be "true".
     
  2. Offline

    MRPS

    What do you want explained? I don't see a question in your copypasta.
     
  3. Offline

    Ivan

    And how is this Bukkit related?
     
  4. Offline

    L33m4n123


    Why does it has to be directly related with Bukkit? That would make the ressource section obsolete as that stuff stands here
    http://jd.bukkit.org/rb/apidocs/

    And the resouce sections is, according to its description

    And this post might be interresting if you care about memory allocating in your plugins


    Read his post again. He is not asking for an explanation ;)
     
  5. Offline

    RawCode

    I will explain much more, this thread for your (community) questions and answers about stuff not covered by javadocs, tutorial or javaspecs.

    Currently i have concurrency (sync and async tasks explained), enchantments, reflection and exceptions on list.
     
  6. Offline

    RawCode

    What is ticks and how they works?

    Two simple facts for begining -
    1) bukkit (and vanilla and spigot) are single threaded applications by design, other threads are here, but these threads are merely IOpumps handling networking and disk.
    2) No game affecting calculations shared over multiple thread or running in concurrent manner.

    Main thread of server code is (with crash recovery section omitted)
    Code:
        public void run() {
            try {
                if (this.init()) {
                    long i = ap();
                    long j = 0L;
    
                    this.p.setMOTD(new ChatComponentText(this.motd));
                    this.p.setServerInfo(new ServerPingServerData("1.7.2", 4));
                    this.a(this.p);
    
                    while (this.isRunning) {
                        long k = ap();
                        long l = k - i;
    
                        if (l > 2000L && i - this.O >= 15000L) {
                            if (this.server.getWarnOnOverload()) // CraftBukkit - Added option to suppress warning messages
                            h.warn("Can\'t keep up! Did the system time change, or is the server overloaded? Running {}ms behind, skipping {} tick(s)", new Object[] { Long.valueOf(l), Long.valueOf(l / 50L)});
                            l = 2000L;
                            this.O = i;
                        }
    
                        if (l < 0L) {
                            h.warn("Time ran backwards! Did the system time change?");
                            l = 0L;
                        }
    
                        j += l;
                        i = k;
                        if (this.worlds.get(0).everyoneDeeplySleeping()) { // CraftBukkit
                            this.t();
                            j = 0L;
                        } else {
                            while (j > 50L) {
                                MinecraftServer.currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit
                                j -= 50L;
                                this.t();
                            }
                        }
    
                        Thread.sleep(1L);
                        this.N = true;
                    }
    
    How it works:

    1)
    Code:
    while (this.isRunning)
    
    Passed as long as server is active, setting it to false will cause server termination.
    Soo it will be always true for plugins, unlikely for plugin to see this as false, but possible.

    ap() method is some kind of placeholder for advanced timetracking, it just invoke currentTime native at current time and nothing else.
    Code:
        public static long ap() {
            return System.currentTimeMillis();
        }
    
    Main server stay in constant loop with 1ms sleep time.
    Each iteration check how long prev iteration was, if iteration was longer then 2 seconds - warning thrown (max once per 15 seconds) and server time is slowed due to lost ticks.
    This caused by tick handling rules - max 40 ticks per iteration.

    In case of random slowdowns, lost ticks will be recovered, but, if tick constantly cost more then 50ms (due some coding fault or other reason) to complete time loss will be unrecoverable, each iteration will cause some of ticks to drop.

    Unrecoverable tick loss known as tickrate drop, it cause entire server and everything on server act slower.

    Sync tasks invoked directly from main thread, events also invoked from main thread, soo if some sync thread keep control longer then expected entire server will slowdown.
     
Thread Status:
Not open for further replies.

Share This Page