rui314 / mold

Mold: A Modern Linker 🦠
MIT License
14.29k stars 471 forks source link

mold is slower than gold linking mongodb #202

Open igorsol opened 2 years ago

igorsol commented 2 years ago

Thanks for fixing #196. Now I can test mold with linking MongoDB binaries.

Environment: Ubuntu 20.04, 8 core intel processor, gcc 9.3.0, mold built from commit 04ad22d326d.

I failed to figure out how to use mold with scons build tool used in MongoDB builds. So I tested it this way:

  1. run MongoDB build with "scons VERBOSE=1 core | tee verbose.txt". VERBOSE option forces scons to print full command lines of build tools.
  2. From verbose.txt I extracted g++ command line used to link 'mongod' binary
  3. Prepended extracted command line with 'mold -run'

Now testing results:

igorsol commented 2 years ago

Later I found that there is -Wl,--no-threads parameter on the generated command line. So I tried to replace it with -Wl,--threads. Result linking time is even longer: 4m 33s. I also tried to add -Wl,--thread-count=8 to the g++ command line but linking time is still 4m 40s.

rui314 commented 2 years ago

Thank you for you report! I have trouble with building mongodb on my machine, so I couldn't reproduce the issue, but I'll try again.

gruenich commented 2 years ago

@igorsol I think you have to specify LINK or SHLINK to set the linker for Scons, see https://scons.org/doc/production/HTML/scons-user/apa.html

rui314 commented 2 years ago

mold seems to be faster than gold on my machine. This is what I tried:

  1. Build mongodb with python3 buildscripts/scons.py VERBOSE=1 install-mongod | tee log to get the command line argument to build build/opt/mongo/db/mongod
  2. Run the same command with different linkers to rebuild mongod

Here is the result:

ld.lld 4.546s
ldmold 3.328s
ld.gold 59.935s

I run the linker commands with taskset 0xffff to simulate a 8-core 16-thread machine.

Are you sure you are using mold? mold leaves its identification string in a .comment section like this:

$ readelf -p .comment build/opt/mongo/db/mongod

String dump of section '.comment':
  [     0]  GCC: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
  [    2a]  GCC: (Ubuntu 10.3.0-1ubuntu1~20.04) 10.3.0
  [    56]  mold 1.0.1 (c3466b90212e7aae10fa0480d90d1ca01875cf88; compatible with GNU ld)

Please double check you are using mold with the above command.

igorsol commented 2 years ago

Yes, I'm sure I use mold. I checked this with readelf command. From your example I see you built mold from commit c3466b902 - I will recheck with this commit. Did you modify linker command to remove -Wl,--no-threads parameter?

rui314 commented 2 years ago

My command line didn't have -Wl,-no-threads.

I wonder what exactly is your command. My link time of mongod is about 2 seconds, but you said it took 4 minutes and 33 seconds. It's very likely that your number includes something that is not linker.

ishitatsuyuki commented 2 years ago

While revisiting this issue https://github.com/rui314/mold/issues/730 comes to mind as a case of threading giving no advantage or even regressions.

Were you running Linux directly on your machine or relied on some kind of virtualization, including but not limited to WSL2?

igorsol commented 2 years ago

In my case that was linux guest in VitualBox on the Windows host. I will try to update my tests with the latest mold version.

rui314 commented 2 years ago

I'm pretty sure that that's a performance issue of VirtualBox and/or Windows. mold is also slow on WSL2. My guess is that the virtual machines on Windows does not scale well for highly multi-threaded applications.