简体   繁体   English

这项工作可以将流量分配给我的RDS只读副本吗?

[英]Would this work to distribute traffic to my RDS Read Replicas?

I am using Amazon RDS for my database services and want to use the read replica feature to distributed the traffic amongst the my read replica volumes. 我将Amazon RDS用于我的数据库服务,并想使用只读副本功能在我的只读副本卷之间分配流量。 I currently store the connection information for my database in a single config file. 我目前将数据库的连接信息存储在一个配置文件中。 So my idea is that I could create a function that randomly picked from a list of my read-replica endpoints/addresses in my config file any time my application performed a read. 所以我的想法是,只要我的应用程序执行读取操作,我就可以创建一个从配置文件中的只读副本端点/地址列表中随机选择的函数。

Is there a problem with this idea as long as I don't perform it on a write? 只要我不写就可以解决这个问题?

My guess is that if you have a service that has enough traffic to where you have multiple rds read replicas that you want to balance load across, then you also have multiple application servers in front of it operating behind a load balancer. 我的猜测是,如果您的服务具有足够的流量到要平衡负载的多个rds只读副本的位置,那么它前面的多个应用程序服务器也将在负载平衡器后面运行。

As such, you are probably better off having certain clusters of app server instances each pointing at a specific read replica. 因此,最好将某些应用服务器实例群集指向每个特定的只读副本。 Perhaps you do this by availability zone. 也许您按可用性区域执行此操作。

The thought here is that your load balancer will then serve as the mechanism for properly distributing the incoming requests that ultimately lead to database reads. 这里的想法是,您的负载均衡器将用作适当分配最终导致数据库读取的传入请求的机制。 If you had the DB reads randomized across different replicas you could have unexpected spikes where too much traffic happens to be directed to one DB replica causing resulting latency spikes on your service. 如果您将数据库读取随机分配给不同的副本,则可能会出现意外的峰值,其中过多的流量恰巧定向到一个数据库副本,从而导致服务上的延迟峰值。

The biggest challenge is that there is no guarantee that the read replicas will be up-to-date with the master or with each other when updates are made. 最大的挑战是,不能保证在进行更新时,只读副本将与主副本或彼此保持最新。 If you pick a different read-replica each time you do a read you could see some strangeness if one of the read replicas is behind: one out of N reads would get stale data, giving an inconsistent view of the system. 如果每次读取时都选择一个不同的只读副本,则如果其中一个只读副本落后,您会发现有些奇怪:N个读取中有一个会获取陈旧数据,从而导致系统视图不一致。

Choosing a random read replica per transaction or session might be easier to deal with from the consistency perspective. 从一致性的角度来看,为每个事务或会话选择随机的只读副本可能更容易处理。

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

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