Post by account_disabled on Jan 1, 2024 3:57:04 GMT
If a function was turned off during a transaction. A scaling strategy caused ten thousand new functions to be connected to the database. A long-running query or call take longer than average. When developing applications for a serverless environment it is always important to assume that such issues can and will occur. Avoiding Serverless Headaches To illustrate how the problem arises let’s look at a simple example. Below is a simple handler which accepts a query in the database for an item and then returns the result object. In a non-serverless environment this function will not have any impact on performance but in a serverless environment without some protection this function can cause severe damage to your application and your wallet. For example if usage of this application increases significantly you may see the database run out of connections very quickly. This can result in slower response times and timeouts that reduce your effective processing speed. To avoid this parallelization problem let's look at three simple configuration.
Changes you can make to your application. The changes are ordered from least impactful and least difficult to most impactful and most difficult. Changing the photo editing servies Client Connection Pool Size Most packages have a way to modify the number of connections a client keeps open to the underlying database called the connection pool. The number of connections in the pool by default may vary but is usually between . If you refer to the above example if you keep connections open per function it will probably be reduced by an order of magnitude even considering the large number of connections. In most cases setting the pool size to the maximum will keep your application running while also guaranteeing The number of connections will never exceed the number of functions running concurrently. If you are still seeing runaway database connections you should set a concurrency limit Most cloud platforms have the ability to limit the amount of concurrency for serverless functions. This gives you protection at the infrastructure level against a degree of parallelism in your work. Now that you have set the.
Connection pool size for each function call, the concurrency limit will allow you to plan for a specific number of open connections to your data store. Most cloud providers recommend starting with low concurrency, such as five to ten and then increasing to handle additional peak loads. . With these settings you will now know the minimum and maximum number of open connections and guarantee that you will not exceed these values. Be sure to check out the documentation on Preserving Concurrency to learn more about this configuration. However as your application becomes more popular you may find that your bottleneck is still the connection to the database especially when other parts of your environment also rely on it. In these cases it may be necessary to funnel connections to the database through a proxy. Pooling Database Connections Thankfully connection pooling works with serverless functionality the same way it does with other applications and is an easy.
Changes you can make to your application. The changes are ordered from least impactful and least difficult to most impactful and most difficult. Changing the photo editing servies Client Connection Pool Size Most packages have a way to modify the number of connections a client keeps open to the underlying database called the connection pool. The number of connections in the pool by default may vary but is usually between . If you refer to the above example if you keep connections open per function it will probably be reduced by an order of magnitude even considering the large number of connections. In most cases setting the pool size to the maximum will keep your application running while also guaranteeing The number of connections will never exceed the number of functions running concurrently. If you are still seeing runaway database connections you should set a concurrency limit Most cloud platforms have the ability to limit the amount of concurrency for serverless functions. This gives you protection at the infrastructure level against a degree of parallelism in your work. Now that you have set the.
Connection pool size for each function call, the concurrency limit will allow you to plan for a specific number of open connections to your data store. Most cloud providers recommend starting with low concurrency, such as five to ten and then increasing to handle additional peak loads. . With these settings you will now know the minimum and maximum number of open connections and guarantee that you will not exceed these values. Be sure to check out the documentation on Preserving Concurrency to learn more about this configuration. However as your application becomes more popular you may find that your bottleneck is still the connection to the database especially when other parts of your environment also rely on it. In these cases it may be necessary to funnel connections to the database through a proxy. Pooling Database Connections Thankfully connection pooling works with serverless functionality the same way it does with other applications and is an easy.