ruby net::http response is too slow in fly.

hello.
I want fetch google certificates by net http client in ruby. This is below code.

CERTS_URI = 'https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com'
res = Net::HTTP.get_response(URI(CERTS_URI))

Though simple request is, response is too slow only when my app is deployed to fly. The time is about 2 minutes. Sometimes, I can not get response by Timeout Failure.

But, when the app is deployed to heroku, I get response in less than 1s.

I do not know why that happens. Is this fly.io problem?

This is my toml file.

# fly.toml file generated for XXXX on 2022-08-12T14:21:16+09:00

app = "XXXX"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[build]
  [build.args]
    BUNDLER_VERSION = "2.3.20"
    NODE_VERSION = "14"
    RUBY_VERSION = "3.1.1"


[deploy]
  release_command = "bundle exec rails db:migrate"

[env]
  PORT = "8080"
  SERVER_COMMAND = "bundle exec puma -C config/puma.rb"

[experimental]
  allowed_public_ports = []
  auto_rollback = true
[processes]
web = "bundle exec puma -C config/puma.rb"
worker = "bundle exec sidekiq -C config/sidekiq.yml"

[[services]]
  http_checks = []
  internal_port = 8080
  processes = ["web"]
  protocol = "tcp"
  script_checks = []
  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

[[statics]]
  guest_path = "/app/public"
  url_prefix = "/"

It’s probably a DNS issue, we’ve seen sometimes a similar thing, with some API endpoints but it got resolved by itself.

Might be able to fix it by using resolv-replace gem.

1 Like

I’m not seeing multi-second response times on a Fly.io machine at IAD.

Test:

require 'net/http'
require 'benchmark'

CERTS_URI = 'https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com'

Benchmark.bm( 20 ) do |bm|
  bm.report('response') { Net::HTTP.get_response(URI(CERTS_URI)) }
end

Results:

                           user     system      total        real
response               0.020106   0.000046   0.020152 (  0.027241)
1 Like

Thank you for your reply. I will try it.

Thank you for your reply.
I tried putting a machine at iad. yes, i got the result close to your result. But, in case of my region, nrt(Tokyo Japan), a result is below.

response                   user     system      total        real
                      0.031116   0.009922   0.041038 (240.341866)