Windows azure キューの場合、ストレージあたりのスケーラビリティ ターゲットは約 500 メッセージ/秒と想定されています ( http://msdn.microsoft.com/en-us/library/windowsazure/hh697709.aspx )。いくつかのメッセージをキューに書き込むだけの次の簡単なプログラムがあります。プログラムが完了するまでに 10 秒かかります (1 秒あたり 4 メッセージ)。仮想マシン内 (西ヨーロッパ) からプログラムを実行しており、ストレージ アカウントも西ヨーロッパにあります。ストレージの geo レプリケーションをセットアップしていません。私の接続文字列は、http プロトコルを使用するように設定されています。
// http://blogs.msdn.com/b/windowsazurestorage/archive/2010/06/25/nagle-s-algorithm-is-not-friendly-towards-small-requests.aspx
ServicePointManager.UseNagleAlgorithm = false;
CloudStorageAccount storageAccount=CloudStorageAccount.Parse(ConfigurationManager.AppSettings["DataConnectionString"]);
var cloudQueueClient = storageAccount.CreateCloudQueueClient();
var queue = cloudQueueClient.GetQueueReference(Guid.NewGuid().ToString());
queue.CreateIfNotExist();
var w = new Stopwatch();
w.Start();
for (int i = 0; i < 50;i++ )
{
Console.WriteLine("nr {0}",i);
queue.AddMessage(new CloudQueueMessage("hello "+i));
}
w.Stop();
Console.WriteLine("elapsed: {0}", w.ElapsedMilliseconds);
queue.Delete();
どうすればパフォーマンスを向上させることができますか?
編集:
Sandrino Di Mattia の回答に基づいて、最初に投稿したコードを再分析したところ、エラーを再現するには不十分であることがわかりました。実際、ServicePointManager.UseNagleAlgorithm = false; を呼び出す直前にキューを作成しました。私の問題を再現するコードは次のようになります。
CloudStorageAccount storageAccount=CloudStorageAccount.Parse(ConfigurationManager.AppSettings["DataConnectionString"]);
var cloudQueueClient = storageAccount.CreateCloudQueueClient();
var queue = cloudQueueClient.GetQueueReference(Guid.NewGuid().ToString());
//ServicePointManager.UseNagleAlgorithm = false; // If you change the nagle algorithm here, the performance will be okay.
queue.CreateIfNotExist();
ServicePointManager.UseNagleAlgorithm = false; // TOO LATE, the queue is already created without 'nagle'
var w = new Stopwatch();
w.Start();
for (int i = 0; i < 50;i++ )
{
Console.WriteLine("nr {0}",i);
queue.AddMessage(new CloudQueueMessage("hello "+i));
}
w.Stop();
Console.WriteLine("elapsed: {0}", w.ElapsedMilliseconds);
queue.Delete();
app.config ファイルを使用して ServicePointManager を構成する Sandrino から提案されたソリューションには、アプリケーションの起動時に ServicePointManager が初期化されるという利点があるため、時間の依存性について心配する必要はありません。