我在facebook上有一个多人纸牌游戏(最多4个玩家可以玩同一个游戏实例)。
我现在正在研究可伸缩性,因为我希望很快一台服务器就不够了。
服务器在内存中存储正在进行的所有游戏的列表:
List<Game>
当客户机发出请求(例如抛出一张卡)时,它会向服务器发送一条消息。
服务器不会立即发送响应,而是在响应之前不断检查是否有其他玩家修改了游戏状态。
这种方法工作得很好,因为客户端(silverlight)不经常轮询服务器。
以我有限的知识,我想走这条路:
这将在webrole中完成:
void Page_LoadOfAnAspxPage
{
// deserialze the message from the posted information
Message msgClient = ...;
// retrieve game from table storage
Game g = RetrieveFromTableStorage(gameGuid);
// post message to game
g.ProcessClientMessage(msgClient);
// save back to table storage so other game clients can be aware of new state
SaveToTableStorage(gameGuid, g);
// now wait until another client modifies the game
while(true) // will I be incurring hosting charges (transactions for what is going on in this while loop)???
{
// grab game from table storage
g = RetrieveFromTableStorage(gameGuid);
// has something changed?
MsgResponse response = g.ProcessClientMessage(msgClient);
if (response.ActionName != ActionName.GameHasNotChanged)
{
// some other client changed the game.
// give this response back to our client
break;
}
// sleep a little and check again...
Sleep(xx);
}
}
你相信这种方法行得通吗?我可能遇到什么障碍?
如有任何建议/改进,我将不胜感激。
非常感谢。
圣地亚哥