且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

多线程环境中的实体框架性能

更新时间:2022-10-16 10:13:10

您好,


您能否告诉我们您的代码在您所描述的区域?


谢谢,


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