server
server copied to clipboard
Add metrics for certain data structure sizes
There are some dictionaries that hold strong references to their values which we should post some metrics about to make sure they aren't growing without bound. Mostly I want to know "how many elements are in the dictionary".
https://github.com/FAForever/server/blob/ccf349e3b4bbaee95373d79a0e2f4ee9c5d064a2/server/ladder_service.py#L53
https://github.com/FAForever/server/blob/ccf349e3b4bbaee95373d79a0e2f4ee9c5d064a2/server/player_service.py#L25
https://github.com/FAForever/server/blob/ccf349e3b4bbaee95373d79a0e2f4ee9c5d064a2/server/game_service.py#L46
https://github.com/FAForever/server/blob/ccf349e3b4bbaee95373d79a0e2f4ee9c5d064a2/server/matchmaker/matchmaker_queue.py#L49
@cleborys noticed:
- The size of
PlayerService._playersis already monitored byserver_user_online - The size of
GameService._gamesis equal to the sum over allserver_game_active_games_totallabels
To collect thoughts from @46bit's PR for the future:
I believe MatchmakerQueue.queue should be updated here:
https://github.com/FAForever/server/blob/a024a2fe8c8b7b905a5bdd41795f8134ee01e677/server/matchmaker/matchmaker_queue.py#L134-L135
https://github.com/FAForever/server/blob/a024a2fe8c8b7b905a5bdd41795f8134ee01e677/server/matchmaker/matchmaker_queue.py#L144-L145
and LadderService.searches updated here:
https://github.com/FAForever/server/blob/542eb721fcc7603015cf846413cc75c42f6f8bdd/server/ladder_service.py#L218
https://github.com/46bit/faforever-server/blob/a024a2fe8c8b7b905a5bdd41795f8134ee01e677/server/ladder_service.py#L250
Even if we would expect that there is a linear relation between len(matchmaker_queue.queue) and len(ladder_service.searches), I would suggest tracking both, since that might catch future bugs.
One could also write a wrapper class for a dictionary that accepts a metric endpoint on instantiation and automatically reports the new length on insertion and deletion, if one is so inclined.