1

約 1,000,000 個の json ファイルがあり、30 分ごとに更新したいと考えています。更新は、既存のコンテンツの末尾に新しい配列を追加するだけです。

1 回の更新では、次のようなコードが使用されます。

            CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobName);

            JObject jObject = null;
            // If the blob exists, then we may need to update it.
            if(blockBlob.Exists())
            {
                MemoryStream memoryStream = new MemoryStream();
                blockBlob.DownloadToStream(memoryStream);

                jObject = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(memoryStream.ToArray())) as JObject;
            } // End of the blob exists

            if(null == jObject)
            {
                jObject = new JObject();
                jObject.Add(new JProperty("identifier", identifier));
            } // End of the blob did not exist

            JArray jsonArray = new JArray();

            jObject.Add(new JProperty(string.Format("entries{0}", timestamp.ToString()),jsonArray));

            foreach(var entry in newEntries)
            {
                jsonArray.Add(new JObject(
                    new JProperty("someId", entry.id),
                    new JProperty("someValue", value)
                    )
                );
            } // End of loop

            string jsonString = JsonConvert.SerializeObject(jObject);

            // Upload
            blockBlob.Properties.ContentType = "text/json";
            blockBlob.UploadFromStream(new MemoryStream(Encoding.UTF8.GetBytes(jsonString)));

基本的:

  1. ブロブが存在するかどうかを確認し、
  2. 存在する場合は、データをダウンロードし、既存の詳細から json オブジェクトを作成します。
  3. そうでない場合は、詳細を含む新しいオブジェクトを作成します。
  4. 更新を BLOB にプッシュします。

これに関する問題はパフォーマンスです。パフォーマンスを向上させるためにできることはかなりあります (更新は 5 つの並列スレッドで実行されServicePointManager.UseNagleAlgorithm、false に設定しました。

それでも動作は遅いです。約 100,000 件の更新には、最大 1 時間かかる場合があります。

基本的に、私の質問は次のようになります。

  1. これには Azure Blob Storage を使用する必要がありますか? (私は別の提案を受け入れます)。
  2. もしそうなら、パフォーマンスを改善するための提案はありますか?

注: ファイルには基本的にイベントの履歴が含まれており、既存のデータに基づいてファイル全体を再生成することはできません。これが、コンテンツが更新される前にダウンロードされる理由です。

4

0 に答える 0