Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[ウェビナー] 実録! Cosmos DBでのチャットサービス稼働 ~MongoDB API編~

isana.net,inc.
August 14, 2018
480

[ウェビナー] 実録! Cosmos DBでのチャットサービス稼働 ~MongoDB API編~

isana.net,inc.

August 14, 2018
Tweet

Transcript

  1. Everything as a Service on Azure NOSQLは? 特に MongoDB は?

    アプリサーバ Azure Web Apps キャッシュサーバ Azure Redis Cache サーバ監視 Application Insights データベース Azure SQL Database ? Copyright © 2018 isana.net,inc. All Rights Reserved.
  2. MongoDB as a Service がやってきた 他、SQL / Graph / テーブル/

    Cassandra API に対応したマルチモデルデータベース Copyright © 2018 isana.net,inc. All Rights Reserved.
  3. Cosmos DB のここがスゴイ Cosmos DB 対応は 1⾏ 書き換えで動作 (MongoDB API)

    ⾃動シャーディング・⾃動インデックス 詳しくは Web で 可⽤性 99.99% (すべてのマルチリージョンで⾮同期レプ リケーション使⽤時なら、99.999%) 待ち時間10ミリ秒以内 (99%の確率、⼀般的な1KBでの読 み込みにおけるエンドツーエンド) Copyright © 2018 isana.net,inc. All Rights Reserved.
  4. サービス紹介 Spika for Business •  ⾃社サービス・製品に •  オンプレミスで導⼊ •  フレキシブルな

    カスタマイズ性 •  リアルタイムチャット •  ユーザー数の関係ない ライセンス費⽤ Spika for business Copyright © 2018 isana.net,inc. All Rights Reserved.
  5. サービス紹介 Spika on Azure Copyright © 2018 isana.net,inc. All Rights

    Reserved. テキストchat と・・・ 翻訳 分析 提案 Q&A
  6. システム構成 (ほとんど PaaS) iOS/Android Azure Web App for Containers Redis

    Cache Cosmos DB Docker Hub Copyright © 2018 isana.net,inc. All Rights Reserved.
  7. RU/秒をオートスケール 定期バッチ処理などで RU/秒 を 制御しましょう (Azure CLI) 失敗例) Webサーバ の

    CPU / メモリ使⽤率 でスケール調整を計画  ⇒ 意外とアクセス数と⽐例せず、  ⇒ Cosmos DB の RU/秒 調整には使えず 時間帯 / 曜⽇ での管理がオススメ ⼀時的なアクセス増⼤に備え、バッファは必要 Copyright © 2018 isana.net,inc. All Rights Reserved.
  8. 実際の⾒積り⽅(1) Endpoint Collection Method Option RU /signin apikeys findOne key:

    ? 3.84 organizations findOne _id: ? 2.99 users findOne _id: ? 3.50 users update _id: ? 4.81 APIごと / クエリーごとに RU を計測 削除では消えたデータサイズ分の RU が消費 Copyright © 2018 isana.net,inc. All Rights Reserved. 実例
  9. RU消費量計測 以下のコードで取得できます https://docs.microsoft.com/ja-jp/azure/cosmos-db/set-throughput より抜粋 db.executeDbAdminCommand({getLastRequestStatistics: 1}, (err, doc) => {

    if(!err) { console.log(`RequestCharge is ${doc.RequestCharge}`); } }); •  メトリクス / 診断ログから取得 •  Azure Portal 上でコマンド実⾏ Copyright © 2018 isana.net,inc. All Rights Reserved. 他の⽅法
  10. データ移⾏ Mongo DB リストア ⇒ 簡単にRU/秒の上限を超えます https://docs.microsoft.com/ja-jp/azure/cosmos-db/mongodb-migrate より リストア時には以下のようなオプションが必要です。 mongorestore

    --host 〜 -u〜 -p 〜 --ssl --sslAllowInvalidCertificates ./dumps/dump --numInsertionWorkersPerCollection 4 --batchSize 24 RUを計算する⽅法が公式ページであるが、⼩さい値から初めて、 徐々に⼤きくするほうが簡単 または Windows 向けのデータ移⾏ツール (azure-documentdb- datamigrationtool) を使⽤してください Copyright © 2018 isana.net,inc. All Rights Reserved.
  11. 忘れやすいポイント SSL接続 再接続設定 var options = { autoReconnect: true, //

    再接続あり connectTimeoutMS: 60000, // コネクションタイムアウト [ms] socketTimeoutMS: 60000, // ソケットタイムアウト [ms] reconnectInterval: 3000, // 再接続試行間隔 [ms] reconnectTries: Infinity // できるかぎり再接続を試みる }; mongoose.connect(‘mongodb://〜&ssl=true’, options, function(err){ ... }); MongoDB では以下の設定を忘れずに Copyright © 2018 isana.net,inc. All Rights Reserved.