多线程环境中的实体框架性能 [英] Entity Framework performance in multithreading environment
问题描述
您好,
我们目前在服务器中使用Entity Framework v3.5来表示业务对象。
服务器部分,行为当从1个客户端调用时(关于性能)。
随着客户的增加,性能变得越来越差。我们决定通过使用JetBrains .Net Profiler调查
,因为Sql Server的分析显示持续时间和读数都很小。
什么.Net个人资料显示,有点惊人。当线程增加时,设置操作
关于主要实体(交易)的参考属性 变得越来越慢。 (Transaction是一个自引用的实体)
例如:
1个线程:
设置BatchReference属性交易实体需要20毫秒。
50个主题:
设置交易实体的BatchReference属性需要600毫秒。
由于在处理期间设置了大量引用,因此服务器总响应时间从
200 ms(1个线程)增加到30秒(导致客户端超时) 当有80~100个线程时。
客户端使用WCF与服务器通信。 (问题是http和net.tcp绑定的重现)
对于每个客户端调用,都会创建一个新的ObjectContext,用于读取 - 写入数据库。
服务器应用程序托管在IIS 7.0上,由一组WCF服务组成。
任何想法为什么会发生这种情况?
您好,
您能否告诉我们您的代码在您所描述的区域?
谢谢,
Cathy Miller
Microsoft在线社区支持
Hello,
we currently use Entity Framework v3.5 in our server to represent business objects.
Server part, behaves well (regarding performance) when called from 1 client.
As clients increase, the performance gets poorer and poorer. We decided to investigate
this, by using JetBrains .Net Profiler, since Sql Server's profiling showed small durations and reads.
What .Net profiler showed, is somehow amazing. When threads increase, set operations
on Reference attributes of main entity (Transaction) become slower and slower. (Transaction is a self referenced entity)
For example:
1 thread :
Setting BatchReference attribute of Transaction Entity takes 20 ms.
50 threads:
Setting BatchReference attribute of Transaction Entity takes 600 ms.
Since a lot of references are set during processing, total server response time grows from
200 ms (1 thread) to 30 seconds (resulting in client to timeout) when having 80 ~ 100 threads.
Clients communicate with server using WCF. (problem is repro for both http and net.tcp bindings)
For each client call a new ObjectContext is created, for reading - writing to the database.
Server application is hosted on IIS 7.0 and is composed of a set of WCF Services.
Any ideas why this happens ?
Hi,
Can you tell us what your code looks like in the area you are describing?
Thank you,
Cathy Miller
Microsoft Online Community Support
这篇关于多线程环境中的实体框架性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!