3

我正在做一个非常简单的测试,队列指向真正的 Azure 存储,我不知道为什么,从我的计算机执行测试比将工作角色部署到天蓝色并在那里执行要快得多。我在本地测试时没有使用开发存储,我的 .cscfg 具有到真实存储的连接字符串。

存储帐户和角色位于同一个关联组中。

测试是一个 Web 角色和一个工作者角色。该页面告诉工人要做什么测试,工人做它并返回消耗的时间。此特定测试使用 32 条消息的批次测量从 Azure 队列中获取 1000 条消息需要多长时间。首先,在将应用程序部署到 Azure 并从那里运行之后,我使用 VS 测试运行调试。

结果是:

  • 从我的电脑:34805.6495 毫秒。
  • 来自 Azure 角色:7956828.2851 毫秒。

这可能意味着从 Azure 外部访问队列比在内部访问队列更快,这没有任何意义。

我正在这样测试:

    private TestResult InQueueScopeDo(String test, Guid id, Int64 itemCount)
    {
        CloudStorageAccount account = CloudStorageAccount.Parse(_connectionString);
        CloudQueueClient client = account.CreateCloudQueueClient();
        CloudQueue queue = client.GetQueueReference(Guid.NewGuid().ToString());

        try
        {
            queue.Create();
            PreTestExecute(itemCount, queue);

            List<Int64> times = new List<Int64>();
            Stopwatch sw = new Stopwatch();
            for (Int64 i = 0; i < itemCount; i++)
            {
                sw.Start();
                Boolean valid = ItemTest(i, itemCount, queue);
                sw.Stop();
                if (valid)
                    times.Add(sw.ElapsedTicks);
                sw.Reset();
            }

            return new TestResult(id, test + " with " + itemCount.ToString() + " elements", TimeSpan.FromTicks(times.Min()).TotalMilliseconds,
                                                 TimeSpan.FromTicks(times.Max()).TotalMilliseconds,
                                                 TimeSpan.FromTicks((Int64)Math.Round(times.Average())).TotalMilliseconds);
        }
        finally
        {
            queue.Delete();
        }

        return null;
    }

PreTestExecute1000 个项目放入队列中,每个项目有 2048 个字节。

这就是ItemTest此测试方法中发生的情况:

    Boolean done = false;
    public override bool ItemTest(long itemCurrent, long itemCount, CloudQueue queue)
    {
        if (done)
            return false;

        CloudQueueMessage[] messages = null;

        while ((messages = queue.GetMessages((Int32)itemCount).ToArray()).Any())
        {
            foreach (var m in messages)
                queue.DeleteMessage(m);
        }

        done = true;

        return true;
    }

我没有做错什么,相同的代码,相同的连接字符串,我得到了这些结果。

任何的想法?

更新:

问题似乎出在我计算它的方式上。

我已经替换了times.Add(sw.ElapsedTicks);fortimes.Add(sw.ElapsedMilliseconds);和这个块:

return new TestResult(id, test + " with " + itemCount.ToString() + " elements",
TimeSpan.FromTicks(times.Min()).TotalMilliseconds,                             
TimeSpan.FromTicks(times.Max()).TotalMilliseconds,     
TimeSpan.FromTicks((Int64)Math.Round(times.Average())).TotalMilliseconds);

对于这个:

return new TestResult(id, test + " with " + itemCount.ToString() + " elements", 
times.Min(),times.Max(),times.Average());

现在结果是相似的,所以显然在处理精度或其他方面存在差异。我稍后会研究这个。

4

2 回答 2

2

The problem apparently was a issue with different nature of the StopWatch and TimeSpan ticks, as discussed here.

Stopwatch.ElapsedTicks Property

Stopwatch ticks are different from DateTime.Ticks. Each tick in the DateTime.Ticks value represents one 100-nanosecond interval. Each tick in the ElapsedTicks value represents the time interval equal to 1 second divided by the Frequency.

于 2011-05-03T14:27:24.593 回答
1

How is your CPU utilization? Is this possible that your code is spiking the CPU and your workstation is much faster than your Azure node?

于 2011-04-27T21:00:22.040 回答