I am creating a browser-based MMO that has time-based events: I.E. the construction of a building will take 23 hours.
I can log that in my MySQL database and then loop through an events table (or equivilent) using a cron script or watch
(this question was immensely helpful).
There seems to be a general consensus that I can either:
(1) Run a cron job every second for a script that processes the events and their related triggers.
(2) Run a cron job every minute that loops every second for 59 iterations that processes the events and their related triggers.
(3) Use watch
to run a php script every second.
Essentially, upon completion of an event, the script will process some triggers that range anywhere from changing states, updating databases, triggering other "events" that are queued after the recent event, and so on.
My biggest concerns come where there is the potential to have 10,000+ events and triggers to process every second. What are some strategies I could use to avoid performance concerns? Are these all of the solutions, or are there better alternatives?
Example events:
Construction of Building A - 00:43:21
Fast forward 2601 seconds and the following triggers are executed:
Place Building A on map at Location x,y
Update resource total given by building
Start timer on next building in the queue
Construction of Building B - 02:10:49
To better explain: In the early stages of the game these events will take anywhere from 5 minutes to an hour. In the later stages of the game these events will be spaced apart by hundreds of hours. I need these events to process in real time because they will impact other aspects of the game (Such as a resource structure improving the amount of resources given every hour). Thus, these events need to be processed by the server, regardless of whether or not the user is active. The theoretical script would check for expired events, and then based on the event, run several other methods related to the expiration of said event.