Efficient way of loading multiple worlds

Discussion in 'Plugin Development' started by xDeeKay, Feb 26, 2015.

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

    xDeeKay

    I have about 30+ worlds I need to be loaded, but I've yet to find an efficient way of doing so.
    I've tried looping through all the worlds and loading them using the WorldCreator, but when doing so, the server usually runs out of memory.

    Here's what I was doing if you're curious:
    Code:
            for (String worlds : worldConfig.getConfigurationSection("worlds.normal").getKeys(false)) {
                String worldNames = worldConfig.getString("worlds.normal." + worlds + ".name");
                this.getServer().createWorld(new WorldCreator(worlds));
                getLogger().info("Loaded world: " + worldNames);
            }
    I've tried loading the world when a player uses a command to get there, but then comes the issue of the worlds not being loaded when using warps and homes from other plugins like Essentials. There's also the obvious issue of a player logging into the server in an unloaded world, so that won't work.

    How can I achieve this as efficiently as possible?
     
  2. Offline

    teej107

    30+ worlds is a lot. If your server runs out of memory, you'll need to get more RAM. I doubt there is a more efficient way of loading a world.

    EDIT: Do you intend to create a new world if it does not exist?
     
  3. Offline

    xDeeKay

    @teej107 Indeed it's a lot of worlds, but we are running that many worlds with Multiverse with no issues, which is why I thought there might be some trick to it that I'm missing. It only runs out of memory when I use the above code to load all the worlds onEnable. If the world doesn't exist, then I guess it will create a new one, but there should never be a world in the worldConfig that doesn't exist.
     
  4. Offline

    mine-care

    Why you want all those worlds loaded at once?
     
  5. Offline

    xDeeKay

    @mine-care They need to be loaded for a few reasons.
    1. If a player logs out in a world, the world needs to be loaded for when they log back in; it will not load itself.
    2. If a player were to initiate a command which is to teleport them to a world, that world needs to be loaded. ie /warp, /home, etc.

    I'm sure there's more, but these are the issues I've come across so far, which is why I need them loaded to a degree when the server starts. By all means if there's a better way, let me know. That's why I made this thread.
     
  6. Offline

    mythbusterma

    @xDeeKay

    30+ worlds is quite a few worlds, I don't see why you would need that many. Also, if a player logs in and is in a world, the server will load the world as needed, so you don't need to keep the other worlds in memory.
     
  7. Offline

    mine-care

    @xDeeKay
    ^
     
  8. Offline

    xDeeKay

    I don't quite understand this. It's totally irrelevant as to what I'm asking. I have reasons for the amount of worlds that are running.

    Please see point 2 then, it's still an issue..
     
  9. Offline

    mythbusterma

    @xDeeKay

    There isn't a reason to have that many worlds running. I'm sure your incredibly vague reasons are necessary.

    A cursory glance at the source of Multiverse doesn't look like it loads all the worlds at once anyway.

    Executing a command that puts a player in a world will load that world on a normal server, so I don't see what your issue is.
     
  10. Offline

    xDeeKay

    @mythbusterma Excuse me? Since when is it up to you to be telling me how I'm allowed to run things? I've explained what I'm trying to achieve, yet you insist on telling me what I'm doing isn't necessary?

    My "incredibly vague" reasons were "incredibly vague" because believe it or not I haven't even told you yet. I don't feel I need to explain that because that wasn't the point of this thread.

    But if you're really dying to know for some reason, the reason for needing 30+ worlds is because it's the nature of our server. We run a Creative server with very small 'per-rank' flat worlds. Once a world becomes full, we create a new world for that rank. There are also several player owned worlds. It's fairly simple.

    If you're going to start telling me this is wrong, stop typing. We've been running this setup for months now with no problems.


    You're wrong here, it does not. I set a home in a world that was loaded, restarted the server, tried to use /home and it said something along the lines of "invalid world". These are not the default overworld, nether, and end worlds I need loaded.

    What does Multiverse do then exactly?
     
  11. Offline

    mythbusterma

    @xDeeKay

    I'm can't stop you from doing something, but I can certainly recommend against it, which is what I'm doing.

    Simulating 30 worlds at once is a tremendous burden on a server, which is why I would say don't load them all.

    It seems that Multiverse loads the world as needed, their source is here if you want to look at it.

    Also, why don't you just use Multiverse to do this? Their plugin is stable, well-developed, and has an API.

    You could also try scheduling out the loading over a few seconds, or even minutes, to see if that makes it a bit easier on the server to keep up. You may also want to try running your server on Java 8 with concurrent mark sweep and parallel new garbage collector, as those will ease the burden on your server.
     
  12. Offline

    xDeeKay

    What do you mean by this? From my observations, once the server starts, Essentials is saying there are 31 worlds available. If Multiverse isn't loading the worlds when the server starts, then what's it doing?

    I'm fairly positive Multiverse is doing something fancy to load the worlds when the server starts.
     
  13. Offline

    Webbeh

    Multiverse has a list of known worlds in its config.

    When the server starts, it checks if the worlds are still present in the hard drive, and loads them IN ITS PLUGIN only.

    When a player logs in, it loads the world where the player has to go (either where he left last time, or basic spawn, or the position your set with your own plugin). It does it automatically, you don't have to do anything.

    Now, if you want to keep them loaded, let them load alone, but cancel all chunkunloadevents. Maybe do a scheduler that checks every 30 minutes or so if there's still a player in the loaded world, and if not, unload all chunks. Most people don't mind having to wait a few seconds for a world to load around them.

    Also if you want chunks around /warps to stay loaded, you'll have to do your own warp plugin, or find one that does what you're looking for. But 30 worlds is really heavy. I hope you're not on a VPS. Not for you, but for other people trying to use that VPS.
     
  14. Offline

    xDeeKay

    @Webbeh Thanks for the explanation. Again, the worlds are flat, very small, and we've disabled most entities so that building is more or less the only thing you can do. Not to mention there's pretty much never a player in every single world; usually only 3-4 worlds have players in them at a time.
     
  15. Offline

    mythbusterma

    @xDeeKay

    Like I said before then, try distributing the loading of them across a time span. Also, why not use Multiverse? Like I said before.
     
  16. Offline

    xDeeKay

    @mythbusterma There's no reason for not using it, we still are. I'm just experimenting and trying something different.
     
  17. Offline

    mythbusterma

    @xDeeKay

    Well, that'd be the easiest way, especially since they have a pretty robust API.
     
  18. Offline

    xDeeKay

    @mythbusterma I love their plugin, which is what gave me the inspiration to start learning the whole world creation side of Bukkit. I'm not necessarily going to ditch Multiverse and start using my plugin, I just like learning this way.

    Thanks for the help.
     
  19. Offline

    1Rogue

    You had the right idea but you fell off when you thought the solution was to load all of your worlds at once. Try loading only the ones that you need.
     
  20. Offline

    xDeeKay

    @1Rogue That's the thing though, I don't need one world loaded more than the next. The worlds I need loaded depend on where players login, or where they need to be teleported to, etc. I was able to load a few worlds manually by using their names, but in the end that wasn't what I needed to achieve.
     
Thread Status:
Not open for further replies.

Share This Page