[Refactoring] send messages to dedicated actor instead of directly accessing objects #799
Labels
No labels
A: API
A: Backend
A: Federation
A: Front-End
A: I18N
A: Meta
A: Security
Build
C: Bug
C: Discussion
C: Enhancement
C: Feature
Compatibility
Dependency
Design
Documentation
Good first issue
Help welcome
Mobile
Rendering
S: Blocked
S: Duplicate
S: Incomplete
S: Instance specific
S: Invalid
S: Needs Voting/Discussion
S: Ready for review
Suggestion
S: Voted on Loomio
S: Wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: Plume/Plume#799
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Instead of passing around references to directly access
worker
, andsearcher
, we could instead send messages to an actor!This would also help split responsibility of these functions, as they would no longer invoke these actions themselves, only sending messages to invoke them.
This would allow to remove searcher and worker from our PlumeRocket. Together with #797, this could help completely dissolve the struct.
How?
We could use an actor system, like riker.
Using multiple messages we could send different messages to different actors that then do what needs to be done
Honestly, it makes me wonder if actix wouldn't be more appropriate for our use case… we would get actors and a web framework out of the box. I think we already tried to migrate once and it didn't went very far, right? What was blocking?
But I'm okay with refactoring our code with Riker and keeping Rocket too.
the main reasons i abandoned the actix experiment were:
(the other one isn't even public yet, so that's actually quite nice :P)
I've created a basic example with riker and multi-type messages for how to replace Searcher: https://gist.github.com/igalic/16ec36a4c9277b3b46f6bea032226189
in a similar fashion, we can replace Worker, which currently mostly sents broadcast messages to all subscribers.
here's what I've found out in an experiment attempting to extract
Searcher
into anActor
:Searcher
is intimately bundled withPost
Searcher
is also intimately bundled withDbConn
, becausePost
doesn't actually have all the infoSearcher
needsgiven this asymmetry, i thought it's best to only pass
Post.id
but we still have to give it access to a
DbConn
perhaps on creation of a
Searcher
Actor
, we could give it its ownDbConn
?Some observations, which lead to the confidence with which we've started on #807:
DbPool
is anArc
, it can be easily shared via.clone()
.This would allow us to create a wrapper object around
Searcher
which can then have its ownDbConn
instead of passing one from a — hopefully — short-livedRequest
, potentially infinitely blocking on it.The general framework lends itself nicely to be solved with an actor framework, but if that doesn't pan out, we can use any old object, and send it any old message!
We've already done good work there in extracting the essence.
It bears repeating why the refactoring to break up PlumeRocket is so important:
We pass PlumeRocket around as
ref
.It's a giant struct with lots of maybe-related data, giving access to different parts of the system.
Passing it, by
ref
thru Rocket will become an issue as soon as we try to goasync
, because then we have a borrowed object sitting somewhere, waiting to be.await
ed.This is all a big mess, and best of all avoided, but it's also a good opportunity to see which parts of the system we can tear apart from there tight coupling so they will work better.
Here is the list of things the worker is used for:
for the first case, i already have opened a question: https://github.com/riker-rs/riker/issues/130
and received an answer