Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Game hiscores: flat files or database?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  16 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Felix E. Klee  
View profile  
 More options Oct 1 2012, 6:10 am
From: "Felix E. Klee" <felix.k...@inka.de>
Date: Mon, 1 Oct 2012 12:10:09 +0200
Local: Mon, Oct 1 2012 6:10 am
Subject: Game hiscores: flat files or database?
Somewhat as a training, I am developing a puzzle game. A first version
was entered into the js13kGames competition:

http://js13kgames.com/entries/rotogamesq

In that version, hiscores are simply stored in the browser. For the next
version, my idea is to store hiscores on a server running Node.js  /
express, hosted on Nodejitsu. How it could work:

Server starts: Hiscore lists for all puzzles are loaded from disk into
server memory.

User opens game in browser:

 1. Browser loads game. Via Socket.IO the hiscore lists for all puzzles
    are transferred to the browser.

 2. User finishes one puzzle, gets into hiscore list, and enters name.

 3. Via Socket.IO, data is sent to the server: puzzle, moves, name

 4. The server verifies that the moves are correct, using a background
    process.

 5. Name and new hiscore are entered into puzzle's hiscore list.

 6. The puzzle's hiscore list is written to disk.

 7. Using Socket.IO, the updated hiscore list is broadcasted.

Now I wonder what is the simplest way to perform step 6. I see two
options:

  * (A) Store hiscore list in a file `hiscores.json`, associated with
    the puzzle. Problems:

      - There *may* be concurrency issues. If two users finish the same
        puzzle near simultaneously, then `fs.writeFile` will be called
        in quick succession. I am not sure whether this could lead to
        file corruption.

      - For creating a backup, it doesn't seem possible to *download*
        files from Nodejitsu, unless I write my own software for that.

      - Although unlikely, suppose I scale up, and two Node.js are
        serving the game. In this case, there are further concurrency
        issues due to the hiscore lists held in memory not being shared
        among the processes.

  * (B) Store hiscore list in database, e.g. Mongo. Problems: I don't
    see any, except that the solution feels fat, a database needs to be
    set up, and I prefer individual files for simplicity.

After writing this email, I tend to option (B), but still:

Which option would you chose? Something else? Suggestions?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
greelgorke  
View profile  
 More options Oct 1 2012, 6:55 am
From: greelgorke <greelgo...@gmail.com>
Date: Mon, 1 Oct 2012 03:55:02 -0700 (PDT)
Local: Mon, Oct 1 2012 6:55 am
Subject: Re: Game hiscores: flat files or database?

b) redis: http://redis.io/topics/introduction
its less puzzling than files, has replication and pubsub, and atomic
operations
Am Montag, 1. Oktober 2012 12:10:50 UTC+2 schrieb Felix E. Klee:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Felix E. Klee  
View profile  
 More options Oct 1 2012, 7:49 am
From: "Felix E. Klee" <felix.k...@inka.de>
Date: Mon, 1 Oct 2012 13:48:43 +0200
Local: Mon, Oct 1 2012 7:48 am
Subject: Re: [nodejs] Re: Game hiscores: flat files or database?
On Mon, Oct 1, 2012 at 12:55 PM, greelgorke <greelgo...@gmail.com>
wrote:

Thanks for the suggestion. However, if using a database, then I prefer
Mongo. Performance is not an issue. Persistence, on the other hand, is a
big issue: If someone spent hours to crack the hiscore, then he will be
disappointed if his entry goes away due to a server crash.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pedro Teixeira  
View profile  
 More options Oct 1 2012, 7:51 am
From: Pedro Teixeira <pedro.teixe...@gmail.com>
Date: Mon, 1 Oct 2012 12:50:49 +0100
Local: Mon, Oct 1 2012 7:50 am
Subject: Re: [nodejs] Re: Game hiscores: flat files or database?

http://redis.io/topics/persistence

--
Pedro


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Felix E. Klee  
View profile  
 More options Oct 1 2012, 8:57 am
From: "Felix E. Klee" <felix.k...@inka.de>
Date: Mon, 1 Oct 2012 14:56:23 +0200
Local: Mon, Oct 1 2012 8:56 am
Subject: Re: [nodejs] Re: Game hiscores: flat files or database?
On Mon, Oct 1, 2012 at 1:50 PM, Pedro Teixeira

<pedro.teixe...@gmail.com> wrote:
> http://redis.io/topics/persistence

Too complicated and/or not reliable enough.

At *any* point in time, I want to have the database mirrored to disk, in
its entirety. Mongo seems perfect. I wonder why people recommend Redis.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pedro Teixeira  
View profile  
 More options Oct 1 2012, 9:01 am
From: Pedro Teixeira <pedro.teixe...@gmail.com>
Date: Mon, 1 Oct 2012 14:00:35 +0100
Local: Mon, Oct 1 2012 9:00 am
Subject: Re: [nodejs] Re: Game hiscores: flat files or database?

Did you read the append-only:true AOF part of the link I sent you?

--
Pedro


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Arnout Kazemier  
View profile  
 More options Oct 1 2012, 9:10 am
From: Arnout Kazemier <i...@3rd-eden.com>
Date: Mon, 1 Oct 2012 15:09:24 +0200
Local: Mon, Oct 1 2012 9:09 am
Subject: Re: [nodejs] Re: Game hiscores: flat files or database?

Then why ask the question if you already made your mind? You clearly don't want to use anything else then mongodb because
you seem to know better and the only thing that redis can do is crash anyways, mongo on the other hand is web scale and build
to solve all the issues in the universe that people throw at it.

As for A) there a couple of "decent" databases written in Node, but using a database is better, because at some point you are going
to scale out of process, or use multiple apps that are not hosted on the same process.. Simplicity is nice and all but it's not always
the best answer on all the questions.

On Monday 1 October 2012 at 14:56, Felix E. Klee wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Felix E. Klee  
View profile  
 More options Oct 1 2012, 9:29 am
From: "Felix E. Klee" <felix.k...@inka.de>
Date: Mon, 1 Oct 2012 15:28:27 +0200
Local: Mon, Oct 1 2012 9:28 am
Subject: Re: [nodejs] Re: Game hiscores: flat files or database?
On Mon, Oct 1, 2012 at 3:09 PM, Arnout Kazemier <i...@3rd-eden.com>
wrote:

> Then why ask the question if you already made your mind?

I'm far from having made up my mind. I just wonder why people recommend
Redis when performance is not an issue here. After, all solving a puzzle
may take some minutes, and only once in a while someone will get into
the hiscores table.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Felix E. Klee  
View profile  
 More options Oct 1 2012, 9:44 am
From: "Felix E. Klee" <felix.k...@inka.de>
Date: Mon, 1 Oct 2012 15:43:47 +0200
Local: Mon, Oct 1 2012 9:43 am
Subject: Re: [nodejs] Re: Game hiscores: flat files or database?
On Mon, Oct 1, 2012 at 3:00 PM, Pedro Teixeira

<pedro.teixe...@gmail.com> wrote:
> Did you read the append-only:true AOF part of the link I sent you?

Yes. I also now read that from time to time Redis rewrites the log so
that - I assume - entries that have been deleted will not appear
anymore. Sounds good!

However, it is recommended to not use AOF alone, possibly making things
more complicated than when using Mongo:

"There are many users using AOF alone, but we discourage it since to
have an RDB snapshot from time to time is a great idea for doing
database backups, for faster restarts, and in the event of bugs in the
AOF engine."

Also, I don't know what happens when the Redis server is restarted. Will
it automatically read the log to recreate the last database status?

I really don't understand what is the particular advantage of using
Redis vs. Mongo for the use case. Redis looks more complicated to set up
and possibly to maintain.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brian Kardell  
View profile  
 More options Oct 1 2012, 9:48 am
From: Brian Kardell <bkard...@gmail.com>
Date: Mon, 1 Oct 2012 09:41:17 -0400
Local: Mon, Oct 1 2012 9:41 am
Subject: Re: [nodejs] Re: Game hiscores: flat files or database?

Brian Kardell :: @bkardell :: hitchjs.com
On Oct 1, 2012 9:29 AM, "Felix E. Klee" <felix.k...@inka.de> wrote:

> On Mon, Oct 1, 2012 at 3:09 PM, Arnout Kazemier <i...@3rd-eden.com>
> wrote:
> > Then why ask the question if you already made your mind?

> I'm far from having made up my mind. I just wonder why people recommend
> Redis when performance is not an issue here. After, all solving a puzzle
> may take some minutes, and only once in a while someone will get into
> the hiscores table.

> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:

https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines

> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nodejs@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

If the only reason you would even consider a db over a file is a very, very
obscure case then why not just set a semaphor and retry after a second or
two if it is still open?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Felix E. Klee  
View profile  
 More options Oct 1 2012, 10:04 am
