与 simplerepository 相比,使用 activerecord 的 Subsonic linq 速度非常慢
有人知道为什么在使用活动记录查询时 linq 查询比使用 simplerepository 查询慢大约 6 倍吗? 下面的代码运行速度比我使用简单存储库查询数据时慢 6 倍。此代码在循环中执行 1000 次
提前致谢
string ret = "";
// if (plan == null)
{
plan =VOUCHER_PLAN.SingleOrDefault(x => x.TENDER_TYPE == tenderType);
}
if (plan == null)
throw new InvalidOperationException("voucher type does not exist." + tenderType);
seq = plan.VOUCHER_SEQUENCES.First();
int i = seq.CURRENT_NUMBER;
seq.CURRENT_NUMBER += seq.STEP;
seq.Save();
Anyone know anything about why linq queries are about 6 times slower when querying using active record vs simplerepository?
The below code runs 6 times slower than when i query the data using a simple repository. This code is executed 1000 times in a loop
Thanks in advance
string ret = "";
// if (plan == null)
{
plan =VOUCHER_PLAN.SingleOrDefault(x => x.TENDER_TYPE == tenderType);
}
if (plan == null)
throw new InvalidOperationException("voucher type does not exist." + tenderType);
seq = plan.VOUCHER_SEQUENCES.First();
int i = seq.CURRENT_NUMBER;
seq.CURRENT_NUMBER += seq.STEP;
seq.Save();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我们对此进行了一些分析,发现 SubSonic 的 record.SingleOrDefault(x=>x.id=someval) 比通过 CodingHorror 执行的相同查询慢 20 倍。在这里记录:https://github.com/subsonic/SubSonic-3.0/issues/258 。
探查器在 ExecutionBuilder.cs 中指出了这一点:
令人失望,因为我真的很喜欢 SubSonic/Linq。
最后我们放弃了,我写了这个 - http://www.toptensoftware.com/petapoco。移植后,我们的负载测试显示每秒请求数上升,CPU 负载从大约 80% 下降到 5%。
We did some profiling on this and found SubSonic's record.SingleOrDefault(x=>x.id=someval) to be up to 20x slower than the same query done through CodingHorror. Logged it here: https://github.com/subsonic/SubSonic-3.0/issues/258.
The profiler pointed at this in ExecutionBuilder.cs:
Disappointing because I really like SubSonic/Linq.
In the end we gave up and I wrote this - http://www.toptensoftware.com/petapoco. After porting, our load test showed requests per second went up and CPU load dropped from about 80% to 5%.
通过缓存在构造函数/init 过程中创建的数据库实例,我能够在性能上产生巨大的差异。我现在看到的速度大约是 2-3 倍,具体取决于情况和运行情况。
1) 如果您只调用默认构造函数,那么用静态实例替换 _db 的方法就可以正常工作,并且具有相同的速度优势。
2) 我为数据库条目编写了一个小缓存类,并在所有使用“new()”的旧位置从我的 ActiveRecord.tt 文件中调用它。
这是在 ActiveRecord.tt 文件中进行的替换类型:
I was able to make a HUGE difference in performance by caching the database instance it creates in the constructor/init procedures. What I am seeing now is ~2-3x speed up, depending on the situation and the run.
1) The method of just replacing _db with a static instance works fine if you only call the default constructor, and has all the same speed benefits.
2) I have written a little caching class for the DB entries and am calling that from my ActiveRecord.tt file in all the old places where "new()" was used.
This is the type of replacement that was made in the ActiveRecord.tt file:
显然,这对于亚音速来说“不是问题”,尽管他们知道它的存在。它不会被修复。你必须使用蹩脚的批处理查询语法才能得到这个,但没有人会这么做。
我不明白的是,90%的情况都是如此。从表中获取记录列表。它应该是快的,而不是慢的。每个人、任何地方、任何时候都这样做。
亚音速的问题很多。我必须为数据库字段编写缓存=>对象字段查找,因为它们也太慢了。
Apparently this "isn't an issue" with subsonic, though they know it is there. It will NOT be fixed. You have to use a crappy batch query syntax to get this, which no one will.
The thing I don't understand about that is that this is the 90% case. Get a list of records from a table. It should BE the fast one, not the slow one. Everyone does it, everywhere, all the time.
So many problems with subsonic. I had to write caching for the DB field => object field lookups, since they were so damn slow too.