FreeBSD vs Linux – Why Applications Run Slower

freebsdlinuxperformancetrueos

Update

They don't! At least, not for me.

See my answer.

Original question

According to last year's Phoronix benchmarks, applications on FreeBSD mostly run slower than on Debian (including Stockfish chess engine, Node.js, FLAC encoding and other computational tasks).

Phoronix article itself attributes some of the performance differences to use of Clang instead of GCC compiler. Some other opinions say that use of ZFS makes FreeBSD slower, as ZFS is inherently slower than ext4.

But even purely computational tasks on FreeBSD compiled with GCC8 performed slower than on Linux.

What is the cause of that? Is it inherent to differences between FreeBSD and Linux kernels, might it be caused by worse quality of drivers or is there some other reason?

P.S. To make it more specific, here is a fairly simple purely computational program that runs slower on FreeBSD than on Linux according to Phoronix: m-queens 1.2. Compiled like this:

gcc -o m-queens.bin main.c -O2 -march=native -mtune=native -std=c99 -fopenmp

Since this a multithreaded task that was run on two 20 core CPUs, I suspect the performance difference boils down to how well OS handles multiple threads.

P.P.S. To make it more clear, I am aware that FreeBSD has good networking capabilities and that it is used by Netflix. The question is specifically about computational tasks, like the one above.

P.P.P.S. After installing FreeBSD (TrueOS) on my 6-core desktop alongside Ubuntu and trying to run the queens benchmark myself, I didn't notice any significant difference in multithreaded performance. While Phoronix claims that it ran 39% slower on FreeBSD, in my tests it was only 3.7% slower, which could be attributed to slight difference in compiler version (gcc 7.4 on TrueOS, gcc 7.2 on Ubuntu). I will test more later.

Best Answer

So many downvotes stimulated me to install FreeBSD (TrueOS) on my 6-core desktop computer to test it myself. (NOTE: I do not recommend trying to install TrueOS alongside other operating systems, because this installation wiped one of my hard drives, even though I tried to install it on a USB drive... Not a user-friendly experience.)

As a result, after running some tests from the Phoronix test suite on both Ubuntu and FreeBSD, I couldn't see the “slow applications on FreeBSD” effect. Quite the contrary, some applications ran significantly (10–25%) faster on FreeBSD:

    Test                                    FreeBSD 13        Ubuntu 17
Fhourstones, kpos/s                       16753             13336
m-queens, multithreaded, user time, s     18.08             17.38
7zip 1 GB text file, user time, s         994               1096

As you can see, the only task that performed slower on FreeBSD was multithreaded N queens problem, taking 3.7% more time than on Ubuntu.

Potential pitfalls:

  • gcc on Ubuntu was version 7.2, on FreeBSD – 7.4
  • Ubuntu was running with KDE, FreeBSD in a shell (shouldn't make much difference)
  • Phoronix used 80-thread server, I used 6-thread Intel i5 computer.

In conclusion, when testing OS performance, you should:

  • run benchmarks on your setup yourself instead of trusting results that were obtained by someone else.
  • try to use the same compiler.
  • beware that performance of scripting languages like Perl and Python are not a good indicator of OS performance, since different installations of the interpreters behave differently.
Related Question