From: "Felix E. Klee" <felix.k...@inka.de>
Date: Mon, 1 Oct 2012 16:03:40 +0200
Local: Mon, Oct 1 2012 10:03 am
Subject: Re: [nodejs] Re: Game hiscores: flat files or database?
On Mon, Oct 1, 2012 at 3:41 PM, Brian Kardell <bkard...@gmail.com>
wrote:

> If the only reason you would even consider a db over a file is a very,
> very obscure case then why not just set a semaphor and retry after a
> second or two if it is still open?

True. However, that only solves the concurrency issue when only one
instance is running. With several instances running (though unlikely)
then things become more complicated, especially since there is no memory
shared between instances.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brian Kardell  
View profile  
 More options Oct 1 2012, 10:08 am
From: Brian Kardell <bkard...@gmail.com>
Date: Mon, 1 Oct 2012 10:08:20 -0400
Local: Mon, Oct 1 2012 10:08 am
Subject: Re: [nodejs] Re: Game hiscores: flat files or database?

Brian Kardell :: @bkardell :: hitchjs.com
On Oct 1, 2012 10:04 AM, "Felix E. Klee" <felix.k...@inka.de> wrote:

> On Mon, Oct 1, 2012 at 3:41 PM, Brian Kardell <bkard...@gmail.com>
> wrote:
> > If the only reason you would even consider a db over a file is a very,
> > very obscure case then why not just set a semaphor and retry after a
> > second or two if it is still open?

> True. However, that only solves the concurrency issue when only one
> instance is running. With several instances running (though unlikely)
> then things become more complicated, especially since there is no memory
> shared between instances.

> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:

https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines

> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nodejs@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en

Note that I said "if the only reason" and it was specifically WRT your
initial question and (what seemed to be) your desire to keep it really
simple.  Of course, there are any number of solutions and tradeoffs (short
term and long) that you can make depending on what your comfort and goals
are.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Rinehart  
View profile  
 More options Oct 1 2012, 11:39 am
From: Daniel Rinehart <dani...@neophi.com>
Date: Mon, 1 Oct 2012 11:39:33 -0400
Local: Mon, Oct 1 2012 11:39 am
Subject: Re: [nodejs] Game hiscores: flat files or database?
I'd recommend using Redis. Its sorted set data type makes a high score
list a breeze to maintain. As mentioned using a combination of RDB and
AOF you get great durability with Redis.

-- Daniel R. <dani...@neophi.com> [http://danielr.neophi.com/]

On Mon, Oct 1, 2012 at 6:10 AM, Felix E. Klee <felix.k...@inka.de> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dan Milon  
View profile  
 More options Oct 1 2012, 5:52 pm
From: Dan Milon <danmi...@gmail.com>
Date: Tue, 2 Oct 2012 00:52:33 +0300
Local: Mon, Oct 1 2012 5:52 pm
Subject: Re: [nodejs] Re: Game hiscores: flat files or database?

Then you should read again about Mongo.

danmilon.

On Mon, Oct 1, 2012 at 3:56 PM, Felix E. Klee <felix.k...@inka.de> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Felix E. Klee  
View profile  
 More options Oct 7 2012, 4:24 pm
From: "Felix E. Klee" <felix.k...@inka.de>
Date: Sun, 7 Oct 2012 22:23:51 +0200
Local: Sun, Oct 7 2012 4:23 pm
Subject: Re: [nodejs] Game hiscores: flat files or database?
On Mon, Oct 1, 2012 at 5:39 PM, Daniel Rinehart <dani...@neophi.com>
wrote:

> I'd recommend using Redis.

Redis, Redis, Redis. Nobody recommending anything else. So, I'm ready to
give it a try.

As I want to use it together with Socket.IO, could I just use the Redis
store built into Socket.IO, or is that strictly temporary?

Remember that, naturally, hiscores should persist a server restart.
Also, when a client connects, it should get all hiscores. So, that's
fundamentally different to, say, an IRC-like chat system.

> Its sorted set data type makes a high score list a breeze to maintain.

Interesting. Note, however, that hiscore table entries are not sorted by
score only: If there are two entries with the same score, then the entry
that was added last should appear first. So sorting is by score plus
time.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Felix E. Klee  
View profile  
 More options Oct 13 2012, 1:24 pm
From: "Felix E. Klee" <felix.k...@inka.de>
Date: Sat, 13 Oct 2012 19:23:46 +0200
Local: Sat, Oct 13 2012 1:23 pm
Subject: Re: Game hiscores: flat files or database?
I am now using Redis 2.6 with LUA scripting, so far with great joy!

The hiscores I store in sorted sets, with floating point scores:

  * Integer part: game score (between 0 and 99)

  * Fractional part: timestamp (46 bits)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »