paddlers-browser-game
paddlers-browser-game copied to clipboard
Full per-village state loading for each request might be inefficient
When the game-master processes a new task for a Paddler-worker, or when the satisfaction level of a visitor is computed, the entire village state with all buildings needs to be loaded from the database. More use cases are likely to come up over time.
Current Situation
The function load_village
defined in town_view.rs loads all buildings at once. This function is called from different places in the code, simply once in each function that requires this state.
Performance Considerations
Loading all the per-village data causes a series of SQL queries to the game database. This is likely to be performance relevant if there is a sizable number of players registered.
This is not a critical issue right now but it should be kept in mind. If server costs start to increase in the future, this might be one of the points to investigate.
Options for Improvement
It might be useful to have a dedicated actor which handles processing that requires the full village state. The actor could then keep some village states cached in memory. This would allow to process some requests without hitting the DB quite as many times. It is especially promising if players trigger multiple requests within a short period of time.
Different instances of the actors could handle different village ids, which would allow scaling the approach efficiently if necessary.
Status
This issue currently has no priority. No investigation has been done so far and it remains unclear how much performance could be gained, if any.