instacart / makara

A Read-Write Proxy for Connections; Also provides an ActiveRecord adapter.

Home Page:http://tech.taskrabbit.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: With stickiness = false is there still stickiness is a single request?

drewB opened this issue · comments

If stickiness = false, I know that the same db connection will not be used for subsequent requests but I am unclear what the behavior is during a single request.

For example:

user = User.find(1) #would go to some reader
user.posts.create(:text, "hello") #master
posts = user.posts.all #would this go to master or a reader?

So would user.posts.all stick to master or would it grab a reader?

If it does not stick for the request then could we get that behavior by turning stickiness on but setting master_ttl = 0 (or near 0)?

I did some testing of this today and this is what I found:

If stickiness = false then it does NOT stick during a single request. So in my example above posts = user.posts.all would go to a reader.

If stickiness = true and master_ttl is set to a very low number (i tried 0.01) then it will stick for the entire request (even if longer than master_ttl).

That's my understanding as well. Stickiness is a concept between SQL calls. Setting it to false (or using the block) might be right in a situation with known writes that have nothing to do with the reads, for example.

maybe there's a case to be made for cookie=false (or some better name) to not do it between requests.

@drewB thanks for the proactive investigation to your own question!

Thanks for confirming what I saw.

Yes, I think that is where the ambiguity is. Cause it isn't really between SQL calls (see #206). It is between requests where request #1 is the first one to make a write sql call. Maybe just an improvement to the README would clear things up. I will create a PR to try and clear that up.