Thread: Disk I/O

Results 1 to 5 of 5
  1. #1 Disk I/O 
    Banned Disk I/O Market Banned


    Join Date
    Jan 2011
    Age
    26
    Posts
    3,112
    Thanks given
    1,198
    Thanks received
    1,479
    Rep Power
    0
    Everyone knows its ideal to do all disk io (loading/saving character files, chat logs, etc.) on a separate thread. Writing is obviously easily done but what about reading? If you wanted to do reading wouldn't you have to use a Phaser or some other sort of blocking object (CountDownLatch would work too) and make the game thread wait on the disk io thread to retrieve the data? Wouldn't that kill the whole point of having a separate thread to do it anyway?

    So the idea I came up with was load the data for files on start up so when its needed it can be accessed from a collection. Take for example character files. I could loop through every single file in the ./data/players/ directory and put it in a map: the String key being the name of the player and PlayerData being the data loaded from the character file:

    Code:
    // every single character file in this map
    private Map<String, PlayerData> playerFiles = new HashMap<String, PlayerData>();
    
    
    public void decodeLogin() {
       
       ...
    
      // time to load the character file! we don't have to load it here cause we did it on startup already
      PlayerData data = playerFiles.get(player.getUsername());
      
      // now we set the data like we'd normally do...
      player.setPosition(data.getposition());
      player.setAuthority(data.getAuthority());
      player.setRunEnergy(data.getRunEnergy());
      ...
    }
    But wait! There's a problem with that. If a character logs out and logs back in there progress will only be saved to the last time that the server was started up! So I came up with this idea: for saving the character file, simply re-add it to the map and save the character on the disk io thread as normal!

    Code:
    playerFiles.put(player.getUsername(), new PlayerData() {
          // ... some sort of implementation here to get all the correct data saved
    });
    
    // and here we use our disk io thread to save the actual file! (for the next startup)
    GameEngine.getDiskPool().execute(new Runnable() {
         @Override
         public void run() {
              // save the actual character file like we'd normally do
              DiskFactory.getCharacter().write(....);
         }
    });

    Right now I honestly can't see how this solution would be flawed, I told a friend about it earlier and he said it was a retarded idea but I'm convinced that its not. Would appreciate it if someone could tell me if its stupid (or not) and why (or why not)

    If you think this is stupid how do you think it should be done? Would love to hear some alternatives.

    thanks for reading!
    Reply With Quote  
     

  2. #2  
    Respected Member


    Join Date
    Jan 2009
    Posts
    5,743
    Thanks given
    1,162
    Thanks received
    3,603
    Rep Power
    5000
    I queue file loads on the same thread io is done and once complete it is queued to complete the login process back on the game thread. Caching the character for 5 - 10 minutes after logout seems a good idea, but caching all characters on start up yeah no not unless you have an excessive amount of memory, you're overthinking things.
    Reply With Quote  
     

  3. #3  
    Member Disk I/O Market Banned


    Luke132's Avatar
    Join Date
    Dec 2007
    Age
    35
    Posts
    12,574
    Thanks given
    199
    Thanks received
    7,106
    Rep Power
    5000
    So the idea I came up with was load the data for files on start up so when its needed it can be accessed from a collection. Take for example character files. I could loop through every single file in the ./data/players/ directory and put it in a map: the String key being the name of the player and PlayerData being the data loaded from the character file:
    pointless, if it was beneficial it would've already been done like that

    Attached imageAttached image
    Reply With Quote  
     

  4. #4  
    Community Veteran



    Join Date
    Jan 2008
    Posts
    3,444
    Thanks given
    46
    Thanks received
    973
    Rep Power
    4748

    So the idea I came up with was load the data for files on start up so when its needed it can be accessed from a collection. Take for example character files. I could loop through every single file in the ./data/players/ directory and put it in a map: the String key being the name of the player and PlayerData being the data loaded from the character file:

    Lol gf your ram


    Also if server designed correctly then you wouldnt need to use a phaser or any other concurrent shit

    Basic design if using login server
    HandshakeDecoder - loginDecoder - send Request to loginServer

    When loginServer send the data back to server u then do

    LoginServerDecoder - - Rest of the login eh registering player.. sending response block

    Reply With Quote  
     

  5. #5  
    Banned Disk I/O Market Banned


    Join Date
    Jan 2011
    Age
    26
    Posts
    3,112
    Thanks given
    1,198
    Thanks received
    1,479
    Rep Power
    0
    ok starting to see how this might be a bad idea

    im looking up other alternatives, maybe I could use an AsynchronousFileChannel? along with caching the data for maybe 10 minutes after logout is completed
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. 562-Disk of Returning-Rs2hd
    By Trapt in forum RS 503+ Client & Server
    Replies: 20
    Last Post: 11-06-2010, 06:34 AM
  2. Disk of returning
    By Colby in forum RS2 Server
    Replies: 25
    Last Post: 08-10-2010, 07:30 PM
  3. Disk space - Clipping via regions.
    By Peril in forum Help
    Replies: 10
    Last Post: 06-17-2010, 06:20 AM
  4. Xp Disk
    By Sir Lethal in forum Software
    Replies: 3
    Last Post: 01-25-2009, 02:38 AM
  5. create a password reset disk
    By Pride in forum Software
    Replies: 1
    Last Post: 08-30-2008, 10:06 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •