2016-04-02 4 views
1

/DocumentDBに次のような構造を持つ文書をupserting:デフォルトのインデックスを使用している場合Azure DocumentDB - カスタムインデックス作成でインサートの料金を改善できますか?私は挿入しています

enter image description here

この形式の文書をupserting要求料は10.67のRUです。これは私が期待するよりも高く見えるので、私は最適化を目指しています。

この記事では、パフォーマンスのヒントを読んだ後:

https://azure.microsoft.com/en-us/blog/performance-tips-for-azure-documentdb-part-2/

私はレイジーにコレクションのインデックス作成方針の索引付けモードを変更しました。私は要求料金が大幅に少なくなることを期待しましたが、それは9.9RUに低下しました。

次に、インデクシングポリシーを変更して、一連のプロパティを[除外されたパス]に追加しました。ここではカスタムインデックス方針は次のとおりです。除外パスの追加

enter image description here

はアップサートのためのRUに影響しなかった - それは9.9のままでした。

何か間違っていますか?そして、この文書構造のためにupsertsがより少ないRUを消費するようにすることは可能ですか?

編集:ここでは

は、私が設定してDocumentDBへの接続をキャッシュするために使用するヘルパークラスである:

public class Documents 
{ 
    public static Documents Instance = new Documents(); 

    public IReliableReadWriteDocumentClient Client { get; private set; } 

    private Documents() 
    { 
     var endpointUrl = ConfigurationManager.AppSettings["Microsoft.Azure.DocumentDb.EndpointUrl"]; 
     var authKey = ConfigurationManager.AppSettings["Microsoft.Azure.DocumentDb.AuthorizationKey"]; 
     var min = TimeSpan.FromMilliseconds(1000); 
     var max = TimeSpan.FromMilliseconds(5000); 
     var delta = TimeSpan.FromMilliseconds(1000); 
     var connectionPolicy = new ConnectionPolicy() 
     { 
      ConnectionMode = ConnectionMode.Direct, 
      ConnectionProtocol = Protocol.Tcp 
     }; 
     var client = new DocumentClient(new Uri(endpointUrl), authKey, connectionPolicy).AsReliable(new ExponentialBackoff(3, min, max, delta)); 
     Task result = client.OpenAsync(); 
     result.Wait(); 
     Client = client; 
    } 
} 

そして、ここでは私のウェブAPIクラスプットハンドラのコードです:

public class InstallationController : ApiController 
{ 
    private IReliableReadWriteDocumentClient docdb; 
    private string docdbUri; 

    public InstallationController() 
    { 
     docdb = Documents.Instance.Client; 
     var databaseId = ConfigurationManager.AppSettings["Microsoft.Azure.DocumentDb.DatabaseId"]; 
     var collectionName = ConfigurationManager.AppSettings["Microsoft.Azure.DocumentDb.CollectionName"]; 
     docdbUri = "dbs/" + databaseId + "/colls/" + collectionName; 
    } 

    // PUT api/installation/<installationId> 
    // This creates or updates an installation 
    public async Task<IHttpActionResult> Put(string id, DeviceInstallation deviceUpdate) 
    { 
     string message; 
     var telemetryClient = new TelemetryClient(); 

     if (id != deviceUpdate.Id) 
     { 
      return BadRequest(); 
     } 

     // Code to check for existing record with same APNS Token omitted for clarity 

     var upsertResponse = await docdb.UpsertDocumentAsync(docdbUri, deviceUpdate); 
     requestCharge = upsertResponse.RequestCharge; 
     message = string.Format("Request charge for installation upsert: {0}", requestCharge); 
     telemetryClient.TrackTrace(message); 

     // Code to save installation to notification hub omitted for clarity 

     return Ok(); 
    } 
} 
+0

あなたの現在の投稿の内容がわかりにくいので、C#コードを追加してください。一般的に、キャッシングコレクション_selfLink_'sは私に大きなパフォーマンス向上をもたらしました。 –

+0

@IngeHenriksen IDベースのルーティング(これは単なる文字列)を使用して、自己リンク(またはコレクションの自己リンクなどのIDを取得するためのデータベースの関連クエリ)は必要ありません。これはクエリのRUコストとは関係ありません。 –

+0

@IngeHenriksen - リクエストしたコードを追加しました。 –

答えて

1

1kB未満の文書を置換すると、IOと複製のコストのために索引付けが行われずに〜10RUが消費されます。 IndexingプロパティはDocumentDBでは軽量です(プロパティ/用語ごとにわずかなRU)ので、ConsistentからLazyへの移行はこの場合大きな違いにはなりません。もしあなたが何千ものプロパティを持つドキュメントを持っていれば、それは違いになります。

これが役に立ちます。

+0

あなたの答えをありがとう。 RU料金を改善するためには何もできないようです。 –

+0

@Aravind Ramachandran:私のdocumendDBの現在予約されているRUsは24X100 RUsです。私は3X100 RUに減らしたいのですが、どこでそれを行うことができるのですか? –

関連する問題