Live data from Hacker News

One Million Chessboards

onemillionchessboards.com

31–40 of 82 posts

Re: One Million Chessboards

#31
post #6

(Also submitted here: https://news.ycombinator.com/item?id=43822992 ) Neat, though I expected every individual board to have "turns" - I didn't expect that I could just pick a random board, liberate the black queen, and have her clean up every single white piece on the board without my "opponent" getting to do anything in return.

oh huh, I'm not sure why this one made it to the front page and not the link to my site! Anyway, yeah, I guess I could have gone with turns here but I thought that building a more realtime MMO thing where pieces could cross boards would be a little more interesting and novel. I also didn't feel like a version of this that was turn based would ever complete. certainly a queen can go wipe out a whole board, but the gam…

As you wish! We've swapped out the link from https://eieio.games/blog/one-million-chessboards/ to your site. But I also put the blog link in the top text, so hopefully readers will look at both.

(Oh and I still owe you an email. I haven't forgotten!)

Re: One Million Chessboards

#32
post #20
post #8

Ah hello! I made this :) My blog describing it is pretty sparse, sorry about that. Happy to answer any questions that folks have about the architecture. Not that it was necessary, but I got really into building this out as a single process that could handle many (10k+/sec) moves for thousands of concurrent clients. I learned a whole lot! And I found golang to be a really good fit for this, since you mostly want to gi…

If you don’t mind explaining, I’m curious how you test something like this before it goes live. It seems like it would be hard to simulate all the things that could happen at scale.

So sometimes I don't test these projects that much but I did this time. Here are a few thoughts:

My biggest goal was "make sure that my bottleneck is serialization or syscalls for sending to the client." Those are both things I can parallelize really well, so I could (probably) scale my way out of them vertically in a pinch.

So I tried to pick an architecture that would make that true; I evaluated a ton of different options but eventually did some napkin math and decided that a 64-million uint64 array with a single mutex was probably ok[1].

To validate that I made a script that spins up ~600 bots, has 100 of them slam 1,000,000 moves through the server as fast as possible, and has the other 500 request lots of reads. This is NOT a perfect simulation of load, but it let me take profiles of my server under a reasonable amount of load and gave me a decent sense of my bottlenecks, whether changes were good for speed, etc.

I had a plan to move from a single RWMutex to a row-locking approach with 8,000 of them. I didn't want to do this because it's more complicated and I might mess it up. So instead I just measure the number of nanos that I hold my mutex for and send that to a loki instance. This was helpful during testing (at one point my read lock time went up 10x!) but more importantly gave me a plan for what to do if prod was slow - I can look at that metric and only tweak the mutex if it's actually a problem.

I also took some free wins like using protobufs instead of JSON for websockets. I was worried about connection overhead so I moved to GET polling behind Cloudflare's cache for global resources instead of pushing them over websockets.

And then I got comfortable with the fact that I might miss something! There are plenty more measurements I could have taken (if there was money on the line I would have measured some things like "number of TCP connections sending 0 moves this server can support" but I was lazy) but...some of the joy of projects like this is the firefighting :). So I was just ready for that.

Oh and finally I consulted with some very talented systems/performance engineer friends and ran some numbers by them as a sanity check.

It looks like this was way more work than I needed to do! I think I could comfortable 25x the current load and my server would be ok. But I learned a lot and this should all make the next project faster to make :)

[1] I originally did my math wrong and modeled the 100x100 snapshots I send to clients as 10,000 reads from main memory instead of 100 copies of 100 uint64s, which lead me down a very different path... I'm not used to thinking about this stuff!

Re: One Million Chessboards

#33
post #31
post #6

Earlier quoted context omitted.

oh huh, I'm not sure why this one made it to the front page and not the link to my site! Anyway, yeah, I guess I could have gone with turns here but I thought that building a more realtime MMO thing where pieces could cross boards would be a little more interesting and novel. I also didn't feel like a version of this that was turn based would ever complete. certainly a queen can go wipe out a whole board, but the gam…

As you wish! We've swapped out the link from https://eieio.games/blog/one-million-chessboards/ to your site. But I also put the blog link in the top text, so hopefully readers will look at both. (Oh and I still owe you an email. I haven't forgotten!)

Ah thank you dang! I meant to submit a Show HN for this one with a little context/a few technical details, but someone beat me to submitting the link. So this is perfect :)

(and thanks, I'm in no rush!!)

Re: One Million Chessboards

#34
post #6

Earlier quoted context omitted.

oh huh, I'm not sure why this one made it to the front page and not the link to my site! Anyway, yeah, I guess I could have gone with turns here but I thought that building a more realtime MMO thing where pieces could cross boards would be a little more interesting and novel. I also didn't feel like a version of this that was turn based would ever complete. certainly a queen can go wipe out a whole board, but the gam…

Individuals here on hacker news tend to gravitate towards blog posts about games rather than links to actual games, generally. Not a hard fast rule, but it's what I've observed over the years.

I have had some success on Hacker News with similar games before[1]! But I'll certainly do a proper writeup of the tech behind this one because I think it's pretty neat.

[1] https://news.ycombinator.com/item?id=40800869 for example

Re: One Million Chessboards

#35

Earlier quoted context omitted.

herding around ~25 queens was also fun building fortresses (since enemy can't cross board border by capture) is also. fun.

theoretically there's a design for "indestructible" fortress (rhoburb, you are a genius) 1) fill corner board with pieces 2) cover the border (from inside) with pawns 3) cover the promotion square on the border with the king king can't exit the board, pawns can't walk backward to leave space, filler doesn't allow these 2 to make way --- the real holy grail that will never be achieved I fear

[dead]

Re: One Million Chessboards

#36
post #30
post #7

Earlier quoted context omitted.

I'll certainly open source the code! I just want the flexibility to change my rate limiting logic in the short term to counteract abuse. Happy to answer questions though!

Yes please open source. I tried something similar based one your checkboxes game! I never worked with websockets so I’m curious how you designed for scale and stopped spammers. I game was click the button 10M times and of course the script kiddies started immediately which is fun! But not my server keeps getting hammered with requests long after the initial interest. I did not know how to rate limit bots without bloc…

fwiw I think the biggest single trick there is to group IPV6 addresses at the /48 or /64 level before applying rate limits (you can rate limit IPV4s on a per-ip basis).

It's kind of annoying and expensive to get a bunch of IPv4s to evade limits, but it's really easy to get a TON of IPv6s.

The other Big Trick I know is to persist rate limits after a client disconnects so that they can't disconnect -> reconnect to refresh their limits.

Re: One Million Chessboards

#37
post #26

> You can move between boards. Evidently move between boards but not capture between boards :-( It's extra weird because it's not that the movement isn't projected (e.g. queen blue lines all point correctly across board boundaries just the lines always stop at every piece on the other board, regardless of color) So, I guess as an exercise in scale, well done! As one million chess boards, caveat gamator

I didn't like the idea of a queen on one board capturing the king on another board as her first move. And then I tried this rule and thought it created really fun counterplay when you're trying to capture a piece someone else is controlling, since you can move to a new board to be safe (and can lay traps this way).

I'm sorry you don't like that decision! But I think that I stand by it.

Re: One Million Chessboards

#39
post #37
post #26

> You can move between boards. Evidently move between boards but not capture between boards :-( It's extra weird because it's not that the movement isn't projected (e.g. queen blue lines all point correctly across board boundaries just the lines always stop at every piece on the other board, regardless of color) So, I guess as an exercise in scale, well done! As one million chess boards, caveat gamator

I didn't like the idea of a queen on one board capturing the king on another board as her first move. And then I tried this rule and thought it created really fun counterplay when you're trying to capture a piece someone else is controlling, since you can move to a new board to be safe (and can lay traps this way). I'm sorry you don't like that decision! But I think that I stand by it.

> I didn't like the idea of a queen on one board capturing the king on another board as her first move

If you did want to experiment with supporting cross-board captures, an alternate way to address that could be by rotating the board 180° every other row, so that white pieces have other white pieces behind their home rank.

Post reply on HN