Dynamodb 简明教程
DynamoDB - Best Practices
在使用各种来源和元素时,某些做法可以优化代码,防止错误并最大限度地降低吞吐量的成本。
Certain practices optimize code, prevent errors, and minimize throughput cost when working with various sources and elements.
以下是 DynamoDB 中一些最重要且使用最广泛的最佳实践。
The following are some of the most important and commonly used best practices in DynamoDB.
Tables
表的分布意味着最佳方法是在所有表项目中均匀地分摊读写活动。
The distribution of tables means the best approaches spread read/write activity evenly across all table items.
目标是均匀地访问表项目上的数据。最佳吞吐量使用取决于主键选择和项目工作负载模式。在分区键值之间均匀地分摊工作负载。避免使用少量大量使用的分区键值等。选择像大量不同的分区键值这样的更优选择。
Aim for uniform data access on table items. Optimal throughput usage rests on primary key selection and item workload patterns. Spread the workload evenly across partition key values. Avoid things like a small amount of heavily used partition key values. Opt for better choices like large quantities of distinct partition key values.
了解分区行为。评估通过 DynamoDB 自动分配的分区。
Gain an understanding of partition behavior. Estimate partitions automatically allocated by DynamoDB.
DynamoDB 提供突发吞吐量使用,它为“突发”功率保留未使用的吞吐量。避免频繁使用此选项,因为突发会快速消耗大量吞吐量;此外,它并不是一个可靠的资源。
DynamoDB offers burst throughput usage, which reserves unused throughput for “bursts” of power. Avoid heavy use of this option because bursts consume large amounts of throughput quickly; furthermore, it does not prove a reliable resource.
在上传时,分布数据以获得更好的性能。通过并发上传到所有已分配的服务器来实施此操作。
On uploads, distribute data in order to achieve better performance. Implement this by uploading to all allocated servers concurrently.
缓存常用项,将读取活动卸载到缓存而不是数据库。
Cache frequently used items to offload read activity to the cache rather than the database.
Items
限制、性能、大小和访问成本仍然是项目中最受关注的问题。选择一对多表。删除属性并划分表以匹配访问模式。通过这种简单的方法,您可以显着提高效率。
Throttling, performance, size, and access costs remain the biggest concerns with items. Opt for one-to-many tables. Remove attributes and divide tables to match access patterns. You can improve efficiency dramatically through this simple approach.
将大值压缩后再存储。利用标准压缩工具。为 S3 等大属性值使用备用存储。您可以将对象存储在 S3 中,并在项目中存储一个标识符。
Compress large values prior to storing them. Utilize standard compression tools. Use alternate storage for large attribute values such as S3. You can store the object in S3, and an identifier in the item.
通过虚拟项目块在多个项目中分布大属性。这提供了解决项目大小限制的方法。
Distribute large attributes across several items through virtual item pieces. This provides a workaround for the limitations of item size.
Queries and Scans
查询和扫描主要面临吞吐量消耗方面的挑战。避免突发,这通常是由切换到强一致性读取等操作导致的。以低资源消耗的方式使用并行扫描(即没有限制的后台函数)。此外,仅将它们与大型表一起使用,并且在您未充分利用吞吐量或扫描操作性能不佳的情况下使用它们。
Queries and scans mainly suffer from throughput consumption challenges. Avoid bursts, which typically result from things like switching to a strongly consistent read. Use parallel scans in a low-resource way (i.e., background function with no throttling). Furthermore, only employ them with large tables, and situations where you do not fully utilize throughput or scan operations offer poor performance.
Local Secondary Indices
索引在吞吐量和存储成本以及查询效率方面存在问题。除非您经常查询属性,否则请避免建立索引。在投影中,做出明智选择,因为它们会使索引变得臃肿。仅选择那些使用频繁的。
Indexes present issues in the areas of throughput and storage costs, and the efficiency of queries. Avoid indexing unless you query the attributes often. In projections, choose wisely because they bloat indexes. Select only those heavily used.
使用稀疏索引,即排序键在所有表项目中均未出现的索引。它们有利于针对大多数表项目中不存在的属性进行的查询。
Utilize sparse indexes, meaning indexes in which sort keys do not appear in all table items. They benefit queries on attributes not present in most table items.
注意项目集合(所有表项目及其索引)的扩展。添加/更新操作会导致表和索引增长,并且集合的限制仍然为 10GB。
Pay attention to the item collection (all table items and their indices) expansion. Add/update operations cause both tables and indexes to grow, and 10GB remains the limit for collections.
Global Secondary Indices
索引在吞吐量和存储成本以及查询效率方面存在问题。选择键属性传播,它就像表中的读/写传播一样,提供工作负载的均匀性。选择可以均匀分布数据的属性。另外,使用稀疏索引。
Indexes present issues in the areas of throughput and storage costs, and the efficiency of queries. Opt for key attributes spreading, which like read/write spreading in tables provides workload uniformity. Choose attributes which evenly spread data. Also, utilize sparse indexes.
利用全局二级索引对请求少量数据的查询进行快速搜索。
Exploit global secondary indices for fast searches in queries requesting a modest amount of data.