{"action":"created","issue":{"url":"https://api.github.com/repos/cuberite/cuberite/issues/3151","repository_url":"https://api.github.com/repos/cuberite/cuberite","labels_url":"https://api.github.com/repos/cuberite/cuberite/issues/3151/labels{/name}","comments_url":"https://api.github.com/repos/cuberite/cuberite/issues/3151/comments","events_url":"https://api.github.com/repos/cuberite/cuberite/issues/3151/events","html_url":"https://github.com/cuberite/cuberite/pull/3151","id":149514844,"number":3151,"title":"Smart chunk unloading","user":{"login":"LogicParrot","id":5030488,"avatar_url":"https://avatars.githubusercontent.com/u/5030488?v=3","gravatar_id":"","url":"https://api.github.com/users/LogicParrot","html_url":"https://github.com/LogicParrot","followers_url":"https://api.github.com/users/LogicParrot/followers","following_url":"https://api.github.com/users/LogicParrot/following{/other_user}","gists_url":"https://api.github.com/users/LogicParrot/gists{/gist_id}","starred_url":"https://api.github.com/users/LogicParrot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LogicParrot/subscriptions","organizations_url":"https://api.github.com/users/LogicParrot/orgs","repos_url":"https://api.github.com/users/LogicParrot/repos","events_url":"https://api.github.com/users/LogicParrot/events{/privacy}","received_events_url":"https://api.github.com/users/LogicParrot/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":95,"created_at":"2016-04-19T16:36:30Z","updated_at":"2016-06-04T12:00:54Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/cuberite/cuberite/pulls/3151","html_url":"https://github.com/cuberite/cuberite/pull/3151","diff_url":"https://github.com/cuberite/cuberite/pull/3151.diff","patch_url":"https://github.com/cuberite/cuberite/pull/3151.patch"},"body":"Work in progress. This is a smarter replacement for #3142\r\n\r\n- The server has  a `MaxChunkRAM` setting, configurable in `settings.ini` (default: 30 MiB)\r\n- The server has a `MinimizeRam` setting, configurable in `settings.ini` (default: 1)\r\n\r\n**Terminology:**\r\nDirtiness:\r\n- Clean chunk: No changes were made, no need to save to disk before unloading.\r\n- Dirty chunk: A chunk which underwent changes. Must save to disk before unloading.\r\n\r\nUsage:\r\n\r\n- Unused chunk: A chunk with no players (nor chunkStay, etc.) nearby, the server may unload this.\r\n- Used chunk: A chunk which is actively used by the game. The server must not unload this.\r\n\r\nOther:\r\n\r\n- Saving a chunk: Turns dirty chunks into clean chunks by saving them to disk. After a save, the chunk is no longer dirty and the server may unload it.\r\n- Unloading a chunk: Removing a chunk from RAM and freeing that RAM. We can only unload chunks that are both unused and clean.\r\n\r\nThe server has two saving/unloading strategies.\r\n\r\n**Strategy 1: `MinimizeRam` is 0:**\r\n The server is RAM-greedy, and uses all the RAM specified in `MaxChunkRAM` as a chunk cache in order to improve performance. Chunks are saved/unloaded as late as possible. Disk I/O is significantly reduced. Performance is improved. RAM usage is typically static and will not go below or above  `MaxChunkRAM`.\r\n - Dirty chunks are saved in 5 minute intervals to avoid data loss in case of a crash.\r\n - If current RAM usage exceeds `MaxChunkRAM`, a minimum amount of clean unused chunks is unloaded in order to preserve the `MaxChunkRAM` limit. The chunks are chosen randomly.\r\n - If there are no clean unused chunks left to unload and `MaxChunkRAM` still cannot be maintained, a save cycle is forced, allowing more chunks to be unloaded.\r\n - Other than the above three scenarios, chunks are never unloaded or saved.\r\n - The amount of RAM used by chunks is normally static and equals `MaxChunkRAM`\r\n - If the activity is too high and the `MaxChunkRAM` limit cannot be maintained even after all measures were taken, the \"agressive\" strategy is used. This happens when the RAM required by the **used chunks** exceeds `MaxChunkRAM`.\r\n\r\n**Strategy 2: `MinimizeRam` is 1:** (Might remove this strategy)\r\n The server is RAM-economic, attempts to never reach `MaxChunkRAM`. Clean unused Chunks are unloaded as soon as possible.\r\n - Dirty chunks are saved in 5 minute intervals to avoid data loss in case of a crash.\r\n - Clean unused chunks are unloaded as soon as possible, making `MaxChunkRAM` much harder to reach in comparison with the previous scheme.\r\n - If current RAM usage exceeds `MaxChunkRAM`, a save cycle is forced, allowing more chunks to be unloaded.\r\n - Other than the three above scenarios, chunks are never unloaded or saved.\r\n - If the activity is too high and the `MaxChunkRAM` limit cannot be maintained, the \"agressive\" strategy is used. This happens when the RAM required by the **used chunks** exceeds `MaxChunkRAM`.\r\n\r\n**\"Agressive\" strategy**:\r\n - Dirty chunks are saved in 5 minute intervals to avoid data loss in case of a crash.\r\n - Whenever a chunk becomes unused, it is unloaded asap (and saved if dirty).\r\n - The agressive strategy is technically nonexistent and does not have its own code. It's just what happens when the server is constantly above `MaxChunkRAM` in either strategy.\r\n\r\nAdditionally, this closes #3166 "},"comment":{"url":"https://api.github.com/repos/cuberite/cuberite/issues/comments/223751892","html_url":"https://github.com/cuberite/cuberite/pull/3151#issuecomment-223751892","issue_url":"https://api.github.com/repos/cuberite/cuberite/issues/3151","id":223751892,"user":{"login":"SphinxC0re","id":3702016,"avatar_url":"https://avatars.githubusercontent.com/u/3702016?v=3","gravatar_id":"","url":"https://api.github.com/users/SphinxC0re","html_url":"https://github.com/SphinxC0re","followers_url":"https://api.github.com/users/SphinxC0re/followers","following_url":"https://api.github.com/users/SphinxC0re/following{/other_user}","gists_url":"https://api.github.com/users/SphinxC0re/gists{/gist_id}","starred_url":"https://api.github.com/users/SphinxC0re/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SphinxC0re/subscriptions","organizations_url":"https://api.github.com/users/SphinxC0re/orgs","repos_url":"https://api.github.com/users/SphinxC0re/repos","events_url":"https://api.github.com/users/SphinxC0re/events{/privacy}","received_events_url":"https://api.github.com/users/SphinxC0re/received_events","type":"User","site_admin":false},"created_at":"2016-06-04T12:00:54Z","updated_at":"2016-06-04T12:00:54Z","body":"Any updates on this one? @LogicParrot "}}
{"actor":{"display_login":"SphinxC0re"}}