Skip to Content
MongoDB权威指南(第3版)
book

MongoDB权威指南(第3版)

by Shannon Bradshaw, Eoin Brazil, Kristina Chodorow
November 2021
Intermediate to advanced
410 pages
12h 1m
Chinese
Posts & Telecom Press
Content preview from MongoDB权威指南(第3版)
263
16
选择片键
使用分片时最重要的任务是选择数据的分发方式。为了在这方面做出明智的选择,必须了
MongoDB
是如何分发数据的。本章旨在帮助你更好地选择片键,包括:
如何在多个可用的片键中做出选择;
不同使用场景中的片键选择;
哪些键不能作为片键;
自定义数据分发方式的可选策略;
如何手动对数据分片。
本章假设你已经理解了前两章介绍的关于分片基本组件的知识。
16.1
 评估使用情况
在对集合进行分片时,需要选择一两个字段来对数据进行拆分。这个键(或这些键)称为
片键
。一旦对一个集合进行了分片,就不能更改片键了,因此正确选择片键是十分重要的。
要选择一个好的片键,需要了解工作负载以及片键将如何分发应用程序的请求。这可能不
太好描述,可以尝试找出一些例子,或者更进一步,在具有样本流量的备份数据集上做一
些实验。本节有许多图表和解释,但这些都不如在自己的数据上试一试。
对于计划分片的每个集合,首先回答以下问题。
计划进行多少个分片?
3
个分片的集群比
1000
个分片的集群具有更大的灵活性
。随着
集群的增长,不应该使用会触发所有分片的查询,因此大部分查询应该包含片键。
分片是为了减少读写延迟吗?(延迟指某个操作需要花费的时间。例如,一个写操作要
花费
20
毫秒
,但你需要它
10
毫秒就完成。)降低写延迟通常包括将请求发送到地理位
置更近或功能更强大的机器上。
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

大数据项目管理:从规划到实现

大数据项目管理:从规划到实现

Ted Malaska, Jonathan Seidman
Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉
Spark快速大数据分析(第2版)

Spark快速大数据分析(第2版)

Jules S. Damji, Brooke Wenig, Tathagata Das, Denny Lee
Kafka权威指南(第2版)

Kafka权威指南(第2版)

Gwen Shapira, Todd Palino, Rajini Sivaram, Krit Petty

Publisher Resources

ISBN: 9787115576538