https://metaplay.io logo
Scheduling recurring actions for players, e.g. eve...
# questions-and-feedback
a
Hi, is the Akka scheduler the recommended way to schedule some activity for a player e.g. in a few hours, or does Metaplay build something on top which is preferred? The Akka stuff seems good to trigger things for the PlayerActor so I'd be happy to go with that but just wanted to verify. https://getakka.net/articles/actors/schedulers.html the examples on the bootcamp page include:
Copy code
csharp
system
.Scheduler   .ScheduleTellRepeatedly(TimeSpan.FromMinutes(30), TimeSpan.FromMinutes(30),
    someActor, someMessage, ActorRefs.Nobody,
    cancellation); // add cancellation support
https://github.com/petabridge/akka-bootcamp/blob/master/src/Unit-2/lesson3/README.md
I'm actually leaning on adding a DB scan job instead which checks from the PlayerModel and other game data whether that Player should be acted on then or not .. i think that scales better than adding a million timers
j
Timers would actually not work because they only run during the entities lifetime (maybe there's some way around that but that's how it works for us generally)
Scanjobs is an option but they're a bit clunky and are definitely not precise
Perhaps just checking on entity start whether x time has expired would work good enough?
a
i want this to work when the player is offline we may want to send a notification when the periodic operation results in a state which exceeds a threshold, for example i made a DB scan job for this i run it every 5 minutes now and the timing for this is usually once per 1h .. so it does not need be accurate, something like +/-2 minutes is fine. but it's individual per player
i think it would be possible to optimize that so that when related things with a Player change, it could set a time-for-next-check-for-me field in the DB, and then a single DB query would find which players need to be (maybe) acted on but currently with our small number of test users i think the scan is fast enough maybe if it's hard to scale later i'll drop the scan & notify-offline-players possibility and just do it at login
n
Yeah, scan jobs that loop over all the players will get quite slow and/or resource-hungry when there's lots of players, so although it can work ok with a small player base, it may not be the ideal long term solution for this. If the operation has predictable timing (i.e. you can calculate when the player's next notification should happen), this could be a device-local notification instead. If it's not predictable, but rather need to try the operation and check the outcome to know if the notification needs to be sent, that might need some kind of custom server-side mechanism. Like an entity to which you could register these per-player scheduled operations and that entity would handle the timers and wake up the player entities at right times. That could possibly be made into a generic SDK feature but at the moment it does not exist. At big scale, the implementation would probably need some sharding to avoid dealing with huge player lists in a single entity. Or, your idea about the time-for-next-check DB field sounds like a viable approach as well. It could be a separate database table (separate from the main Players table) with an index with the time-to-check column, to ensure fast queries. Regardless of the actual mechanism, proactively doing server-side operations for all players can be troublesome as it can cause spikes if the operation happens at roughly the same time for all (or very many) players. If the operation is known to happen at different times for different players, and therefore spread out smoothly over time, it should be okay.
a
oh the dedicated entity for this would work very well i think! i have a few of them for other purposes and it's a very nice mechanism thanks! i'll copy-paste the info to an improvement-issue about this for later
BTW i think the akka.net Scheduler thing would work also when the Player entities are shut down, no? maybe it is like such an entity already anyway, a dedicated entity for this purpose would suite our need nicely
oh and the times for these are individual per player so they should spread out nicely also, they don't need to be so exact so the current DB scan is kind of safe regarding spikes as it does it one by one
5 Views