

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 評估將 SQL Server 資料庫遷移至 AWS 上的 MongoDB Atlas 的查詢效能
<a name="assess-query-performance-for-migrating-sql-server-databases-to-mongodb-atlas-on-aws"></a>

*Battulga Purevragchaa，Amazon Web Services*

*Krishnakumar Sathyanarayana，PeerIslands 美國公司*

*Babu Srinivasan，MongoDB*

## 摘要
<a name="assess-query-performance-for-migrating-sql-server-databases-to-mongodb-atlas-on-aws-summary"></a>

此模式提供使用接近真實世界的資料載入 MongoDB，以及評估 MongoDB 查詢效能的指引，盡可能接近生產案例。評估提供輸入，協助您規劃從關聯式資料庫遷移至 MongoDB。此模式使用 [PeerIslands Test Data Generator 和 Performance Analyzer](https://tools.peerislands.io/) 來測試查詢效能。

此模式對於 Microsoft SQL Server 遷移至 MongoDB 特別有用，因為執行結構描述轉換並將資料從目前的 SQL Server 執行個體載入至 MongoDB 可能非常複雜。相反地，您可以將接近真實世界的資料載入 MongoDB、了解 MongoDB 效能，並在開始實際遷移之前微調結構描述設計。

## 先決條件和限制
<a name="assess-query-performance-for-migrating-sql-server-databases-to-mongodb-atlas-on-aws-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 熟悉 [MongoDB Atlas](https://www.mongodb.com/docs/atlas/getting-started/)
+ 目標 MongoDB 結構描述
+ 典型查詢模式

**限制**
+ 資料載入時間和效能會受到 MongoDB 叢集執行個體大小的限制。我們建議您選擇建議用於生產用途的執行個體，以了解實際效能。
+ PeerIslands Test Data Generator and Performance Analyzer 目前僅支援線上資料載入和查詢。尚未支援離線批次處理 （例如，使用 Spark 連接器將資料載入 MongoDB)。
+ PeerIslands Test Data Generator and Performance Analyzer 支援集合中的欄位關係。它不支援跨集合的關係。

