大型游戏网站的可扩展性建议
我正在建立一个网站,玩家可以在其中玩回合制游戏以获得虚拟积分(类似于扑克网站,但有所不同)。我想出的设置:
- 一个数据服务器,其中包含所有玩家帐户以及相关数据(数据库+服务)。如果有帮助的话,数据库和 API 可以分为两个服务器。
- 为网站提供服务的一台或多台网络服务器,在需要时连接到数据服务器。
- 一个大厅服务器,玩家可以在其中找到彼此并设置游戏(可以有多个,但不太用户友好)
- 运行游戏的多个游戏服务器(所有规则等都在服务器上,客户端只是一个遥控器和查看器) ,带有一个负载均衡器。
- 游戏客户端
客户端将使用Flash制作,网络服务器将使用PHP。剩下的都是Java。
通讯
- 玩家登录网站。网络服务器将用户名/密码发送到数据服务器,数据服务器创建会话密钥(如 cookie)
- 玩家启动客户端。客户端连接到大厅服务器,传递会话密钥。大厅服务器与数据服务器检查此密钥
- 一旦创建了大厅并且必须开始游戏,大厅服务器就会从负载平衡器获取游戏服务器并在此游戏服务器上设置游戏。
- 大厅服务器告诉客户端连接到游戏服务器并开始游戏。
- 当游戏结束时,游戏服务器通知大厅服务器。大厅服务器将检查分数并更新数据服务器中的积分。
协议:
- Java 到 Java:RMI
- PHP 或 Flash 到 Java:通过套接字的自定义二进制协议。该协议支持在空闲时关闭套接字,同时保持虚拟连接处于活动状态并可恢复。
如果客户有他的意愿,该网站将需要支持数千个并发玩家。有了这些信息,您能发现我的设置中存在任何瓶颈吗?我个人有点担心只存在一个数据服务器,但我不确定如何将其拆分。也欢迎其他可扩展性(或其他)评论。
I'm building a website where players can play a turn based game for virtual credits (like a Poker site, but different). The setup I came up with:
- One data server which contains all player accounts with associated data (a database + service). Database and API may be split into two servers, if that helps.
- One or more webservers which serve the website, connecting to the data server when needed.
- One lobby server where players can find eachother and set up games (multiple is possible, but less user friendly)
- Multiple game servers where the game is run (all rules and such are on the server, the client is just a remote control and viewer), with one load balancer.
- A game client
The client will be made with Flash, the webserver will use PHP. The rest is all Java.
Communications
- Player logs in on the site. Webserver sends username/password to data server, which creates a session key (like a cookie)
- Player starts the client. Client connects to lobby server, passing the session key. Lobby server checks this key with the data server
- Once a lobby is created and a game must start, the lobby server fetches a game server from the load balancer and sets up a game on this game server.
- Lobby server tells the clients to connect to the game server and the game is played.
- When the game is finished, the game server lets the lobby server know. The lobby server will check the score and update the credits in the data server.
Protocols:
- Java to Java: RMI
- PHP or Flash to Java: Custom binary protocol via socket. This protocol supports closing the socket when idle while keeping the virtual connection alive and resumable.
If the client has his wishes, the site will need to support thousands of concurrent players. With this information, can you see any bottlenecks in my setup? I'm personally a little bit worried about the existence of only one data server, but I'm not sure how to split that up. Other scalability (or other) remarks are also welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的架构具有许多单一服务,这些服务对于系统的任何部分为任何用户工作都至关重要。我认为这些SPOF。
在这种类型的应用程序中,我认为水平分区是一个好主意,因为它可以轻松完成并增加系统的可靠性。假设您的 SPOF 已分区,而不是冗余。这更容易而且可能更便宜。如果 SPOF 的一部分发生故障(假设您的 20 个独立的物理分布式数据服务器中的 1 个),那就很糟糕,因为您的 5% 的玩家被锁定。但可能很快就会起来。如果您的 SPOF 是多余的,那么出现任何问题的可能性就会降低。但如果真的发生了,每个人都被锁在门外。这是一个问题,因为每个人都会同时尝试恢复在线状态。一旦您的 SPOF 回来,它将受到比通常需要处理的数量级高的请求量的影响。您仍然可以同时采用水平分区和冗余,正如平衡服务所建议的那样。
Your architecture has a lot of single services that are crucial for ANY part of the system to work for ANY user. I considers these SPOFs.
In this type of application, I think horizontal partitioning is a good idea, because for one it can be done easily and adds reliability to the system. Assume your SPOFs are partitioned, rather than redundant. This is easier and possibly cheaper. If a part of an SPOF goes down (let's say 1 of your 20 independent and physically distributed data servers), this bad, because 5% of your players are locked out. But probably it will get up some time soon. If your SPOF is redundant, chances are lower that anything fails. But if it does, EVERYBODY is locked out. This is an issue, because you'll have everybody trying to get back online all at the same time. Once your SPOF is back, it'll be hit by an amount of request orders of magnitude higher than it has to handle usually. And you can still employ horizontal partitioning and redundancy at the same time, as proposed for the balancing service.
在开发过几款 Facebook 游戏后,我想说的是:
要考虑对数千名玩家的可扩展性,但你必须先获得数以万计的玩家,然后才能为这些玩家进行扩展的努力得到回报。
也就是说,提前计划,但在规划一个可容纳数千个并发玩家的系统之前,先要担心只有 1 个玩家。
我怀疑您描述的设置对于您的初始用户群来说效果很好。在构建时,请避免执行以下操作: 要求登录服务器与大厅服务器通信。让每个服务器独立存在,最让你丧命的是服务之间的相互依赖。
但最重要的是,以最方便的方式完成它。如果你有足够多的用户来对你的系统征税,那将是一件非常好的事情。您可以聘请 DBA 来帮助您弄清楚当您拥有这么多用户时如何进行扩展。
Having worked on a couple of facebook games, I would say this:
Be thinking about scalability for thousands of players, but you have to get tens of thousands of players before the effort of scaling for those players will pay off.
That is to say, plan ahead, but worry about getting 1 player before you plan a system for thousands of concurrent players.
I suspect that the setup you describe will perform pretty well for your initial user-base. While you are building, avoid doing things like: Requiring the login server to talk to the lobby server. Make each server stand on it's own, the big thing that will kill you is inter-dependency between services.
But the most important thing, is to get it done in the most expedient way you can. If you get enough users to tax your system, that will be a really good thing. You can hire a DBA to help you figure out how to scale out when you have that many users.