【发布时间】:2013-10-28 07:24:02
【问题描述】:
我有一个工作人员角色,负责处理队列中的项目。它基本上是一个无限循环,将项目从队列中弹出并异步处理。
我有两个配置设置(PollingInterval 和 MessageGetLimit),我希望工作人员角色在更改时能够使用它们(因此不需要重新启动)。
private TimeSpan PollingInterval
{
get
{
return TimeSpan.FromSeconds(Convert.ToInt32(RoleEnvironment.GetConfigurationSettingValue("PollingIntervalSeconds")));
}
}
private int MessageGetLimit
{
get
{
return Convert.ToInt32(RoleEnvironment.GetConfigurationSettingValue("MessageGetLimit"));
}
}
public override void Run()
{
while (true)
{
var messages = queue.GetMessages(MessageGetLimit);
if (messages.Count() > 0)
{
ProcessQueueMessages(messages);
}
else
{
Task.Delay(PollingInterval);
}
}
}
问题:
在高峰时段,while 循环可能每秒运行几次。这意味着它将每天查询配置项多达 100,000 次。
这是有害的还是低效的?
【问题讨论】:
标签: c# .net azure azure-web-roles azure-worker-roles