**產品版本**
+ 此模式同時支援 [MongoDB Atlas](https://www.mongodb.com/atlas) 和 [MongoDB Enterprise Advanced](https://www.mongodb.com/products/mongodb-enterprise-advanced)。

## Architecture
<a name="assess-query-performance-for-migrating-sql-server-databases-to-mongodb-atlas-on-aws-architecture"></a>

**目標技術堆疊**
+ MongoDB Atlas 或 MongoDB Enterprise Advanced

**架構**

![\[評估將 SQL Server 資料庫遷移至 AWS 上 MongoDB Atlas 的查詢效能的架構。\]](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/25f0ab73-d587-4bd0-9fc0-ac675d5aa349/images/717caae4-d52e-4c78-bb7d-2ecb5acccd42.png)


PeerIslands Test Data Generator and Performance Analyzer 是使用 Java 和 Angular 建置的，並將產生的資料存放在 Amazon Elastic Block Store (Amazon EBS)。此工具包含兩個工作流程：測試資料產生和效能測試。
+ 在測試資料產生中，您會建立範本，這是必須產生之資料模型的 JSON 表示法。建立範本後，您可以在目標集合中產生資料，如負載產生組態所定義。
+ 在效能測試中，您會建立設定檔。設定檔是一種多階段測試案例，您可以在其中設定建立、讀取、更新和刪除 (CRUD) 操作、彙總管道、每個操作的權重，以及每個階段的持續時間。建立設定檔之後，您可以根據組態在目標資料庫上執行效能測試。

PeerIslands Test Data Generator and Performance Analyzer 將其資料存放在 Amazon EBS 上，因此您可以使用任何 MongoDB 支援的連線機制，包括對等互連、允許清單和私有端點，將 Amazon EBS 連線至 MongoDB。根據預設，工具不包含操作元件；不過，如果需要，可以使用 Amazon Managed Service for Prometheus、Amazon Managed Grafana、Amazon CloudWatch 和 AWS Secrets Manager 進行設定。

## 工具
<a name="assess-query-performance-for-migrating-sql-server-databases-to-mongodb-atlas-on-aws-tools"></a>
+ [PeerIslands Test Data Generator and Performance Analyzer](https://tools.peerislands.io/) 包含兩個元件。測試資料產生器元件可協助您根據 MongoDB 結構描述產生高度客戶特定的真實世界資料。該工具完全由 UI 驅動，具有豐富的資料程式庫，可用於在 MongoDB 上快速產生數十億筆記錄。此工具也提供在 MongoDB 結構描述中的欄位之間實作關係的功能。Performance Analyzer 元件可協助您產生高度客戶特定的查詢和彙總，並在 MongoDB 上執行逼真的效能測試。您可以使用 Performance Analyzer，針對特定使用案例使用豐富的負載描述檔和參數化查詢來測試 MongoDB 效能。

## 最佳實務
<a name="assess-query-performance-for-migrating-sql-server-databases-to-mongodb-atlas-on-aws-best-practices"></a>

請參閱下列資源：
+ [MongoDB 結構描述設計最佳實務 ](https://www.mongodb.com/developer/products/mongodb/mongodb-schema-design-best-practices/)(MongoDB 開發人員網站）
+ [在 AWS 上部署 MongoDB Atlas 的最佳實務](https://www.mongodb.com/presentation/best-practices-of-deploying-mongodb-atlas-on-aws) (MongoDB 網站）
+ [使用 AWS PrivateLink 將應用程式安全地連接到 MongoDB Atlas 資料平面](https://aws.amazon.com/blogs/apn/connecting-applications-securely-to-a-mongodb-atlas-data-plane-with-aws-privatelink/) (AWS 部落格文章）
+ [MongoDB 效能的最佳實務指南 ](https://www.mongodb.com/basics/best-practices)(MongoDB 網站）

## 史詩
<a name="assess-query-performance-for-migrating-sql-server-databases-to-mongodb-atlas-on-aws-epics"></a>

### 了解您的來源資料
<a name="understand-your-source-data"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 了解目前 SQL Server 來源的資料庫使用量。 | 了解您目前的 SQL Server 使用量。這可以透過對資料庫的`INFORMATION`結構描述執行查詢來實現。決定資料表的數量和每個資料表的大小。分析與每個資料表相關聯的索引。如需 SQL 分析的詳細資訊，請參閱 PeerIslands 網站上的部落格文章 [SQL2Mongo：Data Migration Journey](https://engineering.peerislands.io/sql2mongo-data-migration-journey-fec91a421d60)。 | DBA | 
| 了解來源結構描述。 | 決定資料表結構描述和資料的業務表示方式 （例如，郵遞區號、名稱和貨幣）。使用您現有的實體關係 (ER) 圖表，或從現有的資料庫產生 ER 圖表。如需詳細資訊，請參閱 PeerIslands 網站上的部落格文章 [SQL2Mongo：Data Migration Journey](https://engineering.peerislands.io/sql2mongo-data-migration-journey-fec91a421d60)。 | DBA | 
| 了解查詢模式。 | 記錄您使用的前 10 個 SQL 查詢。您可以使用資料庫中可用的 **performance\$1schema.events\$1statements\$1summary\$1by\$1digest** 資料表來了解熱門查詢。如需詳細資訊，請參閱 PeerIslands 網站上的部落格文章 [SQL2Mongo：Data Migration Journey](https://engineering.peerislands.io/sql2mongo-data-migration-journey-fec91a421d60)。 | DBA | 
| 了解 SLA 承諾。 | 記錄資料庫操作的目標服務層級協議 (SLAs)。典型的措施包括查詢延遲和每秒查詢數。措施及其目標通常可在非功能需求 (NFR) 文件中取得。 | DBA | 

### 定義 MongoDB 結構描述
<a name="define-the-mongodb-schema"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 定義目標結構描述。 | 定義目標 MongoDB 結構描述的各種選項。如需詳細資訊，請參閱 MongoDB Atlas 文件中的[結構描述](https://www.mongodb.com/docs/atlas/app-services/schemas/)。根據資料表關係考慮最佳實務和設計模式。 | MongoDB 工程師 | 
| 定義目標查詢模式。 | 定義 MongoDB 查詢和彙總管道。這些查詢等同於您為 SQL Server 工作負載擷取的熱門查詢。若要了解如何建構 MongoDB 彙總管道，請參閱 [MongoDB 文件](https://www.mongodb.com/docs/manual/core/aggregation-pipeline/)。 | MongoDB 工程師 | 
| 定義 MongoDB 執行個體類型。 | 決定您計劃用於測試的執行個體大小。如需指引，請參閱 [MongoDB 文件](https://www.mongodb.com/docs/atlas/sizing-tier-selection/)。 | MongoDB 工程師 | 

### 準備目標資料庫
<a name="prepare-the-target-database"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 設定 MongoDB Atlas 叢集。 | 若要在 AWS 上設定 MongoDB 叢集，請遵循 [MongoDB 文件](https://www.mongodb.com/docs/atlas/tutorial/create-new-cluster/)中的指示。 | MongoDB 工程師 | 
| 在目標資料庫中建立使用者。 | 遵循 MongoDB 文件中[的指示，設定 MongoDB ](https://www.mongodb.com/docs/atlas/connect-to-database-deployment/)Atlas 叢集以進行存取和網路安全。 | MongoDB 工程師 | 
| 在 AWS 中建立適當的角色，並設定 Atlas 的角色型存取控制。 | 如有必要，請遵循 [MongoDB 文件](https://www.mongodb.com/docs/atlas/security/set-up-unified-aws-access/)中的指示來設定其他使用者。透過 AWS 角色設定[身分驗證和授權](https://www.mongodb.com/docs/atlas/security/config-db-auth/)。 | MongoDB 工程師 | 
| 設定 MongoDB Atlas 存取的 Compass。 | 設定 [MongoDB Compass GUI 公用程式](https://www.mongodb.com/products/compass)，以便於導覽和存取。 | MongoDB 工程師 | 

### 使用測試資料產生器設定基本負載
<a name="set-up-the-base-load-by-using-test-data-generator"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 安裝測試資料產生器。 | 在您的環境中安裝 [PeerIsland Test Data Generator](https://github.com/PeerIslands/loadgen_binary)。 | MongoDB 工程師 | 
| 設定測試資料產生器以產生適當的資料。 | 使用資料程式庫為 MongoDB 結構描述中的每個欄位產生特定資料，以建立範本。如需詳細資訊，請參閱 [MongoDB Data Generator & Perf。Analyzer](https://vimeo.com/570068857) 影片。 | MongoDB 工程師 | 
| 水平擴展測試資料產生器以產生所需的負載。 | 使用您建立的範本，透過設定所需的平行處理，開始針對目標集合產生負載。決定時間範圍並擴展以產生必要的資料。 | MongoDB 工程師 | 
| 驗證 MongoDB Atlas 中的負載。 | 檢查載入 MongoDB Atlas 的資料。 | MongoDB 工程師 | 
| 在 MongoDB 上產生所需的索引。 | 根據查詢模式，視需要定義索引。如需最佳實務，請參閱 [MongoDB 文件](https://www.mongodb.com/docs/manual/applications/indexes/)。 | MongoDB 工程師 | 

### 執行效能測試
<a name="conduct-performance-testing"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 Performance Analyzer 中設定負載描述檔。 | 透過設定特定查詢及其對應的權重、測試執行持續時間和階段，在 Performance Analyzer 中建立效能測試設定檔。如需詳細資訊，請參閱 [MongoDB Data Generator & Perf。Analyzer](https://vimeo.com/570068857) 影片。 | MongoDB 工程師 | 
| 執行效能測試。 | 使用您建立的效能測試描述檔，透過設定所需的平行處理開始針對目標集合進行測試。水平擴展效能測試工具，以針對 MongoDB Atlas 執行查詢。 | MongoDB 工程師 | 
| 記錄測試結果。 | 記錄查詢的 P95, P99 延遲。 | MongoDB 工程師 | 
| 調校您的結構描述和查詢模式。 | 修改索引和查詢模式，以解決任何效能問題。 | MongoDB 工程師 | 

### 關閉專案
<a name="close-the-project"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 關閉臨時 AWS 資源。 | 刪除您用於測試資料產生器和效能分析器的所有臨時資源。 | AWS 管理員 | 
| 更新效能測試結果。 | 了解 MongoDB 查詢效能並將其與您的 SLAs 進行比較。如有必要，請微調 MongoDB 結構描述並重新執行程序。 | MongoDB 工程師 | 
| 結束專案。 | 關閉專案並提供意見回饋。 | MongoDB 工程師 | 

## 相關資源
<a name="assess-query-performance-for-migrating-sql-server-databases-to-mongodb-atlas-on-aws-resources"></a>
+ GitHub 儲存庫：[S3toAtlas](https://github.com/mongodb-partners/S3toAtlas)
+ 結構描述：[MongoDB 結構描述設計](https://www.mongodb.com/developer/products/mongodb/mongodb-schema-design-best-practices/)
+ 彙總管道 ：[MongoDB 彙總管道](https://www.mongodb.com/docs/manual/core/aggregation-pipeline/)
+ MongoDB Atlas 大小：[大小層選擇](https://www.mongodb.com/docs/atlas/sizing-tier-selection/)
+ 影片：[MongoDB Data Generator](https://vimeo.com/570068857) & Perf。分析器
+ 參考：[MongoDB 文件](https://www.mongodb.com/docs/)
+ 教學課程：** **[MongoDB 開發人員指南、](https://www.mongodb.com/docs/develop-applications/)M[MongoDB Jumpstart](https://www.youtube.com/playlist?list=PL4RCxklHWZ9v2lcat4oEVGQhZg6r4IQGV)
+ AWS Marketplace：** **[AWS Marketplace 上的 MongoDB Atlas](https://aws.amazon.com/marketplace/seller-profile?id=c9032c7b-70dd-459f-834f-c1e23cf3d092)
+ AWS 合作夥伴解決方案：** **[ AWS 參考部署上的 MongoDB Atlas](https://aws.amazon.com/quickstart/architecture/mongodb-atlas/)

其他資源：
+ [SQL 分析](https://engineering.peerislands.io/sql2mongo-data-migration-journey-fec91a421d60)
+ [MongoDB 開發人員社群論壇](https://www.mongodb.com/community/forums/)
+ [MongoDB 效能調校問題](https://www.mongodb.com/developer/products/mongodb/performance-tuning-tips/)
+ [Atlas 和 Redshift 的操作分析](https://github.com/mongodb-partners/Atlas_to_Redshift)
+ [使用 MongoDB Atlas 和 AWS Elastic Beanstalk 進行應用程式現代化](https://github.com/mongodb-partners/MEANStack_with_Atlas_on_AWS_EB)