性能差异使用实体框架在32位和64位

性能差异使用实体框架在32位和64位

本文介绍了性能差异使用实体框架在32位和64位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中使用.NET Framework 4.0中的Entity Framework。



将操作系统升级到64位版本后,我注意到更高的CPU使用率应用程序。



专门为x86(而不是像以前那样的任何CPU)编译应用程序,应用程序恢复到与操作系统升级前相同的CPU使用情况。 p>

我使用以下代码进行了一些更详细的测量



一些预热代码在之前运行首次创建上下文并首次运行查询的开销未被测量。这种情况对于我的应用程序来说并不是非常有趣,因为它是一个长时间运行的应用程序

  var s = Stopwatch.StartNew ); 
var name =name; (var i = 0; i using(var context = new MyDatabaseEntities()){
var entity = context.MyEntities.FirstOrDefault(e => e.Name == name);
}
}
s.Stop();

上面的代码编译为x86或x64(任何CPU提供与x64相同的结果)并运行在Windows 7 64位机器上。 (数据库在不同的计算机上运行)



x86中的性能差异为12%。即如果x86版本每秒运行100个查询,那么x64版本每秒运行88次查询。



这是.NET上32位和64位之间的预期/正常性能差异?



有没有什么可以做的,以获得与32位版本64位版本相同的性能?



在上面的例子中,MyEntity是一个非常简单的实体,具有Id和名称



通常应用程序作为Windows服务运行,但是当测量时,它作为正常的Windows应用程序(WPF)运行

解决方案

在我的情况下,我使用asp.net和x86因为内存使用量低于2gb。 x64将双重记忆使用,但您可以分配超过2GB。这是一个类似的问题:
x64 vs x86性能注意事项.Net


I'm using Entity Framework in .NET Framework 4.0 in an application.

After upgrading the operating system to a 64 bit version I noticed higher CPU usage in the application.

Compiling the application specifically for x86 (instead of any CPU as before) the application got back to about the same CPU usage as before the operating system upgrade.

I did some more detailed measuring using the below code

Some warm-up code is run before so that the overhead of creating the context the first time and running the query for the first time is not measured. Those cases are not very interesting for my application since it's a long running application

var s = Stopwatch.StartNew();
var name = "name";
for (var i = 0; i < 100000; ++i) {
    using (var context = new MyDatabaseEntities()) {
        var entity = context.MyEntities.FirstOrDefault(e => e.Name == name);
    }
}
s.Stop();

The code above compiled either for x86 or x64 (Any CPU gives the same results as x64) and run on a Windows 7 64 bit machine. (The database is running on a different machine)

Gives a performance difference of 12% in x86s favor. I.e. if the x86 version runs 100 queries per second, then the x64 version runs 88 queries per second.

Is this an expected/normal performance difference between 32bit and 64bit on .NET?

Is there something I can do to get the same performance in the 64 bit version as in the 32 bit version?

In the above example the MyEntity is a very simple entity with an Id and a Name

Normally the application is run as a windows service, but when measuring, it was run as a normal windows application (WPF)

解决方案

In my case i use asp.net and x86 because of the memory usage is lower than 2gb. The x64 will double memorou usage, but you can allocate over 2gb. Here is a similar question:x64 vs x86 Performance Considerations .Net

这篇关于性能差异使用实体框架在32位和64位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 19:26