swarmsim / swarm

Swarm Simulator, an idle game with lots of bugs.
https://www.swarmsim.com
GNU General Public License v3.0
481 stars 141 forks source link

kong sync #403

Closed erosson closed 9 years ago

erosson commented 9 years ago

from #164. we have a few options for a server - we have money to rent one now; someone's offered to host one. what we can't do is use third-parties that require their own login system, like dropbox/google.

erosson commented 9 years ago

4 main contenders here, I think: aws cognito, custom server app + s3, custom server app + database, or parse.com

(haven't heard back from the guy who offered his server. guessing it fell through after dropbox release.)

leaning toward parse or cognito. so much simpler to avoid building a serverside app. they're both proprietary, moreso than a serverside app - but multistorage should do pretty well for migrating later if necessary.

erosson commented 9 years ago

we're on track for 6 million session per month. that's 12 million syncs, assuming 1 sync onload, 1 sync onclose (with no periodic syncing for crash recovery), $15 per million = $180/month. ouch. https://aws.amazon.com/cognito/pricing/ we still come out ahead but... well, that's a lot. (data storage cost is trivial. we are too big for the free tier.)

same math puts s3 at $60 for puts, $5ish for gets assuming each sync is 1 get + 1 put. that's probably a bad assumption though - the onload-sync probably won't need to put, so $30 for puts, $5ish for gets. that's dramatically better. https://aws.amazon.com/s3/pricing/ (bandwidth cost is trivial. data storage cost is even more trivial. we are too big for the free tier.) capacity for the custom app server is harder to estimate, and much more expensive.

https://www.parse.com/plans/faq parse's pricing is trickier - it's not based on requests per month, but max requests per minute - so, around burst traffic. free for 30 requests/sec, $100 for 40/sec, $200 for $50/sec, prorated - really steep price curve after we reach nonfree. we have to pick this number ahead of time, they won't autoscale it (can we adjust it via api?), and if we exceed it they throw out the excess requests which is really bloody horrible and we want to avoid that. our afternoon peak is roughly (10k sessions/hr) / 3600 seconds/hr * 3 requests per session (2 gets, 1 put; see s3 discussion) = roughly 10 requests per second at peak - we're safely within the free tier right now. is this realistic? I think so - we have lots of users but each user needs very few requests. we'll have trouble if we grow much more, though - we've about maxed out kong growth, but we're going to submit this elsewhere. yet, I think growth still works out cheaper than cognito, which needs $180 for the same growth. wow. thing is, if we misjudge our max burst, we'll start dropping syncs, and that's really bad; cognito doesn't have that problem.

man, I want to like cognito because it has the most predictible costs and it's the closest fit for my use case, but it's just so much more expensive than the other choices.

aws dynamodb is another possibility - its pricing is similar to parse's, we must reserve capacity ahead of time - but the curve for getting big isn't as steep. each write requires 4 write-units (4k), read requires 2 read-units (maybe 1, eventually consistent reads should work for us) - (10k sessions/hr) / 3600 seconds/hr * 4 writes/session = 12 writes/second, 12 reads/second = like $20, and is even within the free tier. liking this, but write/read units are pretty opaque - it's possible we missed something. also a little worried about someone using our aws credentials for their own thing, like with s3. (really, parse would have the same problem.)

erosson commented 9 years ago

scratch all that - since Kongregate is not an openid provider, all solutions without a custom server are vulnerable to someone dumping arbitrary amounts of data into my storage. dang!

new plan: use s3 with signed uploads.

users rarely need to call the auth server for a new policy - like, once every few days; the policy can survive through a session - so we scale really well. (will have to scale with bursty traffic, though - like at release.) after that, all sync calls go straight to s3, no dependence on the auth server.

sucks that we need a custom server after all, but after researching this the only way to avoid it is to basically allow anonymous uploads of any size/rate, or manage user accounts ourself (don't wanna do that; tti/parse do it but it's too much overhead imo).

erosson commented 9 years ago

https://github.com/erosson/swarm-server

aws elastic beanstalk is pretty nifty - simple appengine-like iface, with aws infrastructure. looks like it runs $35/mo or so when idle - a little over half of that is the load balancer, $15 for a micro ec2 instance. autoscales. running with 4 instances, it'd be $80/mo, but usually we'll be closer to 1. s3's extra, of course, as calculated above. in any case, costs seem reasonable.

this now works! kongregate users can remote-sync when signed in! we have an auth server! s3 credentials are cached! it's not flawless - we still need:

the first three block release, but the others can wait if needed.

erosson commented 9 years ago

I think this is ready!