标签: puma

使用Capistrano 3,Nginx,Puma,GitHub和RVM的Amazon EC2的Rails 4 API部署示例?

我在GitHub上有一个Rails 4 API项目,我正在尝试使用Capistrano 3将我的MacBook Pro部署到使用SSH密钥的两个Amazon AWS EC2 Ubuntu实例 - 一个是app/web服务器,另一个是PostgreSQL数据库服务器 app/web服务器通过RVM拥有最新的Ruby 2,并将使用Nginx/Puma提供API .Nginx将托管多个站点,其中一个是此API.这些是我正在使用的相关宝石:

  • 宝石'capistrano','〜> 3.0.0'
  • 宝石'capistrano-rails'
  • 宝石'capistrano-bundler'
  • 宝石'capistrano-rvm','〜> 0.0.2'
  • 宝石'capistrano-puma',github:"seuros/capistrano-puma"

到目前为止,我没有找到使用Puma的完整Capistrano 3配置示例,但是这两个宝石对于Rails社区同样重要,我确信在GitHub上必须有一个工作的Rails存储库包含这些.

我已经通过官方的Capistrano 3文档.我对Capistrano 2和Capistrano 3之间的差异有困难,并希望看到完整的Capistrano 3示例来理解这些差异.理想情况下,我正在寻找一个包含所有配置文件的开源GitHub存储库(Capistrano 3,Puma,Nginx))以及我可以参考的工作.

谢谢!

capistrano nginx amazon-ec2 puma ruby-on-rails-4

8
推荐指数
1
解决办法
2355
查看次数

如何将Rails开发服务器设置为webbrick而不是Puma

我在Heroku上使用Puma作为我的服务器.当我安装了Puma gem时,我的开发环境会以Puma作为服务器启动.如果不从我的gemfile中提取pum gem,我似乎无法关闭它.

我喜欢在开发中使用保存服务器作为生产的想法,但美洲狮服务器使我很难跟踪我的调试语句.此外,我似乎没有办法改变最大线程,即使我的puma.rb文件设置为1,在开发中出现16.

ruby-on-rails heroku puma

8
推荐指数
1
解决办法
1900
查看次数

Rails 4数据库连接池错误

我有一个使用NGINX和Puma托管的rails应用程序.每10个小时左右,该应用程序将无法使用.每当用户尝试连接时,都会显示以下错误消息:

Error during failsafe response: could not obtain a database connection within 5.000 seconds (waited 5.000 seconds)
Run Code Online (Sandbox Code Playgroud)

这将一直持续到应用程序重新启动.

我已经读过这是因为数据库连接池已满,因此必须在rails应用程序中创建线程,这些线程在完成时不会关闭与数据库的连接.据我所知,应用程序代码中只有一个位置使用线程:一个块使用Ruby Timeout模块,但这不访问数据库.

按照本指南 https://devcenter.heroku.com/articles/concurrency-and-database-connections(我实际上并没有使用Heroku)我已将数据库连接池的大小设置为5,使用以下配置文件:

#config/initializers/database_connection.rb
Rails.application.config.after_initialize do
  ActiveRecord::Base.connection_pool.disconnect!

  ActiveSupport.on_load(:active_record) do
    config = ActiveRecord::Base.configurations[Rails.env] ||
                Rails.application.config.database_configuration[Rails.env]
    config['reaping_frequency'] = ENV['DB_REAP_FREQ'] || 10 # seconds
    config['pool']              = ENV['MAX_THREADS'] || 5 
    ActiveRecord::Base.establish_connection(config)
  end
Run Code Online (Sandbox Code Playgroud)

结束

该站点使用Rails 4.0.0托管.我已经读过,这可能实际上是一个Rails 4.0.0问题,并且这在以后的版本中得到修复,但我不确定. Heroku上的ConnectionTimeoutError与Postgres

  1. 有没有办法监视连接池中活动数据库连接的数量?这将使调试更容易.
  2. 是否在Rails应用程序代码中使用Timeout模块可能导致此问题?
  3. 这可能是一个Rails 4.0.0问题,而不是我的应用程序的问题?

