ruby - Rails 4 - How do I optimize my Heroku production environment? -


how can increase rails app performance , use allocated heroku resources max? instance, half of memory remains unused.

should have increase worker process , reduce timeout limit? h12 h18 errors have increased after small raise in traffic website.

and when should buy heroku worker? reduce h18 , h12 errors?

please share insights fine tune things improve performance , reduce errors.

i have started learning rails recently. sorry if question basic.

enter image description here

config/unicorn.rb

# config/unicorn.rb worker_processes integer(env["web_concurrency"] || 3) timeout 65 preload_app true  before_fork |server, worker|   signal.trap 'term'     puts 'unicorn master intercepting term , sending myself quit instead'     process.kill 'quit', process.pid   end    defined?(activerecord::base) ,     activerecord::base.connection.disconnect! end  after_fork |server, worker|   signal.trap 'term'     puts 'unicorn worker intercepting term , doing nothing. wait master send quit'   end    defined?(activerecord::base) ,     activerecord::base.establish_connection end 

gemfile

source 'https://rubygems.org' ruby   '2.1.4' . . . group :production   gem 'pg', '0.17.1'   gem 'rails_12factor', '0.0.2'   gem 'unicorn' end 

some additional information. enter image description here

the question not basic, stuff tricky. it's not entirely clear me why you'd getting h12 (request timeout) , h18 (request interrupted) errors due small increase in traffic. worth trying figure out what's going on -- h12's, looking @ logs (or setting logging new relic), figure out how long individual requests taking process. if individual request not under load taking more few seconds (which kind of long), you're going want work on figuring out why , speeding -- modifying actual app code avoid these slow responses. h18's more mysterious me.

but if individual requests reasonably speedy, , problem not enough processing power handle traffic (which wouldn't neccesarily assume you've told us) -- there things can make of processing power have available. or can increase number of dynos, definitely. if that's issue.

to maximize usage of resources you've got, use puma rather unicorn -- puma heroku-recommended app server rails.

puma, heroku docs explain, allows both run multiple rails processes, have each process process requests concurrently using multiple threads. although multiple threaded request handling requires app thread-safe -- rails is, app code, or possibly gems using, may not be. thread-safety in rails avoiding shared global state (class or module variables; globals), except read-only state set on program boot (or global state synchronized multi-threaded access).

contrary other answers, i'm pretty sure unicorn doesn't use multi-threading @ all, uses multiple processes. puma can run multiple processes each use multiple threads.

for typical rails apps spend non-trivial time waiting on i/o (typically database), multi-threaded request handling way maximize throughput , minimize latency, within given hardware limits. mri ruby , it's "global interpreter lock." better performance, deploy on jruby or rubinius, don't have gil.

either way, it's question of figuring out how many puma processes, how many maximum threads each can fit in dyno without running out of memory. heroku docs suggest can typically run 2-4 puma processes in 1x dyno. have each 1 maximum thread configuration of 2 or 10 threads.

the heroku puma docs pretty good, , should serve give overview of considerations.

but assuming, question did, issue h12 , h18 errors heroku need more processing power handle request traffic. i'm not that's it, might be.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -