I'm working on a turn based board game for iPhone and eventually Android. I'm using Appcelerator Titanium to develop it. My multiplayer design is similar to Words With Friends. Users take turns when ready, and then the opponent's game board is updated accordingly.
我正在为iPhone和最终的Android开发基于回合制的棋盘游戏。我正在使用Appcelerator Titanium来开发它。我的多人游戏设计类似于Words With Friends。用户在准备好后轮流,然后相应地更新对手的游戏板。
One of my needs is to have a messaging API which enables the 2 players' devices to update one another on the status of the game board after a move. Thinking of doing this with JSON and keeping a JSON object on the device which contains the location of all game board pieces at any given time. This is the object that will need to update on the local device and then send a change to the opponent's device after a move is made.
我的一个需求是拥有一个消息传递API,它使2个玩家的设备能够在移动后相互更新游戏板的状态。考虑使用JSON执行此操作并在设备上保留JSON对象,该对象包含任何给定时间的所有游戏板块的位置。这是需要在本地设备上更新然后在移动后向对手的设备发送更改的对象。
I've done APIs in the past for mobile platforms and to do so I've used PHP with MySQL and sent JSON back and forth between the API server and the mobile device. Works just dandy for low concurrent users, and generally non-massive apps. Here's to hoping this one will get massive ;)
我过去曾为移动平台做过API,为此我已经将PHP与MySQL结合使用,并在API服务器和移动设备之间来回发送JSON。对于低并发用户以及通常非大规模的应用程序而言,它只是花花公子。这是希望这个会变得庞大;)
So now, instead of a general httpd server and the like, I'm starting to think about persistent sockets and if they're needed or not for my new game. I'm also thinking that it might be smart to forgo the big LAMP stack, and for scalability and maybe ease of development, to lean more towards a data flow of something like Mongo/Couch -> node.js -> iPhone. I'll be honest, it would be my first foray into a non-sql db and node.js as well.
所以现在,我开始考虑持久套接字,而不是一般的httpd服务器等,以及它是否需要我的新游戏。我也认为放弃大型LAMP堆栈可能是明智的,并且为了可扩展性和易于开发,更倾向于使用像Mongo / Couch - > node.js - > iPhone这样的数据流。老实说,这将是我第一次进入非sql db和node.js。
Interested to hear others' takes and experiences on this, more options/thoughts, and whether I am thinking about it the right way, or just creating headaches for myself.
有兴趣听取别人对此的看法和经验,更多的选择/想法,以及我是否正确地思考它,或者只为自己制造麻烦。
2 个解决方案
#1
7
First of all, Nodejs is awesome for writing reverse TCP proxies to NoSQL databases. You could let all the standard commands pass through but alter/extend their APIs with your own magic, e.g. making MongoDB speak HTTP or CouchDB speak a binary protocol over sockets.
首先,Nodejs非常适合编写反向TCP代理到NoSQL数据库。您可以让所有标准命令通过,但使用您自己的魔法改变/扩展其API,例如使MongoDB说HTTP或CouchDB通过套接字说二进制协议。
When it comes to choosing a NoSQL solution for storing board game pieces and monitoring for player moves I think either Redis and CouchDB are the best candidates.
在选择NoSQL解决方案来存储棋盘游戏和监控玩家移动时,我认为Redis和CouchDB是最佳候选者。
- CouchDB. It's fast, reliable, and can handle a lot of concurrent HTTP connections. It's probably the best option because unlike Redis it can broadcast a message when a document changes. The continous changes API makes it super simple for you to have each player's app monitor for changes to their board. The request might look like:
curl "$HOST/dbname/_changes?filter=app/gameboard&feed=continuous&gameid=38934&heartbeat=1000
Each client will receive a JSON object per line in the response anytime a pertinent document is changed. (And a blank newline every 1000ms as a sort of keepalive.)
- Redis. It uses a simple line-based protocol (like MemcacheD++) to talk over a socket and allows you to store Lists, Sets, Hashes with arbitrary--even binary--values. It's very fast because everything happens in memory but is persisted to disk asynchronously. But most of all you should evaluate it because it already has PubSub notifications baked in. Note that you'll have to explicitly publish move notifications over a channel the players share because Redis won't automatically publish when a key/value changes.
CouchDB的。它快速,可靠,并且可以处理大量并发HTTP连接。它可能是最好的选择,因为与Redis不同,它可以在文档发生变化时广播消息。持续更改API使您可以非常简单地让每个玩家的应用程序监视其电路板的更改。请求可能如下所示:curl“$ HOST / dbname / _changes?filter = app / gameboard&feed = continuous&gameid = 38934&heartbeat = 1000每当有关文档发生更改时,每个客户端都会在响应中每行收到一个JSON对象。(以及一个空行换行符)每1000毫秒作为一种保持活力。)
Redis的。它使用简单的基于行的协议(如MemcacheD ++)来讨论套接字,并允许您存储具有任意 - 甚至二进制 - 值的列表,集合,哈希。它非常快,因为一切都在内存中发生,但是异步地持久化到磁盘。但最重要的是你应该对它进行评估,因为它已经有了PubSub通知。请注意,你必须通过玩家共享的频道明确发布移动通知,因为当键/值发生变化时,Redis不会自动发布。
Since MongoDB does not have a mechanism for observing changes as-they-happen or doing pubsub I don't consider it a good option, though with extra effort you could make it work.
由于MongoDB没有一种机制来观察变化,因为它们正在发生或正在使用pubsub我不认为它是一个好的选择,尽管需要付出额外的努力才能使它工作。
So to conclude, you may be able to replace "the big LAMP stack" with CouchDB alone, Redis alone, or either one placed behind a node app for filtering/extending the APIs they already provide into something that fits your game.
总而言之,您可以单独使用CouchDB替换“大LAMP堆栈”,单独使用Redis,或者将任何一个放置在节点应用程序之后,将其已经提供的API过滤/扩展为适合您游戏的内容。
Best of luck!
祝你好运!
#2
2
I've just started learning mongo, and it isn't hard to learn. Things like indexes and explain are there and work the same. When it comes to architecture, you want to think the opposite of SQL; instead of needing a good reason to de-normalize, you need to come up with a good reason to normalize. The guys at 10gen (who make mongo) will say that thinking of hierarchical is a more natural way of thinking about things, which I would agree with (tentatively). Finders feel sort of sql-ish as well, although you will still use map-reduce for aggregation queries.
我刚开始学习mongo,并不难学。索引和解释之类的东西都在那里并且工作原理相同。在架构方面,你想要与SQL相反;而不是需要一个很好的理由去标准化,你需要提出一个很好的理由来规范化。 10gen(制作mongo)的人会说,分层思考是一种更自然的思考事物的方式,我同意(暂时)。 Finders也感觉有点像sql-ish,尽管你仍然会使用map-reduce进行聚合查询。
From what I understand about couch, the big difference is there is a strong focus on the distributed replication thing. Mongo focuses more on performance over massive amounts of data (although they have autosharding and a great scaling story too). I would go mongo, unless you are actually going to use the distributed aspects of couch.
根据我对沙发的理解,最大的区别在于强烈关注分布式复制事物。 Mongo更关注大量数据的性能(虽然他们有自动分片和一个很好的缩放故事)。我会去mongo,除非你真的要使用沙发的分布式方面。
Node has got to be the coolest thing ever, and I think this would be a great application for it. I have zero experience with it, but from what I have read, it is great for loads of small requests, and scales up wonderfully. Idiomatic javascript lends itself quite well to the whole eventing model, and with v8 it runs just obscenely fast.
Node必须是有史以来最酷的东西,我认为这将是一个很好的应用程序。我对它没有任何经验,但从我所读到的内容来看,这对于大量小请求来说非常棒,并且可以非常好地扩展。惯用的javascript非常适合整个事件模型,而v8的运行速度非常快。
#1
7
First of all, Nodejs is awesome for writing reverse TCP proxies to NoSQL databases. You could let all the standard commands pass through but alter/extend their APIs with your own magic, e.g. making MongoDB speak HTTP or CouchDB speak a binary protocol over sockets.
首先,Nodejs非常适合编写反向TCP代理到NoSQL数据库。您可以让所有标准命令通过,但使用您自己的魔法改变/扩展其API,例如使MongoDB说HTTP或CouchDB通过套接字说二进制协议。
When it comes to choosing a NoSQL solution for storing board game pieces and monitoring for player moves I think either Redis and CouchDB are the best candidates.
在选择NoSQL解决方案来存储棋盘游戏和监控玩家移动时,我认为Redis和CouchDB是最佳候选者。
- CouchDB. It's fast, reliable, and can handle a lot of concurrent HTTP connections. It's probably the best option because unlike Redis it can broadcast a message when a document changes. The continous changes API makes it super simple for you to have each player's app monitor for changes to their board. The request might look like:
curl "$HOST/dbname/_changes?filter=app/gameboard&feed=continuous&gameid=38934&heartbeat=1000
Each client will receive a JSON object per line in the response anytime a pertinent document is changed. (And a blank newline every 1000ms as a sort of keepalive.)
- Redis. It uses a simple line-based protocol (like MemcacheD++) to talk over a socket and allows you to store Lists, Sets, Hashes with arbitrary--even binary--values. It's very fast because everything happens in memory but is persisted to disk asynchronously. But most of all you should evaluate it because it already has PubSub notifications baked in. Note that you'll have to explicitly publish move notifications over a channel the players share because Redis won't automatically publish when a key/value changes.
CouchDB的。它快速,可靠,并且可以处理大量并发HTTP连接。它可能是最好的选择,因为与Redis不同,它可以在文档发生变化时广播消息。持续更改API使您可以非常简单地让每个玩家的应用程序监视其电路板的更改。请求可能如下所示:curl“$ HOST / dbname / _changes?filter = app / gameboard&feed = continuous&gameid = 38934&heartbeat = 1000每当有关文档发生更改时,每个客户端都会在响应中每行收到一个JSON对象。(以及一个空行换行符)每1000毫秒作为一种保持活力。)
Redis的。它使用简单的基于行的协议(如MemcacheD ++)来讨论套接字,并允许您存储具有任意 - 甚至二进制 - 值的列表,集合,哈希。它非常快,因为一切都在内存中发生,但是异步地持久化到磁盘。但最重要的是你应该对它进行评估,因为它已经有了PubSub通知。请注意,你必须通过玩家共享的频道明确发布移动通知,因为当键/值发生变化时,Redis不会自动发布。
Since MongoDB does not have a mechanism for observing changes as-they-happen or doing pubsub I don't consider it a good option, though with extra effort you could make it work.
由于MongoDB没有一种机制来观察变化,因为它们正在发生或正在使用pubsub我不认为它是一个好的选择,尽管需要付出额外的努力才能使它工作。
So to conclude, you may be able to replace "the big LAMP stack" with CouchDB alone, Redis alone, or either one placed behind a node app for filtering/extending the APIs they already provide into something that fits your game.
总而言之,您可以单独使用CouchDB替换“大LAMP堆栈”,单独使用Redis,或者将任何一个放置在节点应用程序之后,将其已经提供的API过滤/扩展为适合您游戏的内容。
Best of luck!
祝你好运!
#2
2
I've just started learning mongo, and it isn't hard to learn. Things like indexes and explain are there and work the same. When it comes to architecture, you want to think the opposite of SQL; instead of needing a good reason to de-normalize, you need to come up with a good reason to normalize. The guys at 10gen (who make mongo) will say that thinking of hierarchical is a more natural way of thinking about things, which I would agree with (tentatively). Finders feel sort of sql-ish as well, although you will still use map-reduce for aggregation queries.
我刚开始学习mongo,并不难学。索引和解释之类的东西都在那里并且工作原理相同。在架构方面,你想要与SQL相反;而不是需要一个很好的理由去标准化,你需要提出一个很好的理由来规范化。 10gen(制作mongo)的人会说,分层思考是一种更自然的思考事物的方式,我同意(暂时)。 Finders也感觉有点像sql-ish,尽管你仍然会使用map-reduce进行聚合查询。
From what I understand about couch, the big difference is there is a strong focus on the distributed replication thing. Mongo focuses more on performance over massive amounts of data (although they have autosharding and a great scaling story too). I would go mongo, unless you are actually going to use the distributed aspects of couch.
根据我对沙发的理解,最大的区别在于强烈关注分布式复制事物。 Mongo更关注大量数据的性能(虽然他们有自动分片和一个很好的缩放故事)。我会去mongo,除非你真的要使用沙发的分布式方面。
Node has got to be the coolest thing ever, and I think this would be a great application for it. I have zero experience with it, but from what I have read, it is great for loads of small requests, and scales up wonderfully. Idiomatic javascript lends itself quite well to the whole eventing model, and with v8 it runs just obscenely fast.
Node必须是有史以来最酷的东西,我认为这将是一个很好的应用程序。我对它没有任何经验,但从我所读到的内容来看,这对于大量小请求来说非常棒,并且可以非常好地扩展。惯用的javascript非常适合整个事件模型,而v8的运行速度非常快。