在 32 位和 64 位中使用实体框架的性能差异 [英] Performance difference using entity framework in 32 bit and 64 bit

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

问题描述

我在应用程序中使用 .NET Framework 4.0 中的实体框架.

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

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

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

专门为 x86(而不是以前的任何 CPU)编译应用程序,应用程序恢复到与操作系统升级前大致相同的 CPU 使用率.

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

之前运行了一些预热代码,因此不会测量第一次创建上下文和第一次运行查询的开销.这些情况对我的应用程序来说不是很有趣,因为它是一个长时间运行的应用程序

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();

上面的代码为 x86 或 x64 编译(任何 CPU 都给出与 x64 相同的结果)并在 Windows 7 64 位机器上运行.(数据库在不同的机器上运行)

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)

在 x86s 方面提供 12% 的性能差异.IE.如果 x86 版本每秒运行 100 个查询,那么 x64 版本每秒运行 88 个查询.

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.

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

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

有什么方法可以让我在 64 位版本中获得与 32 位版本相同的性能吗?

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

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

该应用程序通常作为 Windows 服务运行,但在测量时,它作为普通 Windows 应用程序 (WPF) 运行

推荐答案

就我而言,我使用 asp.net 和 x86,因为内存使用量低于 2gb.x64 将使内存使用量翻倍,但您可以分配超过 2GB.这是一个类似的问题:x64 与 x86 性能注意事项 .Net

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 位中使用实体框架的性能差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