On Sunday, January 7, 2018 at 2:45:30 PM UTC-5, Massimo Di Pierro wrote:
>
> I am curious whether anybody has actually tried this.
>
> I am concerned about a few things that can go wrong:
> 1) even GET request may write to the DB (maybe write session in DB or 
> logging some action)
>

Yes, obviously you wouldn't want to rely on only the HTTP method if you're 
writing to the same database within GET requests. I would suggest if you 
are already to the point of scaling out the main database with read 
replicas in this fashion, then maybe sessions and logging messages should 
go in a separate database altogether (in particular, sessions would be 
better in Redis).
 

> 2) all web2py requests are wrapped in a transaction, can this cause 
> deadlocks?
>

Are you referring to the last proposed solution involving swapping out the 
DAL adapter? If so, how would that result in a deadlock?

Note, there was a problem with the original code -- both DAL instances 
ended up with the same adapter, so web2py would not close/return the 
connection of the read-only database. I changed it so the adapters are 
swapped between the DAL instances, so both connections will be 
committed/closed/returned at the end of the request.

Anyway, I don't think that is the best option, as it is a hack that relies 
on details of the internal implementation (and may have unforeseen 
consequences). I was just brainstorming a way to decouple model definitions 
from database connections.
 

> 3) there is a delay in syncing a master with a slave db, can this result 
> in inconsistencies on the user side?
>

Sure, that's always the trade-off with read replicas. It is suggested in 
the book 
<http://web2py.com/books/default/chapter/29/13/deployment-recipes#Using-replicated-databases>,
 
though.
 

>
> Why do this instead of simply caching read only queries using redis?
>

It probably depends on the use case. If you have lots of unique 
user-specific queries and/or query results that change frequently, caching 
may not relieve much of the burden on the database. I suppose in many cases 
where the freshness of a read replica is an issue, the freshness of a cache 
would also likely be an issue.

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to