

How IQueryable and Take can kill your Sitecore Solution
source link: https://blog.coates.dk/2020/05/18/how-iqueryable-and-take-can-kill-your-website/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How IQueryable and Take can kill your Sitecore Solution
We had a solution that had serve performance issue when it got a lot of visitors. Sitecore was casting the following exception and SolR had a similar errors in its logs:
Unable to read data from the transport connection: The connection was closed
We identified that the problem was caused by hitting the network bandwidth in Azure!
Yes, there were a lot of visitors, but enough to hit the bandwidth limit, the customer upgraded the plan to get more network bandwidth, but still the issues continued.
But what could cause this issue?
I started to review the SolR implementation and found the issue quite quickly.
return IQueryable<Result>
.Where(result => result.Date < DateTime.UtcNow)
.OrderByDescending(result => result.Date)
.GetResults()
.Take(count)
.ToList();
The Take() was made after GetResults() was called, so the entire data set is returned to Sitecore from SolR, then the take was applied to get the top 5 results.
This simple mistake was what caused all the network and performance issues.
Solution
return IQueryable<Result>
.Where(result => result.Date < DateTime.UtcNow)
.OrderByDescending(result => result.Date)
.Take(count)
.GetResults()
.ToList();
It was a simple fix (in 150+ places) to move the Take before GetResults!
This is why I believe that you should always Introduce a (SolR) Sitecore Search Abstraction, please read my post on this very subject, instead of returning the IQueryable interface.
Hope this helps, Alan
Recommend
-
12
.NET深入解析LINQ框架(四:IQueryable、IQueryProvider接口详解) ...
-
7
How to kill Sitecore – whilst installing an update package Leave a reply ...
-
6
How SQL Index Fragmentation will kill Sitecore’s Performance
-
6
IQueryable的简单封装 前两天在园子上看到一个问题 半年前我也考虑过这些问题,但由于这样那样的问题,没有尝试去解决. 后来公司用上了 abp vnext ,然后有一部分代码可以这样写 protected override IQue...
-
14
How do I set a custom property of an Entity type in LINQ to Entities query and still return an IQueryable < T & gt; advertisements I ha...
-
4
.NET Collections – IEnumerable, IQueryable, ICollection Posted by Code Maze | Updated Date Nov 1, 2021 |
-
7
「译」LINQ: Building an IQueryable Provider - Part IX: Removing redundant subqueries2016-03-04 | 刘文俊英文原文是Matt Warren
-
7
「译」LINQ: Building an IQueryable Provider - Part V: Improved Column binding2016-02-04 | 刘文俊英文原文是Matt Warren发表在MSDN...
-
6
「译」LINQ: Building an IQueryable Provider - Part III: Local variable references2016-02-01 | 刘文俊英文原文是Matt Warren发表在M...
-
6
「译」LINQ: Building an IQueryable Provider - Part VI: Nested queries2016-02-13 | 刘文俊英文原文是Matt Warren发表在MSDN Blogs的...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK