I program MMO strategy game (C# monogame) like Goodgame Empire or Travian for Windows Phone.

The server part of the game will run on Windows Server and MS SQL database.

I'm trying to figure out a way to perform periodical operations over players' data. My point is that, for example farm will produce one piece of food every minute and I need store it to database in real time.

I thought about that when registering a new player would cause the database start new job, but for example at 2000 players on the server I'm not sure if I do not kill performance. I want to find optimal solution and I wanted to ask your opinions on what you think would be the best solution.


2 Answers 2


Why do you want to start a new job for every single player?

Create a single job that calculates the updates every minute for all players. This should be a lesser performance impact.

Edit based on comments

When doing this in a single job then use a single transaction for this job then no player gains an advantage as the new values are visible at the end of the transaction.

  • \$\begingroup\$ Because time for update all players by 1 job takes more time. This may caused one player will be updated in time but player 1000 will be updated after 12 seconds for example. If job is something like thread in c# then every job start is started parallel... \$\endgroup\$
    – Earlgray
    Sep 22, 2014 at 12:07
  • 3
    \$\begingroup\$ @Earlgray if you use transaction in the database (which is highly recommended) then all players will be updated at the end of the job at the same time. Therefore there is no advantage for a single player. \$\endgroup\$
    – Uwe Plonus
    Sep 22, 2014 at 12:10
  • 1
    \$\begingroup\$ Agree. You should use a shared Cache system for all the users, and a scheduled job to refresh the values. It's better to have one single thread which sends queries to the database continuously instead multiple connections even if they're lesser frequent \$\endgroup\$
    – simoneL
    Sep 22, 2014 at 12:17

Personally if it were me I would separate this for simplicity.

Here's how ...

  1. Create an API call on your game server that will handle the saving of player
  2. Create a new executable that would simply make an api call to my game server every minute.
  3. Schedule that using windows task scheduler

The new exe can then be configurable to call any number of things every minute.

The other way if you don't want the separation is to have something global and static on the server that contains a timer and on every "elapsed" event call the api method talked about above.

I tend to go for separation that way my server can just literally be a bunch of API calls.


Not the answer you're looking for? Browse other questions tagged .