This chapter teaches you about how to save costs, and manage and scale multiple SQL databases by using elastic pools. You'll also learn how to implement elastic jobs to manage and maintain databases in an elastic pool.
By the end of this chapter, you will be able to:
An Azure SQL Database Elastic Pool is a cost-effective solution for managing and scaling a group or pool of multiple Azure SQL Databases, with the utilization pattern characterized by low average utilization and infrequent spikes.
All databases in an elastic pool:
In
Chapter 6,
Scaling Out Azure SQL Database, we worked on sharding the
toystore
database into four individual shards. Each shard had 50 pieces of a customer's/tenant's data.
Let's say that each individual database is sized to a Standard S3 service tier, for example, 100 DTUs, and has a DTU utilization as shown in the following graph:
The preceding graph shows the DTU's utilization by time for the
toystore_shard1
database. It is evident from the graph that
toystore_shard1
has an average DTU utilization of around 30 DTU and a spike of 80 DTU around 11:00 AM.
Let's say that the other three shards have similar graphs, however, they peak at different times, as shown in the following graph:
The preceding graph shows the four shards in a combined graph. The average utilization is under 40 DTUs and the peak utilization is 90 DTUs. The database peaks at different points in time.
At this point, one may argue that you should use the Standard S2 service tier, which offers 50 DTU and costs less than S3. This would suffice for most of the database's workload, which is below 50 DTUs, however, this would result in performance degradation for peak hours when the utilization is 90 DTU, which is much greater than 50 DTUs.
You have two options here:
Elastic pools provide you with a third option, which provides the optimum performance at a lower cost.
The four shards are grouped together in an elastic pool with an eDTU of 100, as shown in the following image:
This means that a database:
This not only solves the problem of over- and under-provisioning, but also saves costs, as you only have to pay for eDTUs and not the individual databases' DTUs.
A Standard S3 service tier that has a DTU of 100 is priced at $147/month. Four such databases will cost $588/month.
An elastic pool that has an eDTU of 100 is priced at $221/month, which means that you save $367 per month (62% cost reduction) if you have the database in an elastic pool.
Let's say that as the number of customers increases, you plan to further shard the databases into eight shards. This means that you would have eight databases in an elastic pool. This would result in an 85% monthly cost reduction.
This is where elastic pools are very beneficial.
Elastic pools have great benefits, but only if they are sized properly. Otherwise, one may end up spending a lot more than expected on elastic pools.
Azure SQL Databases automatically analyze historical database utilization numbers and provide elastic pool configuration recommendations on the Azure portal. They also provide eDTU estimates for a custom group of databases on a server. You can add or remove databases from the custom group to get the eDTU recommendations. Once you are satisfied with the pool's configuration, you can create the pool.
If you have to manually estimate whether or not an elastic pool would be more cost-effective than having individual databases, follow these steps:
Let's apply the preceding method to our toystore example:
Total Number of DBs= 4 Average DTU utilization per DB = 30 Number of concurrently peaking DBs = 1 Peak utilization per DB = 90 Estimated eDTUs as per Step 1 above = MAX (4 * 30,1*90) => MAX (120, 90) =120 The estimated eDTU as per Step 1 is 120.
In this chapter, we calculated and compared that the 100 eDTU pool saves 67% of costs compared to having four individual Azure SQL Databases.
The following best practices will help you correctly size an elastic pool:
Minimum Number of Databases
The minimum number of databases required for a pool to be cost-effective is driven by the following formula:
Sum of individual database DTUs > 1.5 X eDTUs
For example, for the toystore pool to be more cost-effective, the minimum number of databases in a pool can be calculated as:
Sum of Individual database DTUs > 150 (1.5 X 100)
This means that you need:
Maximum Number of Concurrently Peaking Databases
An elastic pool allows an Azure SQL Database to peak to the maximum eDTU available for that particular pool. However, not all databases can peak to the maximum eDTU at the same time.
The maximum number of concurrently peaking databases shouldn't be greater than 2/3 or 67% of the total number of databases in the pool.
For example, the toystore pool has four databases, which means that for the pool to be effective, you only need 67% of the four databases in the pool, which means you only need two databases. If more than two databases concurrently peak, then the pool has to be sized by more than 100 eDTU. If the pool is resized to more than 100 eDTU, then more S3 databases need to be added to keep the pool cost-effective.
DTU Utilization per Database
The ideal utilization pattern of a database to be considered for an elastic pool should be low average utilization and short, infrequent high utilization. This utilization pattern is best for sharing eDTUs. If a database has a high average utilization, then it would take most of the eDTUs. This means that the other databases wouldn't get the required eDTUs and would have a lower performance.
A database with a peak utilization that is 1.5 times greater than its average utilization is a good candidate for a pool.
In this section, we will understand how to create an elastic pool and add shards to it. Let us go back to our example of ToyStore Ltd. Mike analyses the report of eDTUs, and thinks of switching to Standard Service Tier 3. However, this would involve higher costs, so he plans to save on costs without worsening customer experience during peak hours. He creates an elastic pool and adds
toystore
store
shards to it through the following steps:
toyfactory
Azure SQL server to open the toyfactory overview blade.toyfactory
overview blade, select New pool from the top menu:You will get an empty graph here as there isn't any workload running on the databases.
You can also change the eDTU max and eDTU min per database. The default eDTU min is 0 and the default eDTU max is 100:
toystore_shard_1_50
, toystore_shard_50_100
, toystore_shard_100_150
, and toytore_150_200
and then click the Select button to continue:Observe that the Peak DTU and Average DTU utilization for each database is listed in the database list. This helps choosing the correct database for the pool. It's zero here as we haven't run any workloads on the databases.
Once you are done selecting the databases, click the Select button to continue.
52.15.47.218