Queued chunk generation | Slow down chunk generation speed

Discussion in 'Plugin Development' started by ravand, Aug 23, 2014.

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

    ravand

    I am currently working on a plugin that allows every player to have their own worlds with their desired permissions, plugins, whitelists and pretty much everything you would need for a private setup.

    Now my problem is the disk write capacity that is easily reached when alot of new chunks are being generated from players exploring and initially creating their world. The whole machine suffers from the disk being occupied by generating chunk files.

    An workaround of how to get rid of this problem is putting all the wolrds on ramdisk to eliminate lag from writing to files. This is a rather unpleasant solution so my question is if there is any way in bukkit to stop the chunks from getting generated all at once, maybe a way to queue/buffer them or maybe only allowing a few chunks to be generated as a hard limit in a defined interval.

    I have tried searching for plugins that might do what i am searching for but with no luck, maybe u know more.

    Thanks in advance
    ravand
     
  2. Offline

    mrCookieSlime

    Well a solution would be to lower the render distance in the server.properties .
    Since it would then generate less chunks around the Player.
    But some people might get upset, because they cannot look that far anymore.
     
  3. Offline

    ravand

    Ye i have considered lowering the render distance and for a survival based server setup this wouldn't even bother that much, but i fear this wouldn't solve my problem because if many people are online the disk write will still be occupied alot, i was actually looking for a way to prevent bukkit from generating all of the chunks at once codewise. Isn't there anyway to play around with the chunk generation events?
     
  4. Offline

    xTrollxDudex

    Proxy chunkloader classes
     
  5. Offline

    ravand

    Hmm interesting never heard of that before i'll have a look at it. Can you specify a little bit on how to get started with that, can you maybe provide an example?
     
  6. Offline

    xTrollxDudex

    Limit requests to ChunkServerProvider through replacement class in World
     
  7. Offline

    ravand

    That doesnt quite help me im afraid...
    Can you give a code example of how to do that?
     
  8. Offline

    xTrollxDudex

    PHP:
    World world // ...
    WorldServer ws = ((CraftWorldworld).getHandle();
    ws.chunkProviderServer = new ClassProxyCps();

    private class 
    ClassProxyCps extends ChunkProviderServer {
        private final 
    Table<IntegerIntegerChunkchunks HashBasedTable.create();
        private final 
    LazyTimer timer = new LazyTimer();

        @
    Override public Chunk getChunkAt(int iint j) {
            if (
    this.timer.passedEpoch()) {
                if (!
    table.isEmpty()) {
                    
    Chunk c table.get(ij);
                    if (
    != null) {
                        
    table.remove(ij);
                        return 
    c;
                    }

                    
    table.put(ijsuper.getChunkAt(ij);           
                } else {
                    return 
    super.getChunkAt(ij);
                }
            } else {
                
    // Wait for it to pass the epoch
            
    }
        }
    }

    private class 
    LazyTimer {
        public static final 
    long DELAY 15_000// Adjust to your liking. 1 millis = 1/1000 seconds
        
    private long start;

        public 
    LazyTimer() {
            
    this.reset();
        }

        public 
    boolean passedEpoch() {
            
    boolean passed = (System.currentTimeMillis() - this.start) > LazyTimer.DELAY;
            if (
    passedthis.reset();
            return 
    passed;
        }

        public 
    void reset() {
            
    this.start System.currentTimeMillis();
        }
    }
     
    AoH_Ruthless and ravand like this.
  9. Offline

    ravand

    Thanks for the example and for your time.

    I still have two questions tho, how do i initiliaze this? Will this only work on a world creation or will this also work for later generated chunks?
     
  10. Offline

    xTrollxDudex

    I reccommend that you get the world from WorldInitEvent. Also remember to fill in the else statement, currently, I'm still debating the chunk to return or the waiting statement, but I haven't decided yet.
     
  11. From my personal experience, as a Server Owner, I have suffered lots of time dealing with RAM issues.

    I suggest setting a world limit (border let's say) on each world that the player generates, so after a certain amount of blocks (ex. 5000) the player will not be able to walk further, and chunks will not get generated. Any other than that, try @xTrollxDudex's answer, and also, encourage your clients to install optifine.
     
  12. Offline

    xTrollxDudex

    It won't help if they have distance set to "extreme", which is above the normal limit for distance rendering.
     
  13. Offline

    ravand

    My plugin already has a built in border radius but nontheless setting limits to the world won't help from many chunks getting generated by lets say 10 players who all are on their own world.
     
Thread Status:
Not open for further replies.

Share This Page