Lots of our customers implement operational reporting and analytics on DynamoDB utilizing Rockset as a SQL intelligence layer to serve reside dashboards and purposes. As an engineering workforce, we’re consistently looking for alternatives to enhance their SQL-on-DynamoDB expertise.
For the previous few weeks, we’ve been exhausting at work tuning the efficiency of our DynamoDB ingestion course of. Step one on this course of was diving into DynamoDB’s documentation and performing some experimentation to make sure that we have been utilizing DynamoDB’s learn APIs in a manner that maximizes each the steadiness and efficiency of our system.
Background on DynamoDB APIs
AWS presents a Scan API and a Streams API for studying knowledge from DynamoDB. The Scan API permits us to linearly scan a complete DynamoDB desk. That is costly, however typically unavoidable. We use the Scan API the primary time we load knowledge from a DynamoDB desk to a Rockset assortment, as we’ve no technique of gathering all the info apart from scanning by means of it. After this preliminary load, we solely want to observe for updates, so utilizing the Scan API could be fairly wasteful. As an alternative, we use the Streams API which supplies us a time-ordered queue of updates utilized to the DynamoDB desk. We learn these updates and apply them into Rockset, giving customers realtime entry to their DynamoDB knowledge in Rockset!
The problem we’ve been enterprise is to make ingesting knowledge from DynamoDB into Rockset as seamless and cost-efficient as doable given the constraints introduced by knowledge sources, like DynamoDB. Following, I’ll focus on just a few of points we bumped into in tuning and stabilizing each phases of our DynamoDB ingestion course of whereas protecting prices low for our customers.
Scans
How we measure scan efficiency
Through the scanning part, we intention to persistently maximize our learn throughput from DynamoDB with out consuming greater than a user-specified variety of RCUs per desk. We wish ingesting knowledge into Rockset to be environment friendly with out interfering with current workloads operating on customers’ reside DynamoDB tables.
Understanding the right way to set scan parameters
From very preliminary testing, we seen that our scanning part took fairly a very long time to finish so we did some digging to determine why. We ingested a DynamoDB desk into Rockset and noticed what occurred in the course of the scanning part. We anticipated to persistently eat all the provisioned throughput.
Initially, our RCU consumption appeared like the next:
We noticed an inexplicable stage of fluctuation within the RCU consumption over time, notably within the first half of the scan. These fluctuations are unhealthy as a result of every time there’s a serious drop within the throughput, we find yourself lengthening the ingestion course of and growing our customers DynamoDB prices.
The issue was clear however the underlying trigger was not apparent. On the time, there have been just a few variables that we have been controlling fairly naively. DynamoDB exposes two essential variables: web page dimension and section depend, each of which we had set to fastened values. We additionally had our personal fee limiter which throttled the variety of DynamoDB Scan API calls we made. We had additionally set the restrict this fee limiter was imposing to a hard and fast worth. We suspected that one among these variables being sub-optimally configured was the doubtless explanation for the large fluctuations we have been observing.
Some investigation revealed that the reason for the fluctuation was primarily the speed limiter. It turned out the fastened restrict we had set on our fee limiter was too low, so we have been getting throttled too aggressively by our personal fee limiter. We determined to repair this drawback by configuring our limiter based mostly on the quantity of RCU allotted to the desk. We are able to simply (and do plan to) transition to utilizing a user-specified variety of RCU for every desk, which can permit us to restrict Rockset’s RCU consumption even when customers have RCU autoscaling enabled.
public int getScanRateLimit(AmazonDynamoDB consumer, String tableName,
int numSegments) {
TableDescription tableDesc = consumer.describeTable(tableName).getTable();
// Be aware: this may return 0 if the desk has RCU autoscaling enabled
closing lengthy tableRcu = tableDesc.getProvisionedThroughput().getReadCapacityUnits();
closing int numSegments = config.getNumSegments();
return desiredRcuUsage / numSegments;
}
For every section, we carry out a scan, consuming capability on our fee limiter as we eat DynamoDB RCU’s.
public void doScan(AmazonDynamoDb consumer, String tableName, int numSegments) {
RateLimiter rateLimiter = RateLimiter.create(getScanRateLimit(consumer,
tableName, numSegments))
whereas (!executed) {
ScanResult end result = consumer.scan(/* feed scan request in */);
// do processing ...
rateLimiter.purchase(end result.getConsumedCapacity().getCapacityUnits());
}
}
The results of our new Scan configuration was the next:
We have been blissful to see that, with our new configuration, we have been in a position to reliably management the quantity of throughput we consumed. The issue we found with our fee limiter dropped at mild our underlying want for extra dynamic DynamoDB Scan configurations. We’re persevering with to run experiments to find out the right way to dynamically set the web page dimension and section depend based mostly on table-specific knowledge, however we additionally moved onto coping with among the challenges we have been going through with DynamoDB Streams.
Streams
How we measure streaming efficiency
Our aim in the course of the streaming part of ingestion is to attenuate the period of time it takes for an replace to enter Rockset after it’s utilized in DynamoDB whereas protecting the fee utilizing Rockset as little as doable for our customers. The first price issue for DynamoDB Streams is the variety of API calls we make. DynamoDB’s pricing permits customers 2.5 million free API calls and expenses $0.02 per 100,000 requests past that. We need to attempt to keep as near the free tier as doable.
Beforehand we have been querying DynamoDB at a fee of ~300 requests/second as a result of we encountered numerous empty shards within the streams we have been studying. We believed that we’d have to iterate by means of all of those empty shards whatever the fee we have been querying at. To mitigate the load we placed on customers’ Dynamo tables (and in flip their wallets), we set a timer on these reads after which stopped studying for five minutes if we didn’t discover any new data. On condition that this mechanism ended up charging customers who didn’t even have a lot knowledge in DynamoDB and nonetheless had a worst case latency of 5 minutes, we began investigating how we may do higher.
Lowering the frequency of streaming calls
We ran a number of experiments to make clear our understanding of the DynamoDB Streams API and decide whether or not we may scale back the frequency of the DynamoDB Streams API calls our customers have been being charged for. For every experiment, we different the period of time we waited between API calls and measured the typical period of time it took for an replace to a DynamoDB desk to be mirrored in Rockset.
Inserting data into the DynamoDB desk at a relentless fee of two data/second, the outcomes have been as follows:
Inserting data into the DynamoDB desk in a bursty sample, the outcomes have been as follows:
The outcomes above confirmed that making 1 API name each second is a lot to make sure that we keep sub-second latencies. Our preliminary assumptions have been improper, however these outcomes illuminated a transparent path ahead. We promptly modified our ingestion course of to question DynamoDB Streams for brand new knowledge solely as soon as per second so as give us the efficiency we’re in search of at a a lot decreased price to our customers.
Calculating our price discount
Since with DynamoDB Streams we’re immediately chargeable for our customers prices, we determined that we would have liked to exactly calculate the fee our customers incur because of the manner we use DynamoDB Streams. There are two elements which wholly decide the quantity that customers will likely be charged for DynamoDB Streams: the variety of Streams API calls made and the quantity of knowledge transferred. The quantity of knowledge transferred is basically past our management. Every API name response unavoidably transfers a small quantity (768 bytes) of knowledge. The remaining is all consumer knowledge, which is barely learn into Rockset as soon as. We centered on controlling the variety of DynamoDB Streams API calls we make to customers’ tables as this was beforehand the motive force of our customers’ DynamoDB prices.
Following is a breakdown of the fee we estimate with our newly reworked ingestion course of:
We have been blissful to see that, with our optimizations, our customers ought to incur just about no extra price on their DynamoDB tables on account of Rockset!
Conclusion
We’re actually excited that the work we’ve been doing has efficiently pushed DynamoDB prices down for our customers whereas permitting them to work together with their DynamoDB knowledge in Rockset in realtime!
This can be a simply sneak peek into among the challenges and tradeoffs we’ve confronted whereas working to make ingesting knowledge from DynamoDB into Rockset as seamless as doable. When you’re occupied with studying extra about the right way to operationalize your DynamoDB knowledge utilizing Rockset try a few of our latest materials and keep tuned for updates as we proceed to construct Rockset out!
If you would like to see Rockset and DynamoDB in motion, it is best to try our transient product tour.
Different DynamoDB assets: