在Node.js中,什么存储技术可用于实时游戏 [英] In Node.js what storage technologies are available for real time games

查看:116
本文介绍了在Node.js中,什么存储技术可用于实时游戏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划使用html5和node.js进行实时游戏开发的实验。
我以前使用轮询来模拟游戏中的实时更新。
我的实时游戏将使用AJAX来保持游戏在多个客户端之间同步。基本上每当发生游戏状态的变化时,我将更新相关数据库行中的last_updated字段。每当客户端轮询服务器时,它将检查自上次轮询后发生的任何更新是否返回任何相关更新(通过将以前的轮询时间与last_updated字段进行比较)。



在我的新版本的游戏中,我使用node.js(和网络套接字),我想避免一个这样的机制,我必须不断地搜索数据库,以找到是否有更新。我想知道是否有替代方法来存储重要的游戏状态信息,而不使用数据库在这个甘露。



我真的想能够设置事件当所有客户端的游戏状态改变时触发,而不是不断地检查更改,因为这将节省大量的处理/查询。我真的不知道在一个客户端上触发的事件是否可以发送到其他客户端也连接到我的node.js运行服务器。



干杯,乔希

div class =h2_lin>解决方案

首先,您需要类似 Socket。 IO 来处理websockets(如果WS不可用,还有长轮询等)。



之后,您需要 Redis ZeroMQ 扩展Socket.IO(通过缩放我的意思是多个进程甚至多个服务器)。您还可以使用 CouchDB __change事件。 (可以让你知道何时发生插入/更新)



对于存储引擎,我建议你使用MongoDB(真的很好的写,这是你的需要)或者Redis(从内存中读取)和CouchDB(写入)的组合。



所有这些都有Node.js库,你可以在模块页面 https://github.com/joyent/node/wiki/modules ,或者您可以在他们的网站上(在dbs网站上)找到他们。


I am planning on experimenting with realtime game development using html5 and node.js. I previously made a game using polling to simulate real-time updates in a game. My real-time game would use AJAX to keep the game synchronized across multiple clients. Basically whenever a change in game state occurred, I would update a field last_updated in the database row concerned. Whenever a client polled the server, it would check for any updates that occurred since its last poll returning any relevant updates (doing this by comparing the previous poll time to the last_updated fields).

In my new version of the game where I instead use node.js (and web-sockets) I would like to avoid a mechanism like this where I have to continually do searches to a database to find if there were updates. I was wondering if there were alternative methods to storing important game state information, without the use of a database in this mannor.

I would really like to be able to setup events to fire on all clients when game state is changed instead of having to continually check for changes as this would save a large amount of processing / querying. I don't really know if an event fired on one client can be sent to other clients also connected to my node.js running server. I have always used a database for this sort of thing, but I am really hoping there are other better alternatives?

Cheers, Josh

解决方案

First of all you need something like Socket.IO to handle the websockets (and long-polling etc if WS not available).

After that you need Redis or ZeroMQ to scale Socket.IO (by scaling I mean multiple processes even multiple servers). You could also use CouchDB's _changes event for that. (which could let you know when an insert/update has occurred)

As for the storage engine, I suggest you use either MongoDB (really good for writes, that's what you need) or a combination of Redis (reading from memory) and CouchDB (for writes).

All of them have Node.js libraries, which you can checkout on the modules page https://github.com/joyent/node/wiki/modules or you can find them on their websites (on the dbs websites).

这篇关于在Node.js中,什么存储技术可用于实时游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