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

Loading / importing / require 'gitlab' very slow #633

Closed
ltickett opened this issue Jan 31, 2022 · 5 comments
Closed

Loading / importing / require 'gitlab' very slow #633

ltickett opened this issue Jan 31, 2022 · 5 comments

Comments

@ltickett
Copy link
Contributor

On my development machine it's fine, but when running in CI it takes about 20 minutes to complete the single line of code.

My script starts:

#!/usr/bin/env ruby
# frozen_string_literal: true

puts 'a'
require 'fileutils'
puts 'b'
require 'gitlab'
puts 'c'

a and b get output to the console, but it hangs waiting for c (eventually completing after roughly 20 minutes).

I'm using docker image ruby:2.7.5-slim but tried a few other to no avail.

I've tried a bunch of different mechanisms for executing the ruby script:

1.
ruby grab_readmes.rb
2.
chmod +x grab_readmes.rb
./grab_readmes.rb
3.
bundle exec ruby grab_readmes.rb

None seem to make any difference.

Any bright ideas what's going on or how I can troubleshoot?

Thanks!

@ltickett
Copy link
Contributor Author

I found some output which might help when running ruby -d

Here's the output from the "fast" development machine:

lee@cc-gdk-2:~/grab_readmes$ ruby -d grab_readmes.rb
Exception `LoadError' at /home/lee/.asdf/installs/ruby/2.7.5/lib/ruby/2.7.0/rubygems.rb:1427 - cannot load such file -- rubygems/defaults/operating_system
Exception `LoadError' at /home/lee/.asdf/installs/ruby/2.7.5/lib/ruby/2.7.0/rubygems.rb:1435 - cannot load such file -- rubygems/defaults/ruby
Exception `LoadError' at /home/lee/.asdf/installs/ruby/2.7.5/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83 - cannot load such file -- gitlab
Exception `NameError' at /home/lee/.asdf/installs/ruby/2.7.5/lib/ruby/2.7.0/psych/class_loader.rb:68 - uninitialized constant BigDecimal
Exception `NameError' at /home/lee/.asdf/installs/ruby/2.7.5/lib/ruby/2.7.0/psych/class_loader.rb:68 - uninitialized constant Date
Did you mean?  Data
Exception `NameError' at /home/lee/.asdf/installs/ruby/2.7.5/lib/ruby/2.7.0/psych/class_loader.rb:68 - uninitialized constant DateTime

And from the "slow" CI runner:

$ ruby -d grab_readmes.rb
Exception `LoadError' at /usr/local/lib/ruby/2.7.0/rubygems.rb:1427 - cannot load such file -- rubygems/defaults/operating_system
Exception `LoadError' at /usr/local/lib/ruby/2.7.0/rubygems.rb:1435 - cannot load such file -- rubygems/defaults/ruby
Exception `LoadError' at /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83 - cannot load such file -- gitlab
Exception `LoadError' at /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:160 - cannot load such file -- gitlab
/usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require': cannot load such file -- gitlab (LoadError)
	from /usr/local/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
	from grab_readmes.rb:7:in `<main>'

@ltickett
Copy link
Contributor Author

I'm new to ruby and maybe doing something wrong...

Running gem install gitlab instead of bundle install seems to do the trick 🤞

@ltickett
Copy link
Contributor Author

The plot thickens...

It seems the output from the ruby script isn't an accurate reflection of what code is being/has been executed...

Watch this space :/

@ltickett
Copy link
Contributor Author

Turns out it was a DNS issue.

Weird though as dig shows DNS resolution only takes 8ms... but adding a static mapping to /etc/hosts reduced the execution time from 20mins to 20secs.

Is there anyway to debug what might be happening with DNS resolution in ruby to cause this?

@NARKOZ
Copy link
Owner

NARKOZ commented Mar 23, 2022

Is there anyway to debug what might be happening with DNS resolution in ruby to cause this?

You can use env variable GITLAB_API_HTTPARTY_OPTIONS with value {debug_output: $stdout}

@NARKOZ NARKOZ closed this as completed Mar 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants