Jeremy,
Thanks for everything. You are always super help. Cleanest software I've
ever used. I think everyone on this forum owes you a lifetime supply of
scotch or whatever you drink. :)
I did what you requested:
1. made a super small app that just exercised this problem
2. Added the logging as defined above (super helpful!)
What I found is, it seems like DB.synchronize does not allocate anything
when using a replica. Is DB.synchronize correct for replicas?
The following are the snip of code and log entries: ( can post more of the
code I just didn't want to inundate ).
tester-primary.rb and tester-replicas.rb lines 25-28:
DB.synchronize do
x = Trip.order(:id).first.inspect
y = Template.order(:id).first.inspect
end
app/models/template.rb: ( super simple )
class Template < Sequel::Model
many_to_one :user
end
Querying primary: (seems correct, one NULL for both)
I, [2020-12-09T13:36:43.722029 #39120] INFO -- : (0.000873s) (conn:
47271528492740) (source: tester-primary.rb:25:in `block in <top
(required)>') SELECT NULL
I, [2020-12-09T13:36:43.723006 #39120] INFO -- : (0.000753s) (conn:
47271528492740) (source: tester-primary.rb:26:in `block (2 levels) in <top
(required)>') SELECT * FROM "trips" ORDER BY "id" LIMIT 1
I, [2020-12-09T13:36:43.723889 #39120] INFO -- : (0.000452s) (conn:
47271528492740) (source: tester-primary.rb:27:in `block (2 levels) in <top
(required)>') SELECT * FROM "templates" ORDER BY "id" LIMIT 1
Query replica: (3 SELECT NULL)
I, [2020-12-09T13:35:51.502009 #39117] INFO -- : (0.000418s) (conn:
46966930197660) (source: tester-replica.rb:25:in `block in <top
(required)>') SELECT NULL
I, [2020-12-09T13:35:51.502847 #39117] INFO -- : (0.000605s) (conn:
46966930244680) (source: tester-replica.rb:26:in `block (2 levels) in <top
(required)>') SELECT NULL
I, [2020-12-09T13:35:51.504222 #39117] INFO -- : (0.001229s) (conn:
46966930244680) (source: tester-replica.rb:26:in `block (2 levels) in <top
(required)>') SELECT * FROM "trips" ORDER BY "id" LIMIT 1
I, [2020-12-09T13:35:51.505495 #39117] INFO -- : (0.000398s) (conn:
46966930244680) (source: tester-replica.rb:27:in `block (2 levels) in <top
(required)>') SELECT NULL
I, [2020-12-09T13:35:51.506530 #39117] INFO -- : (0.000874s) (conn:
46966930244680) (source: tester-replica.rb:27:in `block (2 levels) in <top
(required)>') SELECT * FROM "templates" ORDER BY "id" LIMIT 1
Thanks for your help as always.
Geff
On Tuesday, December 8, 2020 at 4:05:29 PM UTC-8 Jeremy Evans wrote:
> On Tue, Dec 8, 2020 at 3:44 PM Geff Hanoian <[email protected]> wrote:
>
>> My goal is to have fault tolerance for read only queries with a Single
>> Primary and multiple replicas.
>>
>> So to do that, I'm trying to use the connection validator (timeout = -1)
>> with DB.synchronize in the rack middleware to limit the "SELECT NULL"
>> queries to one per web request, as the docs state. This worked very well
>> when I just had a single primary defined. However once I defined read only
>> replicas, I get the following during a single web request on a replica:
>>
>> SELECT NULL
>> MY QUERY1
>> SELECT NULL
>> MY QUERY2
>>
>> (oddly I get a SELECT NULL on the primary as well during the web request)
>>
>> I'm wrapping as follows:
>>
>> DB.synchronize do
>> app.call(env)
>> end
>>
>> I feel like I'm crossing the streams and as we all know crossing the
>> streams is bad. :)
>>
>> Any ideas?
>>
>
> It looks like something else is checking out a connection from the pool
> even though you already have a connection checked out (separate
> thread/shard maybe). You probably want to start logging connection info
> and use the caller_logging extension
>
> DB.log_connection_info = true
> DB.extension :caller_logging
>
> This should hopefully help you find where the connections are coming from.
>
> If you still need help, please post a minimal, self-contained,
> reproducible example showing the problem.
>
> Thanks,
> Jeremy
>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sequel-talk/36495c3d-f82d-41dd-8c67-93b56582a5f4n%40googlegroups.com.