根据条件将流量路由到多个节点服务器

编程入门 行业动态 更新时间:2024-10-21 04:07:29
本文介绍了根据条件将流量路由到多个节点服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Node.js和HTML5编写在线多人游戏,现在我想为人们提供多张地图,但是我遇到了缩放问题.我正在运行该服务器的服务器本身无法支持多个地图的游戏循环,即使它具有4个内核,我也只能在一个节点进程中使用一个.

I'm coding an online multiplayer game using nodejs and HTML5 and I'm at the point where I would like to have multiple maps for people to play on, but I'm having a scaling issue. The server I'm running this on isn't able to support the game loops for more than a few maps on its own, and even though it has 4 cores I can only utilize one with a single node process.

我希望能够对此进行扩展,甚至不必仅限于单个服务器.我希望能够为游戏中的每个地图启动一个节点进程,然后拥有一个主进程,该主进程查找玩家所在的地图,并将其连接传递给正确的子进程进行处理,并使用游戏信息进行更新等

I'd like to be able to scale this to not even necessarily be limited to a single server. I'd like to be able to start up a node process for each map in the game, then have a master process that looks up what map a player is in and passes their connection to the correct sub process for handling, updating with game information, etc.

我发现了几种使用代理(如nginx或内置节点群集)进行负载平衡的方法,但是据我所知,我所看到的示例只是为下一个可用进程提供了连接,并且我需要专门分发它们.我是否有某种方法可以根据这样的条件将连接路由到节点进程?我正在使用Express提供我的静态内容和socket.io,以用于当前客户端到服务器的通信.玩家所在的地图信息将与其他玩家数据一起存储在MongoDB中,如果有区别的话.

I've found a few ways to use a proxy like nginx or the built in node clusters to load balance but from what I can tell the examples I've seen just give a connection to whatever the next available process is, and I need to hand them out specifically. Is there some way for me to route a connection to a node process based on a condition like that? I'm using Express to serve my static content and socket.io for client to server communication currently. The information for what map the player is in will be in MongoDB along with the rest of the player data, if that makes a difference.

推荐答案

有很多方法可以解决您的问题,以下是根据您的描述提供的两个建议.

There are many ways to adress your problem, here are two suggestions based on your description.

1-使用路由器服务器,该服务器将向区域服务器"调度玩家查询:在此拓扑中,所有客户端查询都将到达您的路由服务器,该服务器用唯一的ID标记每个查询,并将其调度到正确的区域服务器,区域服务器将处理查询并将其发送回路由服务器,路由服务器将从唯一标记中识别该查询并将响应发送回客户端.

1 - Use a router server which will dispatch players queries to "Area servers" : in this topology all clients queries will arrive to your route server, the server tag each query with a unique id and dispatch it to the right area server, the area server handle the query and sendit back to the route server which will recognize it from the unique tag and send back the response to the client.

此解决方案将分派CPU/内存负载,但不会分派带宽!

this solution will dispatch the CPU/memory load but not the bandwidth !

2-使用身份验证服务器将客户端重定向到负载较小的服务器:在这种情况下,您将有多个相同的服务器和一个身份验证服务器,当客户端进行身份验证时,将发送可用服务器的url和auth令牌客户端的身份验证票证和服务器的身份验证票证. 客户端然后连接到将使用auth toekn/auth票证进行识别的服务器.

2 - Use an authentication server which redirect client to the servers with less load : in this case, you'll have multiple identical servers and one authentication server, when a client authenticate, send the url and an auth token of available server to the client and an authentication ticket to the server. the client then connect to the server which will recognize using the auth toekn/auth ticket.

此解决方案将分派所有CPU/内存/带宽,但可能不适用于所有游戏,因为每个连接都可以将您发送到不同的服务器,并且如果不在同一区域,您将看不到同一区域的玩家.同一台服务器.

this solution will dispatch all CPU/Memory/Bandwidth, but might not be suited to all games since you can be sent to different server each connection and you'll not see the players in the same area if you are not on the same server.

这些只是两个简单的建议,您可以将两种方法混合使用,也可以添加其他内容(例如,内部通信区域服务器等)来解决上述问题,但会增加复杂性.

those are only two simple suggestions, you can mix the two approaches or add other stuff (for example inter-communication area servers etc) which will solve the mensioned issues but will add complexity.

更多推荐

根据条件将流量路由到多个节点服务器

本文发布于:2023-10-12 17:03:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485329.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   节点   路由   流量   条件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!