在某些机器上,clone()/fork()/进程创建速度很慢

发布于 2024-10-25 06:54:18 字数 718 浏览 4 评论 0原文

在我的某些机器上创建新进程非常慢,而在其他机器上则不然。

这些机器都很相似,一些慢速机器与一些快速机器在相同的硬件和内核(2.6.32-26,Ubuntu 10.04)上运行完全相同的工作负载。不涉及进程创建的任务在所有机器上的速度相同。

例如,该程序在受影响的计算机上执行速度慢了约 50 倍:

int main()
{
    int i;
    for (i=0;i<10000;i++)
    {
        int p = fork();
        if (!p) exit(0);
        waitpid(p);
    }
    return 0;
}

什么可能导致任务创建速度慢得多,以及我可以在计算机中查找哪些其他差异?

Edit1:在这些机器上运行 bash 脚本(因为它们产生大量子进程)也非常慢,并且慢速脚本上的 strace 显示了 clone() 内核调用的速度减慢。

Edit2:vmstat 在快机器和慢机器上没有显示任何显着差异。它们都有足够的 RAM 来满足其工作负载,并且不会进行交换。

Edit3:我在 dmesg 中没有看到任何可疑的东西

Edit4:我不确定为什么现在出现在 stackoverflow 上,我不是在问上面的示例程序(只是用它来演示问题) ),但是 Linux 管理/调优,但如果人们认为它属于这里,那就酷了。

Creating new processes is very slow on some of my machines, and not others.

The machines are all similar, and some of the slow machines are running the exact same workloads on the same hardware and kernel (2.6.32-26, Ubuntu 10.04) as some of the fast machines. Tasks that do not involve process creation are the same speeds on all machines.

For example, this program executes ~50 times slower on the affected machines:

int main()
{
    int i;
    for (i=0;i<10000;i++)
    {
        int p = fork();
        if (!p) exit(0);
        waitpid(p);
    }
    return 0;
}

What could be causing task creation to be much slower, and what other differences could I look for in the machines?

Edit1: Running bash scripts (as they spawn a lot of subprocesses) is also very slow on these machines, and strace on the slow scripts shows the slowdown in the clone() kernel call.

Edit2: vmstat doesn't show any significant differences on the fast vs slow machines. They all have more than enough RAM for their workloads and don't go to swap.

Edit3: I don't see anything suspicious in dmesg

Edit4: I'm not sure why this is on stackoverflow now, I'm not asking about the example program above (just using it to demonstrate the problem), but linux administration/tuning, but if people think it belongs here, cool.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

在你怀里撒娇 2024-11-01 06:54:18

我们的应用程序堆栈也遇到了同样的问题,注意到应用程序性能大幅下降,并且 strace 的克隆时间更长。在 18 个节点上使用您的测试程序,我在我们遇到克隆时间缓慢的 3 个节点上重现了您的结果。所有节点都以相同的方式配置,但硬件略有不同。我们检查了 BIOS、vmstat、vm.overcommit_memory 并更换了 RAM,但没有任何改善。然后,我们将驱动器移至更新的硬件,问题得到解决。

CentOS 5.9
2.6.18-348.1.1.el5 #1 SMP 1 月 22 日星期二 16:19:19 EST 2013 x86_64 x86_64 x86_64 GNU/Linux

“坏”和“好”lspci:

$ diff ../bad_lspci_sort ../good_lspci_sort 
< Ethernet controller: Intel Corporation 82579LM Gigabit Network Connection (rev 05)
> Ethernet controller: Intel Corporation 82574L Gigabit Network Connection

< Host bridge: Intel Corporation Xeon E3-1200 Processor Family DRAM Controller (rev 09)
> Host bridge: Intel Corporation Xeon E3-1200 v2/Ivy Bridge DRAM Controller (rev 09)

< ISA bridge: Intel Corporation C204 Chipset Family LPC Controller (rev 05)
> ISA bridge: Intel Corporation C202 Chipset Family LPC Controller (rev 05)

< PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 6 (rev b5)
> PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 7 (rev b5)

< VGA compatible controller: Matrox Electronics Systems Ltd. MGA G200e [Pilot] ServerEngines (SEP1) (rev 04)
> VGA compatible controller: Matrox Electronics Systems Ltd. MGA G200eW WPCM450 (rev 0a)

We experienced the same issue with our application stack, noticing massive degradation in application performance and longer clone times with strace. Using your test program across 18 nodes, I reproduced your results on the same 3 we were experiencing slow clone times with. All nodes were provisioned the same way, but with slightly different hardware. We checked the BIOS, vmstat, vm.overcommit_memory and replaced the RAM with no improvement. We then moved our drives to updated hardware and the issue was resolved.

CentOS 5.9
2.6.18-348.1.1.el5 #1 SMP Tue Jan 22 16:19:19 EST 2013 x86_64 x86_64 x86_64 GNU/Linux

"bad" and "good" lspci:

$ diff ../bad_lspci_sort ../good_lspci_sort 
< Ethernet controller: Intel Corporation 82579LM Gigabit Network Connection (rev 05)
> Ethernet controller: Intel Corporation 82574L Gigabit Network Connection

< Host bridge: Intel Corporation Xeon E3-1200 Processor Family DRAM Controller (rev 09)
> Host bridge: Intel Corporation Xeon E3-1200 v2/Ivy Bridge DRAM Controller (rev 09)

< ISA bridge: Intel Corporation C204 Chipset Family LPC Controller (rev 05)
> ISA bridge: Intel Corporation C202 Chipset Family LPC Controller (rev 05)

< PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 6 (rev b5)
> PCI bridge: Intel Corporation 6 Series/C200 Series Chipset Family PCI Express Root Port 7 (rev b5)

< VGA compatible controller: Matrox Electronics Systems Ltd. MGA G200e [Pilot] ServerEngines (SEP1) (rev 04)
> VGA compatible controller: Matrox Electronics Systems Ltd. MGA G200eW WPCM450 (rev 0a)
病毒体 2024-11-01 06:54:18

我可能会首先使用 strace 来查看正在运行哪些系统调用,以及缓慢的系统调用挂在哪里。
我也很好奇你在这里如何使用 waitpid() 。在我的系统上, waitpid 的签名是

pid_t waitpid(pid_t pid, int *status, int options);

它看起来像是您正在使用 wait(),但传入子进程的 pid 而不是 int “status”,它具有您想要测试的状态标志的 OR为了。我预计,如果 PID 最终被解释为状态掩码,这可能会导致一些奇怪的事情发生。

I might start by using strace to see what system calls are being run, and where the slow ones hang.
I'm also curious as to how you're using waitpid() here. On my systems, the signature for waitpid is

pid_t waitpid(pid_t pid, int *status, int options);

It sort of looks like you're using wait(), but passing in the pid of the child process instead of an int "status" that has an OR of the status flags you want to test for. That could cause some strange things to happen, I would expect, if the PID ended up being interpreted as a status mask.

篱下浅笙歌 2024-11-01 06:54:18

需要注意的差异是内核(参数、设备驱动程序、活动模块)和硬件(CPU 版本、CPU 数量、内存配置、外围设备)。

另外:机器在重新启动/重新启动后会改变行为吗?

编辑:

低性能可能与(虚拟)内存层次结构有关。这个层次结构非常复杂,这种复杂性可能会导致奇怪的效果。在从 TLB 到数据缓存再到主内存的过程中,可能会发生奇怪的冲突。这些可能是由不同机器的内核的内存布局略有不同引起的,或者是因为内存层次结构(硬件)实际上略有不同。

当然可能还有其他原因,奇怪的外设(生成中断),不同的工作负载(例如活动进程的数量),...

如果您能解决这个问题,请分享结果!谢谢。

Differences to look at are the kernel (parameters, device drivers, active modules) and the hardware (cpu version, number of cpus, memory configuration, peripheral devices).

Also: do machines change behavior after a reboot/power cycle?

EDIT:

The low performance is probably related to the (virtual) memory hierarchy. This hierarchy is very complex, and this complexity can lead to strange effects. Somewhere on the way from TLB to data caches to main memory strange conflicts may occur. These can be caused by a slightly different memory layout of the kernels of the different machines, or because the memory hierarchy (hardware) is actually slightly different.

Of course there could be other reasons, a strange peripheral (generating interrupts), a different workload (e.g. number of active processes), ...

If you can solve this problem, please share the results! Thanks.

凑诗 2024-11-01 06:54:18

您是否检查过 BIOS 配置,以防 CPU 缓存被禁用,或者电源配置混乱,或者某些系统过热,或者某些内存降频...

Have you checked the BIOS configuration, in case you have the CPU caches disabled, or the power configuration messed up, or some systems are overheating, or some memory is underclocked...

[浮城] 2024-11-01 06:54:18

所有系统的 /sbin/sysctl vm.overcommit_memory 值是否相同?如果不是,那就可以解释这种差异。

允许过度使用将使 fork() 更快,但这意味着新分配的页面不会得到 RAM 或交换的支持。如果/当你触摸一个无支持的页面时,操作系统必须找到它的支持——如果找不到,进程就会被终止。如果子进程所做的只是 exec()(就像在 system() 调用中发生的那样),那么这不是问题,因为所有这些未支持的页面都会被丢弃;但是,这可能会给 fork() 的其他用户带来严重问题。

Are the values of /sbin/sysctl vm.overcommit_memory the same for all the systems? If not, that could explain the difference.

Allowing overcommitment will make fork() much faster, but it means newly-allocated pages won't be backed by RAM or swap. If/when you touch an unbacked page, the OS has to find backing for it--and if it can't, the process gets killed. This isn't a problem if all the child does is exec(), as happens in a system() call, since all those unbacked pages are discarded; however, it could lead to serious problems for other users of fork().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文