[Plugin] Multithreading server - help

Discussion in 'Plugin Development' started by pomo4ka, May 30, 2011.

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

    pomo4ka

    Hi, UTB is my first topic in this section, I really want to learn to make their plug-ins, I have the desire and time, but I do not know where to start.

    I looked tutorial from @Samkio and seems to be little understood. I want to make a plugin that would run the server on all the core machinery. Rummaged through the internet and found a couple of articles, how to implement multithreading. In the end, I turned a little script.
    Code:
    public class Archiver implements Runnable {
        public static AtomicLong count = AtomicLong(0);
        public static String[] tasks;
        class Task implements Runnable {
            Task(String taskId) {
                this.taskId = taskId;
            }
            //...
            public void run() {
                long delta = something(taskId);
                delta += somethingElse(taskId);
                delta += commit(taskId);
                synchronized(count) {
                    count.addAndGet(delta);
                }
            }
        }
        public void run() {
            int processors = Runtime.getRuntime().availableProcessors();
            ExecutorService pool = Executors.newFixedThreadPool(processors);
            for(String id : tasks)
                pool.execute(new Task(id));
            pool.shutdown();
            try{
                if(!pool.awaitTermination(20, TimeUnit.MINUTES))
                    throw new InterruptedException("Time Limit Exceeded");
            } catch(InterruptedException e) {
                e.printStackTrace();
                pool.shutdownNow();
                System.exit(1);
            }
            System.out.println(count);
        }
        public static void main(String[] args) {
            tasks = args;
            new Thread(new Archiver()).start();
        }
    }
    
    If something is wrong, correct me please. Can a living creature to help me in implementing this idea? I'll be very grateful for the help. Thank you.
     
  2. Offline

    Gandalf

    Why on earth would you want to multithread as a beginner, that is one of the more advanced concepts of programming and requires a knowledge of locks, synchronized threads, asynchronized threads, how to use them in conjunction of each other, etc.

    Just learn basic Java first and move on from there, start from Hello World and work your way up.
     
    Daniel Heppner likes this.
  3. Offline

    Jayjay110

    Multi-wat? wtf were did u learn this stuff :p
     
  4. Offline

    pomo4ka

    I've tried to do "Hello World", error when connecting the plug to the server. :(
     
  5. Offline

    Sammy

    My mind is blown !
    This is like wanting to learn how to drive with a F1 ^^
    Better, its like learning to fly jumping of a bridge ihihi
     
  6. You shouldn't really need to use multi-threading for plugins anyway, not like their that processor intensive.
     
  7. Offline

    Sammy

    But he wants to do even 'worst'...
    He wants to multi thread the bukkits server ^
     
  8. So he want's to multi-thread the actual server. That is not a good idea for a beginner :p
     
  9. Offline

    pomo4ka

    Thank you very much for all the help. Well, everything seems to be, I figured in the creation of plug-in.
    Made the lesson "Adamki11s":
    Code:
    package me.pomo4ka.test;
    
    import java.util.logging.Logger;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class test extends JavaPlugin{
    	Logger log = Logger.getLogger("Minecraft");
    	public void onEnable(){
    		log.info("Test plugin is enabled!");
    	}
    	public void onDisable(){
    		log.info("Test plugin is disable!");
    	}
    	}
    
    Tell me please, which way to go, to know in detail the "Java"? :)
     
  10. On the tutorial there should be a link to thenewboston's java video tutorials, they're a great place to start.
     
  11. Offline

    Jayjay110

    Whats multi-threading?
     
  12. Offline

    Sammy

  13. Offline

    pomo4ka

    Who knows how this can be done? :)
     
  14. Offline

    Gandalf

    Multithreading is actually more CPU intensive. However it allows you to run multiple parts of your program concurrently such as monitor and log in separate threads.

    I do but I don't understand what you need it for....

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

    Sammy

    I will give you a example.
    A couple of months ago there was a team of 10 Developers give or take.
    There were trying to do this for many months, they made a development pdf with a a huge amount of info about sockets, thread conjunctions etc etc.
    THEY GAVE UP and they were all pro developers ^^

    Long story short.... don't aim that high for your first plugin.... :)
     
  16. Offline

    Gandalf

    That's called hyperthreading, totally different concept.
     
  17. Offline

    pomo4ka

    I need to run the server on all the cores. Is it possible?
     
  18. Offline

    Sammy

    But thats what he said he wanted to do.
     
  19. Offline

    Gandalf

    Frankly, not for you, and not for me either.

    I was just saying that isn't multithreading, that is hyperthreading.
     
  20. Offline

    pomo4ka

    I'll quote the message, which was written by Russian developers server under Minecraft.
    Link: http://blog.greencubes.ru/?p=12

    Multithreading - all processes on the server will be processed in separate threads (growth of grass and trees, burning stoves, the movement of mobs, the preservation of peace, the players, day and night) that will allow a full load arbitrarily powerful server, up to a cluster.
     
  21. Offline

    Gandalf

    Yes running them on separate threads but all on the same core. It increases efficiency and utilizes more resources. The MC server already has multithreading.
     
  22. Offline

    pomo4ka

    You mean version 1.6?

    On the server, Notch, and our plans

    Long ago it is no secret that the team GreenCubes.ru develops its server Minecraft. In this message I want to share some information, why is it all about and where we spend all our human resources.
    We already wrote about what bad Notch original server, but I allow myself to repeat the points that we do not like most.
    Let's start with the fact that the Notch, on our hypothesis, wrote a game for single player, and then simply divided into two parts - client and server, talking about it a lot of rudimentary code in the server, which is absolutely not used and only on the client side. From all this implies the following disadvantages:
    • Absolute single-threaded server
    A very powerful server GreenCubes.ru because of this almost entirely idle, since of all processor cores using a single 100% and a little more on the needs of the system, and most Java-machine. This is absolutely the wrong approach, which is good only for the game alone: all the events from all players, all movement of mobs, trucks, growth of grass and trees, day and night - everything it falls on one core and, moreover, is waiting for completion of the previous action!
    • Curve of the server code
    Notch, despite the opinion of most people, quite a good programmer - he uses at times, very good and effective approaches to solving various problems. But he never wrote a server on the calculation that it has to be simultaneously connected to more than 100 players, as it is now GreenCubes.ru.
    • Third-party modification of the server (Bukkit, hey0)
    Of course, this is not the fault of Notch, but it is still a problem - a third-party modification (especially popular now Bukkit, which is installed on Greencubes) like "obvorachivayut" original server Notch, which creates another problem: once the code. In times of hey0, this problem was not that relevant, because he made few modifications to the server. But Bukkit - very big and heavy modes, and each event is processed further and Bukkit'om, as well as it creates additional classes that duplicate classes Notch to make it easier for developers to write plug-ins.
    What will we do with this?
    It's simple: we write your own server Minecraft. And this server will be designed to service a large number of players. According to an exemplary forecast of at least 200-300 with no lag. This will be achieved by the following features of the new server:
    • Multithreading - all processes on the server will be processed in separate threads (growth of grass and trees, burning stoves, the movement of mobs, the preservation of peace, the players, day and night) that will allow a full load arbitrarily powerful server, up to a cluster .
    • Own modifications - most plugins GreenCubes.ru written by us, so we do not do support Bukkit and third-party plug-ins, but simply integrated directly into the server code to its fashion.
    • Changing systems of conservation - saving more does not affect the gameplay and will happen in the background.
    • Support for multiple worlds - the server will be built native support for several of the worlds, but not implemented by external plugins.
    • Built-in anti-cheat - we lay on the shoulders server predraschet player's position and his actions with the inventory that does not allow users to fly, run faster than allowed, as well as to steal from the chests and DUPAL "items.
    What have we done?
    On average, the new server ready at 15%. We have already implemented the basic structure, the generation of the world (both conventional and hell) using algorithms Notch, a network protocol.
    When can I see all this?
    We are working as fast as we can. Closed Betatest scheduled to begin next week.
    There will be a wipe?
    None. Wipe the main world Greencubes will not. We promised.


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

    Gandalf

    Yes the MC server already does this.

     
  24. Offline

    pomo4ka

    Okay, thank you very much. I hope this makes bukkit too :)
     
  25. Offline

    Lolmewn Retired Staff

    Then I don't see the point of trying to add it :p
     
    pomo4ka likes this.
  26. Offline

    pomo4ka

    Now, I do not see the point. Now we need to think about how to get rid of the large consumption of RAM. :)
     
  27. Offline

    Gandalf

    Rewrite the server.
     
  28. Offline

    pomo4ka

    Logically of course, but alas, I do not have such experience with Java.
     
  29. Offline

    Sammy

    As far as I know the MC server's development is almost stagnated since the alpha, notch is always making new "small" stuff but don't really messing with the core of it all in a significant way.
    So we need to nag him to make an updated just dedicated to the MC server.
     
Thread Status:
Not open for further replies.

Share This Page