我做在我们现有的项目EWS的应用可能被写入大量使用MAPI的,我发现东西有点研究扰乱LoadPropertiesForItems()方法的性能。交易所Web服务托管API - 使用ItemView.Offset为FindItems()点击LoadPropertiesForItems方法的性能
考虑这样的场景:
- 我们有10000(万)消息在收件箱文件夹
- 我们希望得到大约30的每封邮件的属性,看看它们是否符合我们的条件作进一步处理
- 消息从服务器100级的消息
所以包取回,代码如下:
ItemView itemsView = new ItemView(100);
PropertySet properties = new PropertySet();
properties.Add(EmailMessageSchema.From);
/*
add all necessary properties...
*/
properties.Add(EmailMessageSchema.Sensitivity);
FindItemsResults<Item> findResults;
List<EmailMessage> list = new List<EmailMessage>();
do
{
findResults = folder.FindItems(itemsView);
_service.LoadPropertiesForItems(findResults, properties);
foreach (Item it in findResults)
{
... do something with every items
}
if (findResults.NextPageOffset.HasValue)
{
itemsView.Offset = findResults.NextPageOffset.Value;
}
}while(findResults.MoreAvailable);
而问题是,itemsView.Offset财产的每个增量使得LoadPropertiesForItems方法更长的时间来执行。对于前几次迭代来说,它不是很明显,但是大约30次的循环使得通话时间从1秒增加到8秒或更多秒。内存分配遇到了导致内存异常的物理限制。
我敢肯定,因为我改变一点点,一个代码我的问题“与失调相关”:
itemsView = new ItemView(100, offset, OffsetBasePoint.Beginning);
...rest of loop
if (findResults.NextPageOffset.HasValue)
{
offset = findResults.NextPageOffset.Value;
}
,我操纵offset变量以这种方式(循环之外声明),我在第一次迭代之后,将它的值设置为4500,并且在第一次迭代之后将其值设置为调试模式。我根据我的怀疑,首先调用LoadPropertiesForItems花费很长时间执行,第二次调用(offset = 100)非常快。
任何人都可以证实,也许提出一些解决方案?
当然,我可以做我的工作,而无需使用偏移,但为什么要我? :)
如此看来,最好的解决办法是让消息的块,对他们的例如100,对它们进行处理,将其标记为“已处理”,并得到另一块等等。感谢您的确认。 – grapkulec 2011-04-28 08:33:41