Rails Puma 并发问题
Rails Puma concurrency issue
我正在尝试在开发中的 rails puma 服务器中实现并发,但 运行 遇到了麻烦。
我的端点看起来像:
def show
(1..10).each do |i|
Rails.logger.info "I!! #{i}"
sleep(1)
end
render json: {health: "hihi"}
end
我运行两次击中这个端点,一个接一个,他们运行按顺序。我可以让它们更并发吗?
日志:
puma -t 2:16 -p 3000
[20186] Puma starting in cluster mode...
[20186] * Version 3.4.0 (ruby 2.2.2-p95), codename: Owl Bowl Brawl
[20186] * Min threads: 2, max threads: 16
[20186] * Environment: development
[20186] * Process workers: 2
[20186] * Preloading application
[20186] * Listening on tcp://0.0.0.0:3000
[20186] Use Ctrl-C to stop
[20186] - Worker 0 (pid: 20217) booted, phase: 0
[20186] - Worker 1 (pid: 20218) booted, phase: 0
Started GET "/v1/address-service/addresses/1" for 127.0.0.1 at 2016-05-07 19:00:38 -0700
ActiveRecord::SchemaMigration Load (0.5ms) SELECT `schema_migrations`.* FROM `schema_migrations`
Processing by Api::V1::AddressService::AddressesController#show as JSON
Parameters: {"id"=>"1"}
I!! 1
I!! 2
I!! 3
I!! 4
I!! 5
I!! 6
I!! 7
I!! 8
I!! 9
I!! 10
Completed 200 OK in 10143ms (Views: 0.9ms | ActiveRecord: 0.0ms | Elasticsearch: 0.0ms)
Started GET "/v1/address-service/addresses/1" for 127.0.0.1 at 2016-05-07 19:00:49 -0700
Processing by Api::V1::AddressService::AddressesController#show as JSON
Parameters: {"id"=>"1"}
I!! 1
I!! 2
I!! 3
I!! 4
I!! 5
I!! 6
I!! 7
I!! 8
I!! 9
I!! 10
Completed 200 OK in 10031ms (Views: 0.3ms | ActiveRecord: 0.0ms | Elasticsearch: 0.0ms)
development.rb:
config.cache_classes=false
config.allow_concurency = true
我意识到我正在使用 chrome 进行测试,它出于某种原因一次只发送一个请求。我使用了 curl,它按预期工作。
我正在尝试在开发中的 rails puma 服务器中实现并发,但 运行 遇到了麻烦。
我的端点看起来像:
def show
(1..10).each do |i|
Rails.logger.info "I!! #{i}"
sleep(1)
end
render json: {health: "hihi"}
end
我运行两次击中这个端点,一个接一个,他们运行按顺序。我可以让它们更并发吗?
日志:
puma -t 2:16 -p 3000
[20186] Puma starting in cluster mode...
[20186] * Version 3.4.0 (ruby 2.2.2-p95), codename: Owl Bowl Brawl
[20186] * Min threads: 2, max threads: 16
[20186] * Environment: development
[20186] * Process workers: 2
[20186] * Preloading application
[20186] * Listening on tcp://0.0.0.0:3000
[20186] Use Ctrl-C to stop
[20186] - Worker 0 (pid: 20217) booted, phase: 0
[20186] - Worker 1 (pid: 20218) booted, phase: 0
Started GET "/v1/address-service/addresses/1" for 127.0.0.1 at 2016-05-07 19:00:38 -0700
ActiveRecord::SchemaMigration Load (0.5ms) SELECT `schema_migrations`.* FROM `schema_migrations`
Processing by Api::V1::AddressService::AddressesController#show as JSON
Parameters: {"id"=>"1"}
I!! 1
I!! 2
I!! 3
I!! 4
I!! 5
I!! 6
I!! 7
I!! 8
I!! 9
I!! 10
Completed 200 OK in 10143ms (Views: 0.9ms | ActiveRecord: 0.0ms | Elasticsearch: 0.0ms)
Started GET "/v1/address-service/addresses/1" for 127.0.0.1 at 2016-05-07 19:00:49 -0700
Processing by Api::V1::AddressService::AddressesController#show as JSON
Parameters: {"id"=>"1"}
I!! 1
I!! 2
I!! 3
I!! 4
I!! 5
I!! 6
I!! 7
I!! 8
I!! 9
I!! 10
Completed 200 OK in 10031ms (Views: 0.3ms | ActiveRecord: 0.0ms | Elasticsearch: 0.0ms)
development.rb:
config.cache_classes=false
config.allow_concurency = true
我意识到我正在使用 chrome 进行测试,它出于某种原因一次只发送一个请求。我使用了 curl,它按预期工作。