Improve MMO game performance

点点圈 提交于 2019-12-13 18:26:06

问题


we are all aware of the popular trend of MMO games. where players face each other live.

My area of concern, is storage of player moves and game results.

Using Csharp and PostgreSql v9.0 via NPGSQL adapter

The game client is browser based ASP.NET and calls Csharp functions for all database related processing

To understand my query, please consider the following scenario

we store game progress in a postgres table.

For Example a tournament starts with four players and following activity

  1. Each player starts with 100hitpoints
  2. player 1 makes a strike (we refer to a chart to convert blows to hitpoints with random-range %)
  3. player 2 has 92HP, and returns a light blow, so player1 has 98hp

The above two round will now be in Game Progress Table, as

ROW Player1HP Player2HP Strikefrom StrikeTo ReturnStrikeHP Round TimeStamp StrikeMethod
1      100       100         0        0            0          0
2       98        92        P1        P2           2          1

To find if tournament has ended we check 3 players have zero hitpoints Or gametime has elapsed a stipulated timeout value from last progress

our table has a primarykey as tournamentid a random 32 character code on basis of playerids (8 for each player)

There are other columns such as armor , mana, spells , which all get carried forward for each player , in total there are 48 columns - 12 for each player and their attributes

Finally there is a gameResult table that has result of a tournament , with tournamentid, tournament_timestamp, gameresult (complete, PlayerSurrender, InvalidSession , SecurityHack, TimeOut), winnerPlayer , playerMetrics , rowIDfrom, rowIDto

QUERY

My questions are focussed on reducing load on Game database or Sql queries

a) How to detect if a player has not logged in simutaneously and opened two game sessions but without having to refer to a Database or using Sql

b) How to control the surge of records into the GameProgress table. so that players get response quicker. The Server starts to lag at peak hours or when 1000 players are online

There is a tremendous flow of sql queries, for ex. even in the current game version
There are average/minimum 100 tournaments online per 12 minutes or 500 players / hour
In Game Progress table, We are storing each player move 
    a 12 round tourament of 4 player there can be 48 records
    plus around same number for spells or special items
    a total of 96 per tourament or 48000 record inserts per hour (500 players/hour)

I am also considering using a background process in Csharp, that keeps moving expired tournament records from GameProgresstable to another Database where we have a server free of gameplay load.

c) How often should we run vaccum full of postgres .

I am open to new applications opensource or toPay, that can improve performance. For ex. we used FastCsvReader http://www.codeproject.com/Articles/9258/A-Fast-CSV-Reader to improve enumeration of server log files.

regards Arvind


回答1:


 How to detect if a player has not logged in simutaneously and opened two game sessions 
 but without having to refer to a Database or using Sql

Assuming you use multiple servers you create a processes somewhere that only registers logins and logouts. You have it called whenever one of the two happens. You can use that process to check whether a user is already logged in. You can loadbalance this process by, for instance, running it on all servers and use an algorithm to use serverx only for a subset of the users. Say you have 10 servers, do (userId % 10) to get the Id of the server a user registers login/logout with.

This way you do these checks only in memory with calls between servers. Possibly you will need a timeout/refreshcall so users that disconnect or servers that crash will not keep users logged in forever.

How to control the surge of records into the GameProgress table. so that players get
response quicker. The Server starts to lag at peak hours or when 1000 players are
online

#1 Switch the postgress database to using SSD's for storage

#2 Elevate this entire process into memory and do not use the database for realtime work

#3 Update records in the database instead of creating new ones

#4 Use multiple databases and distribute users over them

#5 ....

Our table has a primarykey as tournamentid a random 32 character code on basis of
playerids. 

A randomly generated primary key is very bad practice imho. Use a sequence, or anything is guaranteed to be unique. If your randomcode is not random enough you will get very nasty bugs. You need to generate this only once per game so it is not a performance bottleneck.




回答2:


Another thing I would recommend although it has complexity costs is consider moving the portion of your system that is updated very frequently to something like VoltDB. This poses complexity costs, and you;d probably want to go with their commercial licenses/support. However, the benefits of a main memory db on this kind of load are likely to be worth it, provided you have disaster recovery as well. Your PostgreSQL instance can then handle longer-term data, while VoltDB can handle real-time processing.



来源:https://stackoverflow.com/questions/12668680/improve-mmo-game-performance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!