Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unload chunks #488

Closed
wants to merge 5 commits into from
Closed

Unload chunks #488

wants to merge 5 commits into from

Conversation

Saiv46
Copy link
Contributor

@Saiv46 Saiv46 commented Mar 8, 2021

Yes, flying-squid keeps all chunks loaded until got Out-Of-Memory error

@rom1504
Copy link
Member

rom1504 commented Mar 8, 2021

what is the idea of the change ?

if you want to decrease world memory, one solution could be a LRU, but this should be happening in pworld, not in flying-squid

@Saiv46
Copy link
Contributor Author

Saiv46 commented Mar 8, 2021

what is the idea of the change ?
The idea is to actually unload chunks when player is too far from it (not just remove a key from player.loadedChunks ), same when using /changeworld. Now we have a server.chunksUsed with chunk keys and counter of it - unloading chunks that is not used by calling corresponding method of pworld.

In pworld a LRU can be implemented (and I'll implement it someday), but that's optional.
The goal of PR is to bring some stability to the running instance of flying-squid by reducing memory usage.

@rom1504
Copy link
Member

rom1504 commented Mar 8, 2021

You can't actually remove the chunks if one player get too far as other players may still need them.

So you need a strategy to decide when to remove chunks.
The more memory efficient solution would be to keep only the union of what players need now but it would increase compute (would need to regenerate or reread chunks more often)
A less memory efficient but nicer on compute solution is LRU, to keep the chunks a bit longer in case players move back.

@rom1504
Copy link
Member

rom1504 commented Mar 8, 2021

It seems you implemented the first solution I'm mentioning.
Maybe you can put it under an option so people can choose ?

@Saiv46
Copy link
Contributor Author

Saiv46 commented Mar 8, 2021

You can't actually remove the chunks if one player get too far as other players may still need them.

I implemented a counter for that. The only problem I see is when players in two dimensions are loading chunks at same position - server will keep both and unload only one.

So you need a strategy to decide when to remove chunks.
The more memory efficient solution would be to keep only the union of what players need now but it would increase compute (would need to regenerate or reread chunks more often)

Unlike java server, flying-squid is very fast at regenerating/rereading chunks (even at max (64 chunks) render distance).

A less memory efficient but nicer on compute solution is LRU, to keep the chunks a bit longer in case players move back.

That should be implemented in pworld, also see: PrismarineJS/prismarine-design#1

Copy link
Member

@rom1504 rom1504 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you either add a _ before all these new methods in serv and player
either document them all

the first option is probably best as it doesn't seem like these methods should be exposed

@rom1504
Copy link
Member

rom1504 commented Mar 20, 2021

do you intend to finish this? a minor change is still missing

@rom1504
Copy link
Member

rom1504 commented Mar 28, 2021

Thanks, merged in @KaffinPX PR

@rom1504 rom1504 closed this Mar 28, 2021
@Saiv46 Saiv46 deleted the patch-1 branch August 13, 2021 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants