使用derailed_benchmarks gem的错误请求错误

时间:2016-05-19 10:57:35

标签: ruby-on-rails

我正在尝试使用derailed_benchmark gem来跟踪rails应用中的内存泄漏。

当我运行测试时

USE_SERVER=puma bundle exec derailed exec perf:mem_over_time

测试运行直到内存使用率开始趋于平稳,然后测试引发错误:

RuntimeError: Bad request to "curl 'http://localhost:3000/' -s --fail 2>&1" Response:

我该如何解决这个问题?

输出如下:

perf:mem_over_time
Booting: production
Endpoint: "/"
/Users/Chris/.rvm/gems/ruby-2.2.1@golf_mentor221/gems/derailed_benchmarks-1.3.1/lib/derailed_benchmarks/tasks.rb:72: warning: already initialized constant DERAILED_APP
/Users/Chris/.rvm/gems/ruby-2.2.1@golf_mentor221/gems/derailed_benchmarks-1.3.1/lib/derailed_benchmarks/tasks.rb:23: warning: previous definition of DERAILED_APP was here
Port: 3000
Server: "puma"
Puma 2.16.0 starting...
* Min threads: 0, max threads: 16
* Environment: none
* Listening on tcp://0.0.0.0:3000
PID: 17093
125.01171875
128.15234375
132.0546875
133.5078125
133.68359375
133.8828125
bundler: failed to load command: derailed (/Users/Chris/.rvm/gems/ruby-2.2.1@golf_mentor221/bin/derailed)
RuntimeError: Bad request to "curl 'http://localhost:3000/' -s --fail 2>&1" Response:
""
  /Users/Chris/.rvm/gems/ruby-2.2.1@golf_mentor221/gems/derailed_benchmarks-1.3.1/lib/derailed_benchmarks/tasks.rb:85:in `call_app'
  /Users/Chris/.rvm/gems/ruby-2.2.1@golf_mentor221/gems/derailed_benchmarks-1.3.1/lib/derailed_benchmarks/tasks.rb:174:in `block (3 levels) in <top (required)>'
  /Users/Chris/.rvm/gems/ruby-2.2.1@golf_mentor221/gems/derailed_benchmarks-1.3.1/lib/derailed_benchmarks/tasks.rb:173:in `times'
  /Users/Chris/.rvm/gems/ruby-2.2.1@golf_mentor221/gems/derailed_benchmarks-1.3.1/lib/derailed_benchmarks/tasks.rb:173:in `block (2 levels) in <top (required)>'
  /Users/Chris/.rvm/gems/ruby-2.2.1@golf_mentor221/gems/rake-10.5.0/lib/rake/task.rb:240:in `call'
  /Users/Chris/.rvm/gems/ruby-2.2.1@golf_mentor221/gems/rake-10.5.0/lib/rake/task.rb:240:in `block in execute'
  /Users/Chris/.rvm/gems/ruby-2.2.1@golf_mentor221/gems/rake-10.5.0/lib/rake/task.rb:235:in `each'
  /Users/Chris/.rvm/gems/ruby-2.2.1@golf_mentor221/gems/rake-10.5.0/lib/rake/task.rb:235:in `execute'
  /Users/Chris/.rvm/gems/ruby-2.2.1@golf_mentor221/gems/rake-10.5.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
  /Users/Chris/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
  /Users/Chris/.rvm/gems/ruby-2.2.1@golf_mentor221/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
  /Users/Chris/.rvm/gems/ruby-2.2.1@golf_mentor221/gems/rake-10.5.0/lib/rake/task.rb:165:in `invoke'
  /Users/Chris/.rvm/gems/ruby-2.2.1@golf_mentor221/gems/derailed_benchmarks-1.3.1/bin/derailed:41:in `exec'
  /Users/Chris/.rvm/gems/ruby-2.2.1@golf_mentor221/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
  /Users/Chris/.rvm/gems/ruby-2.2.1@golf_mentor221/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
  /Users/Chris/.rvm/gems/ruby-2.2.1@golf_mentor221/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
  /Users/Chris/.rvm/gems/ruby-2.2.1@golf_mentor221/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
  /Users/Chris/.rvm/gems/ruby-2.2.1@golf_mentor221/gems/derailed_benchmarks-1.3.1/bin/derailed:92:in `<top (required)>'
  /Users/Chris/.rvm/gems/ruby-2.2.1@golf_mentor221/bin/derailed:23:in `load'
  /Users/Chris/.rvm/gems/ruby-2.2.1@golf_mentor221/bin/derailed:23:in `<top (required)>'

2 个答案:

答案 0 :(得分:3)

来自derailed_benchmark团队的help,我发现这是因为我使用rack-attack gem来限制请求。

答案 1 :(得分:1)

我有类似的问题

derailed_benchmarks-1.3.4/lib/derailed_benchmarks/tasks.rb:106:in `call_app': Bad request: <html><body>You are being <a href="https://example.org/api/v0/valid">redirected</a>.</body></html> (RuntimeError)

Mine是由仅生产配置引起的,以强制执行SSL:

config.force_ssl=true

config.middleware.insert_before ActionDispatch::Static, Rack::SslEnforcer, only_environments: ['production', 'staging']

我评论了这些以解决这个问题