Reputation: 483
I am trying to achieve concurrency in a rails puma server on development but am running into trouble.
My endpoint looks like:
def show
(1..10).each do |i|
Rails.logger.info "I!! #{i}"
sleep(1)
end
render json: {health: "hihi"}
end
I run hit this endpoint twice, one after the other, and they run in sequence. Can I get them to be more concurrent?
Log:
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
Upvotes: 3
Views: 732
Reputation: 483
I realize I was using chrome to test and it only sends one request at a time for what ever reason. I used curl and it works as expected.
Upvotes: 1