mold icon indicating copy to clipboard operation
mold copied to clipboard

mold is slower than gold linking mongodb

Open igorsol opened this issue 3 years ago • 9 comments

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:

  • without mold (gold is used): 2 min 23 sec
  • with mold: from 3m51s to 4m11s

igorsol avatar Dec 26 '21 18:12 igorsol

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.

igorsol avatar Dec 27 '21 15:12 igorsol

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.

rui314 avatar Dec 28 '21 03:12 rui314

@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

gruenich avatar Dec 30 '21 17:12 gruenich

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.

rui314 avatar Jan 13 '22 05:01 rui314

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?

igorsol avatar Jan 17 '22 17:01 igorsol

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.

rui314 avatar Jan 24 '22 04:01 rui314

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?

ishitatsuyuki avatar Oct 17 '22 02:10 ishitatsuyuki

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.

igorsol avatar Oct 18 '22 12:10 igorsol

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.

rui314 avatar Oct 19 '22 23:10 rui314