简体   繁体   English

涉及SQL时,使用Amazon EC2自动扩展

[英]Auto-scaling with Amazon EC2 when SQL is involved

I'm building a whiteboard web app with self-contained "rooms" of clients that runs off Amazon EC2 instances (a single one for now). 我正在构建一个白板Web应用程序,其客户端的自包含“房间”运行在Amazon EC2实例(目前只有一个)。 Commands are sent via websockets to a PHP server, which stores all commands in a SQL database. 命令通过websockets发送到PHP服务器,PHP服务器将所有命令存储在SQL数据库中。

Up until now I was using Google Cloud SQL. 到目前为止,我一直在使用Google Cloud SQL。 My plan was to learn how to scale with EC2 and have all instances use the same remote database. 我的计划是学习如何使用EC2进行扩展,并让所有实例都使用相同的远程数据库。 I've learned this won't work due to the 200 ms write latency of a remote SQL server vs. the 0.5 ms write latency of a local SQL server. 我已经知道,由于远程SQL服务器的200毫秒写入延迟与本地SQL服务器的0.5毫秒写入延迟,这将无法工作。 The server makes a write every time a command arrives. 每次命令到达时,服务器都会写入。

I'm new to scalability and distributed systems. 我是可扩展性和分布式系统的新手。 My intuition tells me I either need to use Amazon RDS and hope for millisecond latencies if my EC2 and RDS instances are in the same region, or work with SQL locally on EC2 instances. 我的直觉告诉我,如果我的EC2和RDS实例位于同一区域,或者在EC2实例上本地使用SQL,我需要使用Amazon RDS并希望毫秒级延迟。 I'm leaning toward the latter. 我倾向于后者。 Here's my issue: EC2 is elastic . 这是我的问题:EC2很有弹性 What happens when I need to get rid of an instance? 当我需要摆脱一个实例时会发生什么?

All I can think of right now is somehow replicating the SQL data from each EC2 instance to a master instance (maybe even Google Cloud SQL!). 我现在能够想到的是以某种方式将每个EC2实例的SQL数据复制到主实例(甚至可能是Google Cloud SQL!)。 In other words, all reads/writes for each "room" happen locally, and are eventually replicated to the master server for long-term storage. 换句话说,每个“房间”的所有读/写都在本地发生,并最终复制到主服务器以进行长期存储。 If a "room" is re-opened a week later, a different EC2 instance can grab data from the master server, work with it locally, and replicate changes back before being destroyed. 如果一周后重新打开“房间”,则另一个EC2实例可以从主服务器获取数据,在本地使用它,并在销毁之前复制更改。

Does my approach sound correct--is replication the right concept here? 我的方法听起来是否正确 - 在这里复制正确的概念? If so, how much support for what I'm trying to do already exists? 如果是这样,那么我正在尝试做的事情已经存在多少支持? That is, do I need to set up a master server that manages EC2 instances and distributes/collects the SQL data manually (100% custom implementation), or is there are there existing libraries/mechanisms for SQL and maybe even EC2 instance replication/management? 也就是说,我是否需要设置一个管理EC2实例的主服务器并手动分发/收集SQL数据(100%自定义实现),或者是否存在SQL的现有库/机制,甚至可能是EC2实例复制/管理? And if my approach is wrong, what are some better approaches? 如果我的方法是错误的,那么更好的方法是什么? This is one of those times where I don't know what to research on my own. 这是我不知道自己要研究什么的时候之一。 Thanks! 谢谢!

我同意user02525或许看看使用Elasticache redis,听起来更符合你正在做的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM