Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add libgmp for faster Integer calculations. #266

Merged
merged 2 commits into from Mar 1, 2019

Conversation

@lsb
Copy link
Contributor

commented Feb 27, 2019

I was wondering why some large integer multiplications were taking a while, so I ran

$ docker run ruby:2.6 ruby -e 'puts Integer::GMP_VERSION'
-e:1:in `<main>': uninitialized constant Integer::GMP_VERSION (NameError)

and found that GMP wasn't included in the default images. Building these images gives me

$ docker run ruby:gmp-2.6 ruby -e 'puts Integer::GMP_VERSION'
GMP 6.1.2

For significantly large integers (on my machine) GMP is over 50x faster than Ruby's fallback Integer methods: https://github.com/ruby/ruby/blob/a2eb04f52dccb9b42404f8b133acb36b577e3b54/bignum.c#L2527

@lsb

This comment was marked as resolved.

Copy link
Contributor Author

commented Feb 27, 2019

(The two build failures look like RubyGems 502s?

testing ruby:2.4-jessie
	'utc' [1/9]...passed
	'cve-2014--shellshock' [2/9]...passed
	'no-hard-coded-passwords' [3/9]...passed
	'override-cmd' [4/9]...passed
	'ruby-hello-world' [5/9]...passed
	'ruby-standard-libs' [6/9]...passed
	'ruby-gems' [7/9]...skipping activesupport due to required Ruby version: >= 2.5.0 (vs 2.4.5)
/usr/local/lib/ruby/2.4.0/open-uri.rb:363:in `open_http': 502 Bad Gateway (OpenURI::HTTPError)
	from /usr/local/lib/ruby/2.4.0/open-uri.rb:741:in `buffer_open'
	from /usr/local/lib/ruby/2.4.0/open-uri.rb:212:in `block in open_loop'
	from /usr/local/lib/ruby/2.4.0/open-uri.rb:210:in `catch'
	from /usr/local/lib/ruby/2.4.0/open-uri.rb:210:in `open_loop'
	from /usr/local/lib/ruby/2.4.0/open-uri.rb:151:in `open_uri'
	from /usr/local/lib/ruby/2.4.0/open-uri.rb:721:in `open'
	from /usr/local/lib/ruby/2.4.0/open-uri.rb:35:in `open'
	from -e:24:in `block in <main>'
	from -e:20:in `each'
	from -e:20:in `<main>'
failed
	'ruby-bundler' [8/9]...passed
	'ruby-nonroot' [9/9]...passed
The command "(
  set -Eeuo pipefail
  set -x
  travis_retry docker build -t "$image" .
  ~/official-images/test/run.sh "$image"
)
" exited with 1.

and

testing ruby:2.3-jessie
	'utc' [1/9]...passed
	'cve-2014--shellshock' [2/9]...passed
	'no-hard-coded-passwords' [3/9]...passed
	'override-cmd' [4/9]...passed
	'ruby-hello-world' [5/9]...passed
	'ruby-standard-libs' [6/9]...passed
	'ruby-gems' [7/9].../usr/local/lib/ruby/2.3.0/open-uri.rb:359:in `open_http': 502 Bad Gateway (OpenURI::HTTPError)
	from /usr/local/lib/ruby/2.3.0/open-uri.rb:737:in `buffer_open'
	from /usr/local/lib/ruby/2.3.0/open-uri.rb:212:in `block in open_loop'
	from /usr/local/lib/ruby/2.3.0/open-uri.rb:210:in `catch'
	from /usr/local/lib/ruby/2.3.0/open-uri.rb:210:in `open_loop'
	from /usr/local/lib/ruby/2.3.0/open-uri.rb:151:in `open_uri'
	from /usr/local/lib/ruby/2.3.0/open-uri.rb:717:in `open'
	from /usr/local/lib/ruby/2.3.0/open-uri.rb:35:in `open'
	from -e:24:in `block in <main>'
	from -e:20:in `each'
	from -e:20:in `<main>'
failed
	'ruby-bundler' [8/9]...passed
	'ruby-nonroot' [9/9]...passed
The command "(
  set -Eeuo pipefail
  set -x
  travis_retry docker build -t "$image" .
  ~/official-images/test/run.sh "$image"
)
" exited with 1.
@tianon

This comment has been minimized.

Copy link
Member

commented Mar 1, 2019

Nice catch; I dug in and found ruby/ruby@83a0709, which led me to wonder if this was actually applicable enough to add to buildpack-deps which led me to find:

... and thus file docker-library/buildpack-deps#92. 👍

@tianon

This comment has been minimized.

Copy link
Member

commented Mar 1, 2019

(but this is still applicable for -slim and -alpine variants, so I'll be pushing an update shortly after I finish a little testing to make sure it works on each)

@tianon tianon merged commit f2bdb4a into docker-library:master Mar 1, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

tianon added a commit to infosiftr/stackbrew that referenced this pull request Mar 1, 2019

Update docker-library images
- `buildpack-deps`: `libgmp-dev` (docker-library/buildpack-deps#92)
- `docker`: 18.09.3
- `ghost`: 2.16.2
- `mariadb`: 10.4.3
- `mongo`: 3.6.11
- `openjdk`: 13-ea+10
- `rabbitmq`: 3.7.13-rc.2, `RABBITMQ_VM_MEMORY_HIGH_WATERMARK=0` valid (docker-library/rabbitmq#322)
- `ruby`: `libgmp` (docker-library/ruby#266)
@abevoelker

This comment has been minimized.

Copy link

commented on eae22dc Mar 2, 2019

I see libgmp3-dev got swapped out for libgmp-dev in the slim images. FWIW I had to install libgmp3-dev on the latest ruby:2.5-slim image to get the nokogiri gem to install correctly.

This comment has been minimized.

Copy link

replied Mar 3, 2019

We ran into same issue, nokogiri could not build it's native extensions (alpine and slim). Error was
/usr/bin/ld: cannot find -lgmp. libgmp3-dev helped on slim, but haven't discovered a solution for alpine yet.

This comment has been minimized.

Copy link

replied Mar 3, 2019

Same problem here with installing spaceship which depends on fastlane which indirectly depends on the unf_ext gem. So more people might run into issues.

This comment has been minimized.

Copy link

replied Mar 3, 2019

I wasn't sure if I was doing something wrong at first, but since others are having the same/similar issue, I opened #267 for this.

This comment was marked as outdated.

Copy link

replied Mar 4, 2019

Hi everyone,

Since this change, with Ruby 2.3, the wkhtmltopdf-binary-edge gem installation fails with a native dependency compilation error.

I had to add the ruby-dev system dependency to fix the problem.

This comment has been minimized.

Copy link

replied Mar 4, 2019

If you came here because of Nokogiri installation is throwing an error:

Installing nokogiri 1.9.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

That's probably because of It seems that gmp-dev somehow didn't make it into the image. It is added to the ruby-builddeps it gets cleaned up by the apk add --no-cache --virtual .ruby-builddeps.

To fix it:

apk add --no-cache gmp-dev

This comment has been minimized.

Copy link
Member Author

replied Mar 4, 2019

Let's move the discussion over to #267 to keep it all in one place.

@maxbrunet

This comment has been minimized.

Copy link

commented Mar 3, 2019

@juusujanar I got the issue with nokogiri on alpine and fixed it by installing gmp-dev.

maxbrunet added a commit to maxbrunet/lofocats_api that referenced this pull request Mar 3, 2019

maxbrunet added a commit to maxbrunet/lofocats_ui that referenced this pull request Mar 3, 2019

maxbrunet added a commit to maxbrunet/lofocats_api that referenced this pull request Mar 3, 2019

maxbrunet added a commit to maxbrunet/lofocats_ui that referenced this pull request Mar 3, 2019

@ALandscheidt

This comment has been minimized.

Copy link

commented Mar 4, 2019

jaro_winkler can't build on ruby:2.4.5-slim-stretch. Add libgmp-dev fixed it.

@springerigor

This comment has been minimized.

Copy link

commented Mar 4, 2019

Since this PR was merged libgmp-dev is removed by apt-get purge command. As a result it is not available during runtime and some Ruby gems depends on it (like well-known nokogiri).

To solve the issue you should install it by yourself (apt get libgmp-dev).

I tested it with Ruby 2.5.3 & Nokogiri 1.8.4 and the described approach solved the issue.

@tianon

This comment has been minimized.

Copy link
Member

commented Mar 4, 2019

See #267 for where this issue is being discussed further.

@docker-library docker-library locked and limited conversation to collaborators Mar 4, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
10 participants
You can’t perform that action at this time.