ruby on rails - Seeing duplicate requests handled with Unicorn -


recently upgraded our ec2 instances c3.large in order boost more unicorn workers handle increased traffic our site. (6xworkers per machine - 2 ec2 instances).

when did this, started seeing duplicate records being created! looks somehow, maybe 2 unicorn workers attempting process same request?

in nginx logs see 1 [post] request particular rails controller - yet 2 records being created in database. i'm hitting kind of race condition issue - have no idea how debug this. doesn't happen time, when it's frustrating well. noticed 2 database records within 5 seconds of each other. (and yes disable button when user clicks submit button).

unicorn 4.8.2 ruby 1.9.3 rails 3.2.14

any great! thanks!

although may not fix problem, upgrade ruby 2.0.0. there blog mentioning idea upgrade ruby 2.0.0 if using unicorn.

for example: https://www.digitalocean.com/community/articles/how-to-optimize-unicorn-workers-in-a-ruby-on-rails-app

specifically:

if using ruby 1.9, should consider switching ruby 2.0. understand why, need understand little bit forking.

forking , copy-on-write (cow)

when child process forked, exact same copy parent process. however, actual physical memory copied need not made. since exact copies, both child , parent processes can share same physical memory. when write made-- copy child process physical memory.

so how relate ruby 1.9/2.0 , unicorn?

recall unicorn uses forking. in theory, operating system able take advantage of cow. unfortunately, ruby 1.9 not make possible. more accurately, garbage collection implementation of ruby 1.9 not make possible. extremely simplified version — when garbage collector of ruby 1.9 kicks in, write have been made, rendering cow useless.

without going detail, suffices garbage collector of ruby 2.0 fixes this, , can exploit cow.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -