如何克服无服务器和MongoDB的扩展问题? [英] How can I overcome scaling issues with serverless and MongoDB?
问题描述
我熟悉无服务器和MongoDB,并想知道是否存在任何可扩展的方式来连接两个世界.据我所知,您无法以RESTful方式与MongoDB进行交互.而是打开应该重用的连接.
I'm familiar with serverless and MongoDB and would like to know if there are any scalable ways to connect the two worlds. As far as I know, you can't interact with MongoDB in a RESTful way. Instead, opening a connection which is supposed to be reused.
假设我将AWS Lambda用作无服务器API的一部分.当lambda处于冷状态时,您必须打开与MongoDB的新连接,而当lambda仍处于热状态时,该连接将保持打开状态.此解决方案很好,但是当API上的流量激增时,您将达到MongoDB施加的连接限制.
Let's say I'm using AWS Lambda as part of a serverless API. When the lambda is cold you have to open a new connection to MongoDB and while the lambda is still hot, the connection remains open. This solution is fine, but when you have a surge of traffic on the API you will hit a connection limit imposed by MongoDB.
在lambda之类的无状态世界中,是否有办法克服这种连接限制?
Is there a way to overcome this connection limit in a stateless world such as lambda?
推荐答案
要考虑的想法:您可以使用Kinesis触发Lambda,它将并发执行的次数限制为碎片数,例如8个碎片并发8个.
The idea to think of: You can use Kinesis to trigger you Lambda, It will limit the number of concurrent executions to the shards count, for example, 8 shards for 8 concurrently.
通过这种方式,您可以保持连接打开,并限制打开的连接,以避免扩展问题.
In this way, you can keep your connection open, and earn a limit of your open connection to avoid scaling issues.
您可以通过一些监视工具进行监视(对于单个调用,无论是新连接还是重复使用的连接),这将有助于您随着时间的推移保持扩展状态,这将有助于管理MongoDB和Kinesis迭代器年龄.如:
This type of thing (For a single invocation, whether the connection is new or re-used) you can monitor by some monitoring tools that will help you to keep you scaling status over time, its will help to manage MongoDB and Kinesis iterator age. Such as:
- AWS X射线
- AWS Cloudwatch指标
- Datadog
- Lumigo
作为我在一家Lumigo公司工作的披露,我们有一个分布式监视工具,可以帮助您跟踪生产规模问题
As a disclosure I work for a company called Lumigo, We have a distributed monitoring tool that can help you to track your production scaling issues
这篇关于如何克服无服务器和MongoDB的扩展问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!