rails应用程序正在生产环境中运行.如果需要,我可以提供有关我的Puma,NGINX配置的更多信息.

database-connection ruby-on-rails nginx puma

8
推荐指数
1
解决办法
2380
查看次数

RoR 5.0.0 ActionCable wss WebSocket握手:意外的响应代码:301

您好我正在尝试使用ror 5.0.0 beta(使用puma)进行简单聊天,在生产模式下工作(在localhost中没有问题).

这是我的Nginx配置:

upstream websocket {
    server 127.0.0.1:28080;
}


server {

    listen 443;
    server_name mydomain;
    ssl_certificate ***/server.crt;
    ssl_certificate_key ***/server.key;
    ssl on;
    ssl_session_cache builtin:1000 shared:SSL:10m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 
HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
    ssl_prefer_server_ciphers on;
    access_log /var/log/nginx/jenkins.access.log;

    location / {
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_pass http://localhost:3000;
      proxy_read_timeout 90;

      proxy_redirect http://localhost:3000 https://mydomain;


    location /cable/{
        proxy_pass         http://websocket/;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection "upgrade";
        proxy_set_header   Host $http_host;
        break;
    }

   }
Run Code Online (Sandbox Code Playgroud)

这是config/redis/cable.yml

production:url:redis:// …

wss nginx puma ruby-on-rails-5 actioncable

8
推荐指数
1
解决办法
4693
查看次数

ActiveRecord中的表名损坏错误

偶尔我们PG::UndefinedTable在使用ActiveRecord时会出错.关联表名称是一些损坏的方式,我经常看到 Cancelled附加到表名的末尾.

例如:

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "fooCancell" does not exist 
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "Cancelled" does not exist
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  relation "barC" does not exist
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,我使用foo和模糊了表名bar.

当rails项目在Puma中运行时,我们会看到这个错误.队列工作人员似乎做得很好.

错误消息中的表与实际表或模型不对应.看起来像是内存损坏的情况.有没有人见过这样的问题?如果是这样,你是如何解决它的?

puma.rb

on_worker_boot do
  ActiveRecord::Base.establish_connection
end
Run Code Online (Sandbox Code Playgroud)

database.yml的

production:
  url:  <%= ENV["DATABASE_URL"] %>
  pool: <%= ENV['DB_CONNECTION_POOL_SIZE'] || 5%>
  reaping_frequency: <%= ENV['DB_CONNECTION_REAPING_FREQUENCY'] || 10 %>
  prepared_statements: false
Run Code Online (Sandbox Code Playgroud)

ruby activerecord ruby-on-rails puma

8
推荐指数
1
解决办法
240
查看次数

Rails 4,Live Streaming,保持打开状态,阻止请求

我正在尝试使用Rails 4 Live Streaming组件.这一切都有效,除了它似乎流保持打开并阻止新的请求.

关闭或单击应用程序中的新链接时,如何确保连接正常关闭?

这是我的直播活动控制器.

  def events
    response.headers["Content-Type"] = "text/event-stream"
    redis = Redis.new
    redis.psubscribe("participants.*") do |on|
      on.pmessage do |pattern, event, data|
        response.stream.write("event: #{event}\n")
        response.stream.write("data: #{data}\n\n")
      end
    end
  rescue IOError
  ensure
    redis.quit
    response.stream.close
  end
Run Code Online (Sandbox Code Playgroud)

数据库conf

production:
  adapter: postgresql
  encoding: unicode
  database: ************
  pool: 1000
  username: ************
  password: ************
  timeout: 5000
Run Code Online (Sandbox Code Playgroud)

我在使用postgresql 9.2.x的Ubuntu 10.04上使用puma作为独立的webserver(我没有需要由nginx提供的大量静态文件).

ruby-on-rails http-live-streaming puma ruby-on-rails-4

7
推荐指数
2
解决办法
3027
查看次数

Rails 4 直播不适用于 Puma

我正在尝试使用 Puma 服务器在 Rails 上实施一个小测试ActiveController::Live。我通过 启动了 Puma 服务器rails s puma,并用来curl localhost:3000/messages/events进行测试。不过,在数据一次返回之前,有一个很长的停顿,这与使用 WEBrick 相同。那么为什么 Puma 服务器不直播结果呢?

class MessagesController < ApplicationController
  include ActionController::Live

  def index
    @messages = Message.all
  end

  def create
    @message = Message.create!(params[:message].permit(:content, :name))
  end

  def events
    3.times do |n|
      response.stream.write "#{n}...\n\n"
      sleep 2
    end
  ensure
    response.stream.close
  end
end
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails live-streaming puma

7
推荐指数
1
解决办法
892
查看次数

连接到 Rails 服务器时 Puma mini SSL 错误

每次我尝试连接到服务器时,Rails 服务器都会抛出 SSL 错误。

[34087] Puma starting in cluster mode...
[34087] * Version 4.3.3 (ruby 2.6.5-p114), codename: Mysterious Traveller
[34087] * Min threads: 10, max threads: 10
[34087] * Environment: development
[34087] * Process workers: 1
[34087] * Phased restart available
[34087] * Listening on tcp://0.0.0.0:3001
[34087] * Listening on ssl://0.0.0.0:3000?cert=config/ssl.crt&key=config/ssl.key&verify_mode=none&no_tlsv1=false&no_tlsv1_1=false
[34087] Use Ctrl-C to stop
[34087] * Starting control server on unix:///tmp/puma-status-1596893456509-34087
[34087] - Worker 0 (pid: 34120) booted, phase: 0
2020-08-08 19:03:16 +0530: SSL error, peer: 127.0.0.1, peer …
Run Code Online (Sandbox Code Playgroud)

openssl ruby-on-rails ssl-certificate puma

7
推荐指数
1
解决办法
2009
查看次数

如何查找Puma Worker自发重启的根本原因?

在我的 RoR API 服务上,我有时会看到请求在处理过程中被中断。只需 Puma 服务器停止处理请求,然后我就可以在日志中看到消息说:

[10] - Worker 0 (PID: 811) booted in 0.01s, phase: 0
Run Code Online (Sandbox Code Playgroud)

我正在尝试找出其根本原因。该 API 服务作为 pod 在 Kubernetes 中运行,在该服务之前我有 AWS ELB。

需要明确的是,K8S pod 不会重新启动,只有 Puma 的一名工作人员被“杀死”,然后立即重新启动。

ruby-on-rails amazon-web-services puma kubernetes

7
推荐指数
0
解决办法
957
查看次数

NoMethodError:未定义 Puma::Events:Class 的方法“字符串”

我正在运行一个非常简单的测试,它需要 javascript,只是为了检查索引加载和元素是否存在,如下所示:

\n
class ProfitsTest < ApplicationSystemTestCase\n  setup do\n    @admin = users(:admin)\n    @admin.confirm\n    sign_in @admin\n  end\n\n  test 'visiting the index' do\n    # Index only test\n    visit profits_url\n    assert_selector 'h1', text: '\xe8\xa8\x88\xe7\xae\x97\xe8\xa1\xa8'\n  end\nend\n
Run Code Online (Sandbox Code Playgroud)\n

我的水豚配置如下(只是删除 Puma 启动日志):

\n
require 'test_helper'\n\nclass ApplicationSystemTestCase < ActionDispatch::SystemTestCase\n  driven_by :selenium, using: :headless_chrome # :chrome\n  Capybara.server = :puma, { Silent: true }\n  Selenium::WebDriver.logger.ignore(:browser_options)\nend\n
Run Code Online (Sandbox Code Playgroud)\n

这是我收到的错误:

\n
#<Thread:0x000000010f82b2d8 /Users/cody/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/capybara-3.37.1/lib/capybara/server.rb:76 run> terminated with exception (report_on_exception is true):\n/Users/cody/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/capybara-3.37.1/lib/capybara/registrations/servers.rb:32:in `block in <main>': undefined method `strings' for Puma::Events:Class (NoMethodError)\n\n  events = conf.options[:Silent] …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails capybara puma

7
推荐指数
2
解决办法
1057
查看次数