我遇到过这样一种情况:在一组特定的服务器上,简单的.net fibonniacci代码速度较慢,唯一明显不同的是CPU。AMD皓龙处理器6276 - 11秒英特尔至强XPU E7 - 4850 -7秒
代码是为x86和使用.NET Framework4.0编写的。两者之间的-Clock速度是相似的,事实上,PassMark基准给出了AMD的高for分数。-Have在场中的其他AMD服务器上尝试了这一方法,但速度较慢。-Even我本地的I7机器运行代码的速度更快。
Fibonnacci代码:
class Program
{
static void Main(string[] args)
{
const int ITERATIONS = 10000;
const int FIBONACCI = 100000;
var watch = new Stopwatch();
watch.Start();
DoFibonnacci(ITERATIONS, FIBONACCI);
watch.Stop();
Console.WriteLine("Total fibonacci time: {0}ms", watch.ElapsedMilliseconds);
Console.ReadLine();
}
private static void DoFibonnacci(int ITERATIONS, int FIBONACCI)
{
for (int i = 0; i < ITERATIONS; i++)
{
Fibonacci(FIBONACCI);
}
}
private static int Fibonacci(int x)
{
var previousValue = -1;
var currentResult = 1;
for (var i = 0; i <= x; ++i)
{
var sum = currentResult + previousValue;
previousValue = currentResult;
currentResult = sum;
}
return currentResult;
}
}有可能发生什么事的想法吗?
发布于 2013-09-25 04:50:02
正如我们在评论中建立的,您可以通过将进程绑定到AMD Opteron机器上的特定处理器来解决此性能狂欢。
受到这个不太切题的问题的启发,我决定看看可能的情况,在这些情况下,单个核心锁定将产生如此大的差异(从11秒到7秒似乎有点极端)。
最合理的答案并不是革命性的:
AMD Opteron系列采用了所谓的NUMA架构的HyperTransport,而不是传统的前端总线,因为你会发现在英特尔的SMP (包括至强4850 )
我的猜测是,这种症状源于NUMA体系结构中的各个节点具有单独的缓存,而不是共享处理器缓存的英特尔CPU。
换句话说,当连续的计算在Opteron上的节点之间移动时,缓存将被刷新,而在SMP体系结构(如至强4850 )中的处理器之间的平衡没有这样的影响,因为缓存是共享的。
在.NET中设置亲和性非常简单,只需选择一个处理器(为了简单起见,让我们选择第一个处理器):
static void Main(string[] args)
{
Console.WriteLine(Environment.ProcessorCount);
Console.Read();
//An AffinityMask of 0x0001 will make sure the process is always pinned to processer 0
Process thisProcess = Process.GetCurrentProcess();
thisProcess.ProcessorAffinity = (IntPtr)0x0001;
const int ITERATIONS = 10000;
const int FIBONACCI = 100000;
var watch = new Stopwatch();
watch.Start();
DoFibonnacci(ITERATIONS, FIBONACCI);
watch.Stop();
Console.WriteLine("Total fibonacci time: {0}ms", watch.ElapsedMilliseconds);
Console.ReadLine();
}尽管我很确定这在NUMA环境中并不是很聪明。
Windows2008CodePlex有some cool native NUMA functionality,我找到了一个很有前途的codeplex项目,它也有一个.NET包装器:http://multiproc.codeplex.com/
我根本没有资格教你如何使用这项技术,但这应该会为你指明正确的方向。
https://stackoverflow.com/questions/18992140
复制相似问题